mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-07 22:16:44 +01:00
Move some methods out of the Equine<?> interface that don't need to be there
This commit is contained in:
parent
33dc4cbb34
commit
e9070b87b0
16 changed files with 57 additions and 130 deletions
|
@ -9,8 +9,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
import com.minelittlepony.unicopia.*;
|
||||
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
|
||||
import com.minelittlepony.unicopia.block.data.ModificationType;
|
||||
import com.minelittlepony.unicopia.entity.Physics;
|
||||
import com.minelittlepony.unicopia.entity.PonyContainer;
|
||||
import com.minelittlepony.unicopia.entity.*;
|
||||
import com.minelittlepony.unicopia.particle.ParticleSource;
|
||||
import com.minelittlepony.unicopia.util.SoundEmitter;
|
||||
import com.minelittlepony.unicopia.util.VecHelper;
|
||||
|
@ -120,9 +119,6 @@ public interface Caster<E extends Entity> extends
|
|||
return Optional.of((Caster<?>)entity);
|
||||
}
|
||||
|
||||
return PonyContainer.of(entity)
|
||||
.map(PonyContainer::get)
|
||||
.filter(c -> c instanceof Caster<?>)
|
||||
.map(c -> (Caster<?>)c);
|
||||
return Equine.<Entity, Caster<?>>of(entity, c -> c instanceof Caster<?>);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,6 +142,11 @@ public class Creature extends Living<LivingEntity> implements WeaklyOwned.Mutabl
|
|||
builder.add(UEntityAttributes.ENTITY_GRAVTY_MODIFIER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean beforeUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
|
|
@ -1,78 +1,45 @@
|
|||
package com.minelittlepony.unicopia.entity;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.minelittlepony.unicopia.EntityConvertable;
|
||||
import com.minelittlepony.unicopia.Race;
|
||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||
import com.minelittlepony.unicopia.projectile.ProjectileImpactListener;
|
||||
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
||||
import com.minelittlepony.unicopia.util.Tickable;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||
|
||||
public interface Equine<T extends Entity> extends NbtSerialisable, Tickable, ProjectileImpactListener, EntityConvertable<T> {
|
||||
Race getSpecies();
|
||||
|
||||
Physics getPhysics();
|
||||
|
||||
Race getSpecies();
|
||||
|
||||
void setSpecies(Race race);
|
||||
|
||||
/**
|
||||
* Gets the last magical entity to attack us.
|
||||
*/
|
||||
@Nullable
|
||||
Caster<?> getAttacker();
|
||||
|
||||
/**
|
||||
* Returns true if this player is fully invisible.
|
||||
* Held items and other effects will be hidden as well.
|
||||
*/
|
||||
default boolean isInvisible() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this player should be invisible.
|
||||
*/
|
||||
default void setInvisible(boolean invisible) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called at the beginning of an update cycle.
|
||||
*/
|
||||
default boolean beforeUpdate() {
|
||||
return false;
|
||||
boolean beforeUpdate();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <E extends Entity, T extends Equine<? extends E>> Optional<T> of(@Nullable E entity) {
|
||||
return entity instanceof Container ? Optional.of(((Container<T>)entity).get()) : Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Event triggered when this entity is hit by a projectile.
|
||||
*/
|
||||
@Override
|
||||
default boolean onProjectileImpact(ProjectileEntity projectile) {
|
||||
return false;
|
||||
@SuppressWarnings("unchecked")
|
||||
static <E extends Entity, T> Optional<T> of(@Nullable E entity, Predicate<Object> typeCheck) {
|
||||
return entity instanceof Container
|
||||
? (Optional<T>)Optional.of((Object)((Container<?>)entity).get()).filter(typeCheck)
|
||||
: Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when this entity jumps
|
||||
*/
|
||||
default void onJump() {
|
||||
interface Container<T extends Equine<?>> {
|
||||
Equine<?> create();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an entity is harmed.
|
||||
*/
|
||||
default Optional<Boolean> onDamage(DamageSource source, float amount) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
static <E extends Entity, T extends Equine<E>> Optional<T> of(@Nullable E entity) {
|
||||
return PonyContainer.<E, T>of(entity).map(PonyContainer::get);
|
||||
T get();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.minelittlepony.unicopia.entity;
|
||||
|
||||
public interface IItemEntity extends PonyContainer<ItemImpl> {
|
||||
public interface IItemEntity extends Equine.Container<ItemImpl> {
|
||||
|
||||
int getAge();
|
||||
|
||||
|
|
|
@ -2,10 +2,7 @@ package com.minelittlepony.unicopia.entity;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.minelittlepony.unicopia.*;
|
||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||
import com.minelittlepony.unicopia.util.VecHelper;
|
||||
|
||||
|
@ -15,6 +12,7 @@ import net.minecraft.entity.data.DataTracker;
|
|||
import net.minecraft.entity.data.TrackedData;
|
||||
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
|
@ -42,10 +40,9 @@ public class ItemImpl implements Equine<ItemEntity> {
|
|||
owner.getDataTracker().startTracking(ITEM_RACE, Race.REGISTRY.getId(Race.HUMAN).toString());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Caster<?> getAttacker() {
|
||||
return null;
|
||||
public boolean onProjectileImpact(ProjectileEntity projectile) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -132,12 +129,10 @@ public class ItemImpl implements Equine<ItemEntity> {
|
|||
return physics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Race getSpecies() {
|
||||
return Race.fromName(entity.getDataTracker().get(ITEM_RACE), Race.HUMAN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpecies(Race race) {
|
||||
entity.getDataTracker().set(ITEM_RACE, Race.REGISTRY.getId(race).toString());
|
||||
}
|
||||
|
|
|
@ -53,6 +53,8 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
|||
@Nullable
|
||||
private Runnable landEvent;
|
||||
|
||||
private boolean invisible = false;
|
||||
|
||||
@Nullable
|
||||
private Caster<?> attacker;
|
||||
|
||||
|
@ -69,6 +71,14 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
|||
entity.getDataTracker().startTracking(effect, new NbtCompound());
|
||||
}
|
||||
|
||||
public boolean isInvisible() {
|
||||
return invisible && SpellPredicate.IS_DISGUISE.isOn(this);
|
||||
}
|
||||
|
||||
public void setInvisible(boolean invisible) {
|
||||
this.invisible = invisible;
|
||||
}
|
||||
|
||||
public void waitForFall(Runnable action) {
|
||||
if (entity.isOnGround()) {
|
||||
action.run();
|
||||
|
@ -166,7 +176,6 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJump() {
|
||||
if (getPhysics().isGravityNegative()) {
|
||||
entity.setVelocity(entity.getVelocity().multiply(1, -1, 1));
|
||||
|
@ -174,12 +183,10 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
|||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public final Caster<?> getAttacker() {
|
||||
return attacker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Boolean> onDamage(DamageSource source, float amount) {
|
||||
|
||||
if (source == DamageSource.LIGHTNING_BOLT && (invinsibilityTicks > 0 || tryCaptureLightning())) {
|
||||
|
@ -280,7 +287,7 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
|||
}
|
||||
|
||||
public static Optional<Living<?>> getOrEmpty(Entity entity) {
|
||||
return PonyContainer.of(entity).map(PonyContainer::get).map(a -> a instanceof Living ? (Living<?>)a : null);
|
||||
return Equine.of(entity, a -> a instanceof Living);
|
||||
}
|
||||
|
||||
public static Living<?> living(Entity entity) {
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
package com.minelittlepony.unicopia.entity;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
public interface PonyContainer<T extends Equine<?>> {
|
||||
|
||||
Equine<?> create();
|
||||
|
||||
T get();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <E extends Entity, T extends Equine<?>> Optional<PonyContainer<T>> of(@Nullable Entity entity) {
|
||||
if (entity instanceof PonyContainer) {
|
||||
return Optional.of(((PonyContainer<T>)entity));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
|
@ -1,12 +1,9 @@
|
|||
package com.minelittlepony.unicopia.entity.duck;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.Equine;
|
||||
import com.minelittlepony.unicopia.entity.PonyContainer;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Hand;
|
||||
|
||||
public interface LivingEntityDuck extends PonyContainer<Equine<?>> {
|
||||
public interface LivingEntityDuck {
|
||||
void updateItemUsage(Hand hand, ItemStack stack, int time);
|
||||
|
||||
boolean isJumping();
|
||||
|
|
|
@ -102,8 +102,6 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
|
|||
@Nullable
|
||||
private Race clientPreferredRace;
|
||||
|
||||
private boolean invisible = false;
|
||||
|
||||
private int ticksInSun;
|
||||
private boolean hasShades;
|
||||
private int ticksSunImmunity = INITIAL_SUN_IMMUNITY;
|
||||
|
@ -225,20 +223,10 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
|
|||
return corruption;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvisible() {
|
||||
return invisible && SpellPredicate.IS_DISGUISE.isOn(this);
|
||||
}
|
||||
|
||||
public boolean isSpeciesPersisted() {
|
||||
return speciesPersisted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInvisible(boolean invisible) {
|
||||
this.invisible = invisible;
|
||||
}
|
||||
|
||||
public boolean isSunImmune() {
|
||||
return ticksSunImmunity > 0;
|
||||
}
|
||||
|
@ -673,7 +661,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
|
|||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
public static Pony of(@Nullable PlayerEntity player) {
|
||||
return player == null ? null : ((PonyContainer<Pony>)player).get();
|
||||
return player == null ? null : ((Container<Pony>)player).get();
|
||||
}
|
||||
|
||||
public static Stream<Pony> stream(Stream<Entity> entities) {
|
||||
|
@ -681,9 +669,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
|
|||
}
|
||||
|
||||
public static Optional<Pony> of(Entity entity) {
|
||||
return entity instanceof PlayerEntity
|
||||
? PonyContainer.of(entity).map(a -> (Pony)a.get())
|
||||
: Optional.empty();
|
||||
return Equine.<Entity, Pony>of(entity, a -> a instanceof Pony);
|
||||
}
|
||||
|
||||
public static boolean equal(GameProfile one, GameProfile two) {
|
||||
|
|
|
@ -129,7 +129,7 @@ public class CrystalHeartItem extends Item implements FloatingArtefactEntity.Art
|
|||
}
|
||||
});
|
||||
VecHelper.findInRange(entity, entity.world, entity.getPos(), 20, i -> {
|
||||
return i instanceof ItemEntity ie && isFillable(ie.getStack()) && PonyContainer.of(i).filter(p -> p.get().getSpecies() == Race.CHANGELING).isPresent();
|
||||
return i instanceof ItemEntity ie && isFillable(ie.getStack()) && Equine.of(i).filter(p -> p.getSpecies() == Race.CHANGELING).isPresent();
|
||||
}).forEach(i -> containers.add((ItemEntity)i));
|
||||
|
||||
int demand = outputs.size() + containers.stream().mapToInt(i -> i.getStack().getCount()).sum();
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.Equine;
|
||||
import com.minelittlepony.unicopia.entity.Living;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
|
@ -24,7 +24,7 @@ abstract class MixinDamageSource {
|
|||
if (self.isFromFalling()) {
|
||||
info.setReturnValue(new DamageSource(self.name + ".pegasus").getDeathMessage(entity));
|
||||
} else {
|
||||
Equine.of(entity).map(Equine::getAttacker).ifPresent(attacker -> {
|
||||
Living.getOrEmpty(entity).map(Living::getAttacker).ifPresent(attacker -> {
|
||||
Entity prime = entity.getPrimeAdversary();
|
||||
if (prime != null && !attacker.isOwnedBy(prime)) {
|
||||
info.setReturnValue(Text.translatable("death.attack.generic.and_also", info.getReturnValue(), attacker.asEntity().getDisplayName()));
|
||||
|
|
|
@ -6,8 +6,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.IItemEntity;
|
||||
import com.minelittlepony.unicopia.entity.ItemImpl;
|
||||
import com.minelittlepony.unicopia.entity.*;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
|
@ -21,14 +20,14 @@ abstract class MixinItemEntity extends Entity implements IItemEntity {
|
|||
private MixinItemEntity() { super(null, null); }
|
||||
|
||||
@Override
|
||||
public ItemImpl create() {
|
||||
public Equine<?> create() {
|
||||
return new ItemImpl((ItemEntity)(Object)this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemImpl get() {
|
||||
if (caster == null) {
|
||||
caster = create();
|
||||
caster = (ItemImpl)create();
|
||||
}
|
||||
return caster;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import net.minecraft.util.Hand;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
@Mixin(LivingEntity.class)
|
||||
abstract class MixinLivingEntity extends Entity implements LivingEntityDuck {
|
||||
abstract class MixinLivingEntity extends Entity implements LivingEntityDuck, Equine.Container<Living<?>> {
|
||||
@Shadow
|
||||
protected ItemStack activeItemStack;
|
||||
@Shadow
|
||||
|
@ -51,11 +51,11 @@ abstract class MixinLivingEntity extends Entity implements LivingEntityDuck {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Equine<?> get() {
|
||||
public Living<?> get() {
|
||||
if (caster == null) {
|
||||
caster = create();
|
||||
}
|
||||
return caster;
|
||||
return (Living<?>)caster;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,7 +17,7 @@ import net.minecraft.entity.mob.MobEntity;
|
|||
import net.minecraft.world.World;
|
||||
|
||||
@Mixin(MobEntity.class)
|
||||
abstract class MixinMobEntity extends LivingEntity implements PonyContainer<Equine<?>> {
|
||||
abstract class MixinMobEntity extends LivingEntity implements Equine.Container<Creature> {
|
||||
private MixinMobEntity() { super(null, null); }
|
||||
|
||||
@Shadow
|
||||
|
@ -27,14 +27,12 @@ abstract class MixinMobEntity extends LivingEntity implements PonyContainer<Equi
|
|||
|
||||
@Inject(method = "<init>(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At("RETURN"))
|
||||
private void init(EntityType<? extends MobEntity> entityType, World world, CallbackInfo info) {
|
||||
((Creature)get()).initAi(goalSelector, targetSelector);
|
||||
get().initAi(goalSelector, targetSelector);
|
||||
}
|
||||
|
||||
@Inject(method = "tickNewAi", at = @At("HEAD"))
|
||||
public void beforeTickAi(CallbackInfo into) {
|
||||
Equine<?> eq = Equine.of(this).orElse(null);
|
||||
|
||||
if (eq instanceof Living<?> && eq.getPhysics().isGravityNegative()) {
|
||||
if (get().getPhysics().isGravityNegative()) {
|
||||
((RotatedView)world).pushRotation((int)getY());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.PonyContainer;
|
||||
import com.minelittlepony.unicopia.entity.duck.PlayerEntityDuck;
|
||||
import com.minelittlepony.unicopia.entity.Equine;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
|
@ -27,7 +26,7 @@ import net.minecraft.util.Unit;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
@Mixin(PlayerEntity.class)
|
||||
abstract class MixinPlayerEntity extends LivingEntity implements PonyContainer<Pony>, PlayerEntityDuck {
|
||||
abstract class MixinPlayerEntity extends LivingEntity implements Equine.Container<Pony>, PlayerEntityDuck {
|
||||
private MixinPlayerEntity() { super(null, null); }
|
||||
@Override
|
||||
@Invoker("updateCapeAngles")
|
||||
|
|
|
@ -6,7 +6,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.PonyContainer;
|
||||
import com.minelittlepony.unicopia.entity.Equine;
|
||||
import com.minelittlepony.unicopia.entity.duck.ServerPlayerEntityDuck;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
@ -14,7 +14,7 @@ import net.minecraft.screen.ScreenHandlerListener;
|
|||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
||||
@Mixin(ServerPlayerEntity.class)
|
||||
abstract class MixinServerPlayerEntity extends PlayerEntity implements ScreenHandlerListener, PonyContainer<Pony>, ServerPlayerEntityDuck {
|
||||
abstract class MixinServerPlayerEntity extends PlayerEntity implements ScreenHandlerListener, Equine.Container<Pony>, ServerPlayerEntityDuck {
|
||||
MixinServerPlayerEntity() {super(null, null, 0, null);}
|
||||
|
||||
@Override
|
||||
|
@ -24,7 +24,7 @@ abstract class MixinServerPlayerEntity extends PlayerEntity implements ScreenHan
|
|||
@SuppressWarnings("unchecked")
|
||||
@Inject(method = "copyFrom(Lnet/minecraft/server/network/ServerPlayerEntity;Z)V", at = @At("HEAD"))
|
||||
private void onCopyFrom(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo info) {
|
||||
get().copyFrom(((PonyContainer<Pony>)oldPlayer).get());
|
||||
get().copyFrom(((Equine.Container<Pony>)oldPlayer).get());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue