mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Cleanup and move duck interfaces to a dedicated package
This commit is contained in:
parent
1cea2bf391
commit
7b58fdb6ba
25 changed files with 82 additions and 95 deletions
|
@ -5,7 +5,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.HomingSpell;
|
|||
import com.minelittlepony.unicopia.ability.magic.spell.Situation;
|
||||
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
|
||||
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
|
||||
import com.minelittlepony.unicopia.entity.LavaAffine;
|
||||
import com.minelittlepony.unicopia.entity.duck.LavaAffine;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package com.minelittlepony.unicopia.entity;
|
||||
|
||||
public interface CapeHolder {
|
||||
void callUpdateCapeAngles();
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package com.minelittlepony.unicopia.entity;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Hand;
|
||||
|
||||
public interface ItemWielder {
|
||||
void updateItemUsage(Hand hand, ItemStack stack, int time);
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package com.minelittlepony.unicopia.entity;
|
||||
|
||||
public interface Jumper {
|
||||
boolean isJumping();
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package com.minelittlepony.unicopia.entity;
|
||||
|
||||
public interface Leaner {
|
||||
float getLeaningPitch();
|
||||
|
||||
void setLeaningPitch(float pitch);
|
||||
|
||||
float getLastLeaningPitch();
|
||||
|
||||
void setLastLeaningPitch(float pitch);
|
||||
|
||||
default void copyFrom(Leaner other) {
|
||||
setLeaningPitch(other.getLeaningPitch());
|
||||
setLastLeaningPitch(other.getLastLeaningPitch());
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package com.minelittlepony.unicopia.entity;
|
||||
|
||||
public interface MotionChecker {
|
||||
void setPreventMotionChecks(boolean enabled);
|
||||
}
|
|
@ -7,9 +7,9 @@ import org.jetbrains.annotations.Nullable;
|
|||
|
||||
import com.minelittlepony.unicopia.Unicopia;
|
||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||
import com.minelittlepony.unicopia.entity.ItemWielder;
|
||||
import com.minelittlepony.unicopia.entity.duck.LivingEntityDuck;
|
||||
import com.minelittlepony.unicopia.entity.duck.EntityDuck;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.entity.Removeable;
|
||||
import com.minelittlepony.unicopia.util.Registries;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
|
@ -105,7 +105,7 @@ public class EntityBehaviour<T extends Entity> {
|
|||
public void copyBaseAttributes(LivingEntity from, Entity to, Vec3d positionOffset) {
|
||||
// Set first because position calculations rely on it
|
||||
to.age = from.age;
|
||||
((Removeable)to).setRemovalReason(from.getRemovalReason());
|
||||
((EntityDuck)to).setRemovalReason(from.getRemovalReason());
|
||||
to.setOnGround(from.isOnGround());
|
||||
|
||||
if (!from.world.isClient) {
|
||||
|
@ -146,8 +146,8 @@ public class EntityBehaviour<T extends Entity> {
|
|||
|
||||
to.updatePosition(x, y, z);
|
||||
|
||||
if (to instanceof FallingBlockEntity) {
|
||||
((FallingBlockEntity)to).setFallingBlockPos(from.getBlockPos());
|
||||
if (to instanceof FallingBlockEntity fbe) {
|
||||
fbe.setFallingBlockPos(from.getBlockPos());
|
||||
}
|
||||
} else {
|
||||
to.copyPositionAndRotation(from);
|
||||
|
@ -170,13 +170,11 @@ public class EntityBehaviour<T extends Entity> {
|
|||
to.horizontalSpeed = from.horizontalSpeed;
|
||||
to.prevHorizontalSpeed = from.prevHorizontalSpeed;
|
||||
to.setOnGround(from.isOnGround());
|
||||
to.setInvulnerable(from.isInvulnerable() || (from instanceof PlayerEntity && ((PlayerEntity)from).getAbilities().creativeMode));
|
||||
to.setInvulnerable(from.isInvulnerable() || (from instanceof PlayerEntity player && player.getAbilities().creativeMode));
|
||||
|
||||
to.distanceTraveled = from.distanceTraveled;
|
||||
|
||||
if (to instanceof LivingEntity) {
|
||||
LivingEntity l = (LivingEntity)to;
|
||||
|
||||
if (to instanceof LivingEntity l) {
|
||||
l.headYaw = from.headYaw;
|
||||
l.prevHeadYaw = from.prevHeadYaw;
|
||||
l.bodyYaw = from.bodyYaw;
|
||||
|
@ -205,19 +203,19 @@ public class EntityBehaviour<T extends Entity> {
|
|||
copyInventory(from, l);
|
||||
}
|
||||
|
||||
if (to instanceof TameableEntity) {
|
||||
((TameableEntity)to).setSitting(from.isSneaking());
|
||||
if (to instanceof TameableEntity tameable) {
|
||||
tameable.setSitting(from.isSneaking());
|
||||
}
|
||||
|
||||
if (to instanceof AbstractSkeletonEntity) {
|
||||
((AbstractSkeletonEntity)to).setAttacking(from.getItemUseTimeLeft() > 0);
|
||||
if (to instanceof AbstractSkeletonEntity skeleton) {
|
||||
skeleton.setAttacking(from.getItemUseTimeLeft() > 0);
|
||||
}
|
||||
|
||||
if (to instanceof ItemWielder) {
|
||||
((ItemWielder)to).updateItemUsage(from.getActiveHand(), from.getActiveItem(), from.getItemUseTimeLeft());
|
||||
if (to instanceof LivingEntityDuck duck) {
|
||||
duck.updateItemUsage(from.getActiveHand(), from.getActiveItem(), from.getItemUseTimeLeft());
|
||||
}
|
||||
|
||||
if (from.age < 100 || from instanceof PlayerEntity && (((PlayerEntity)from).isCreative() || ((PlayerEntity)from).isSpectator())) {
|
||||
if (from.age < 100 || from instanceof PlayerEntity player && (player.isCreative() || player.isSpectator())) {
|
||||
to.extinguish();
|
||||
}
|
||||
|
||||
|
@ -251,7 +249,7 @@ public class EntityBehaviour<T extends Entity> {
|
|||
|
||||
protected boolean isSneakingOnGround(Caster<?> source) {
|
||||
Entity e = source.getEntity();
|
||||
return e.isSneaking() && (e.isOnGround() && !(e instanceof PlayerEntity && ((PlayerEntity)e).getAbilities().flying));
|
||||
return e.isSneaking() && (e.isOnGround() && !(e instanceof PlayerEntity player && player.getAbilities().flying));
|
||||
}
|
||||
|
||||
public static <T extends Entity> void register(Supplier<EntityBehaviour<T>> behaviour, EntityType<?>... types) {
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package com.minelittlepony.unicopia.entity.behaviour;
|
||||
|
||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||
import com.minelittlepony.unicopia.entity.CapeHolder;
|
||||
import com.minelittlepony.unicopia.entity.Leaner;
|
||||
import com.minelittlepony.unicopia.entity.duck.*;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
@ -10,8 +9,8 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||
public class PlayerBehaviour extends EntityBehaviour<PlayerEntity> {
|
||||
@Override
|
||||
public void update(Caster<?> source, PlayerEntity entity, Disguise spell) {
|
||||
if (source instanceof Pony) {
|
||||
PlayerEntity pFrom = ((Pony)source).getMaster();
|
||||
if (source instanceof Pony pony) {
|
||||
PlayerEntity pFrom = pony.getMaster();
|
||||
|
||||
entity.capeX = pFrom.capeX;
|
||||
entity.capeY = pFrom.capeY;
|
||||
|
@ -20,7 +19,7 @@ public class PlayerBehaviour extends EntityBehaviour<PlayerEntity> {
|
|||
entity.prevCapeY = pFrom.prevCapeY;
|
||||
entity.prevCapeZ = pFrom.prevCapeZ;
|
||||
} else {
|
||||
((CapeHolder)entity).callUpdateCapeAngles();
|
||||
((PlayerEntityDuck)entity).callUpdateCapeAngles();
|
||||
}
|
||||
|
||||
if (source.getEntity().getPose() != entity.getPose()) {
|
||||
|
@ -29,8 +28,8 @@ public class PlayerBehaviour extends EntityBehaviour<PlayerEntity> {
|
|||
if (source.getEntity().isSwimming() != entity.isSwimming()) {
|
||||
entity.setSwimming(source.getEntity().isSwimming());
|
||||
}
|
||||
if (source.getEntity() instanceof Leaner) {
|
||||
((Leaner)entity).copyFrom(((Leaner)source.getEntity()));
|
||||
if (source.getEntity() instanceof LivingEntityDuck duck) {
|
||||
duck.copyLeaningAnglesFrom(((LivingEntityDuck)source.getEntity()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.minelittlepony.unicopia.entity;
|
||||
package com.minelittlepony.unicopia.entity.duck;
|
||||
|
||||
import net.minecraft.entity.Entity.RemovalReason;
|
||||
|
||||
public interface Removeable {
|
||||
public interface EntityDuck {
|
||||
void setRemovalReason(RemovalReason reason);
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.minelittlepony.unicopia.entity;
|
||||
package com.minelittlepony.unicopia.entity.duck;
|
||||
|
||||
public interface LavaAffine {
|
||||
void setLavaAffine(boolean lavaAffine);
|
|
@ -0,0 +1,23 @@
|
|||
package com.minelittlepony.unicopia.entity.duck;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Hand;
|
||||
|
||||
public interface LivingEntityDuck {
|
||||
void updateItemUsage(Hand hand, ItemStack stack, int time);
|
||||
|
||||
boolean isJumping();
|
||||
|
||||
float getLeaningPitch();
|
||||
|
||||
void setLeaningPitch(float pitch);
|
||||
|
||||
float getLastLeaningPitch();
|
||||
|
||||
void setLastLeaningPitch(float pitch);
|
||||
|
||||
default void copyLeaningAnglesFrom(LivingEntityDuck other) {
|
||||
setLeaningPitch(other.getLeaningPitch());
|
||||
setLastLeaningPitch(other.getLastLeaningPitch());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.minelittlepony.unicopia.entity.duck;
|
||||
|
||||
public interface PlayerEntityDuck {
|
||||
void callUpdateCapeAngles();
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.minelittlepony.unicopia.entity;
|
||||
package com.minelittlepony.unicopia.entity.duck;
|
||||
|
||||
import java.util.Stack;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package com.minelittlepony.unicopia.entity.duck;
|
||||
|
||||
public interface ServerPlayerEntityDuck {
|
||||
void setPreventMotionChecks(boolean enabled);
|
||||
}
|
|
@ -9,6 +9,8 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
|
|||
import com.minelittlepony.unicopia.advancement.UCriteria;
|
||||
import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation;
|
||||
import com.minelittlepony.unicopia.entity.*;
|
||||
import com.minelittlepony.unicopia.entity.duck.LivingEntityDuck;
|
||||
import com.minelittlepony.unicopia.entity.duck.Leaner;
|
||||
import com.minelittlepony.unicopia.entity.player.MagicReserves.Bar;
|
||||
import com.minelittlepony.unicopia.item.AmuletItem;
|
||||
import com.minelittlepony.unicopia.item.UItems;
|
||||
|
@ -231,7 +233,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
|
|||
cancelFlight();
|
||||
}
|
||||
|
||||
if (entity.isClimbing() && (entity.horizontalCollision || ((Jumper)entity).isJumping())) {
|
||||
if (entity.isClimbing() && (entity.horizontalCollision || ((LivingEntityDuck)entity).isJumping())) {
|
||||
velocity.y = -0.2F;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.spongepowered.asm.mixin.Mixin;
|
|||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.LavaAffine;
|
||||
import com.minelittlepony.unicopia.entity.duck.LavaAffine;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.data.*;
|
||||
|
@ -67,5 +67,4 @@ abstract class MixinBoatEntity extends Entity implements LavaAffine {
|
|||
public boolean isLavaAffine() {
|
||||
return dataTracker.get(IS_LAVA_BOAT);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,10 @@ import org.spongepowered.asm.mixin.Mixin;
|
|||
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.RotatedView;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.Equine;
|
||||
import com.minelittlepony.unicopia.entity.Living;
|
||||
import com.minelittlepony.unicopia.entity.duck.RotatedView;
|
||||
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.ai.brain.Brain;
|
||||
|
|
|
@ -6,14 +6,14 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.LavaAffine;
|
||||
import com.minelittlepony.unicopia.entity.Removeable;
|
||||
import com.minelittlepony.unicopia.entity.duck.LavaAffine;
|
||||
import com.minelittlepony.unicopia.entity.duck.EntityDuck;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.Entity.RemovalReason;
|
||||
|
||||
@Mixin(Entity.class)
|
||||
abstract class MixinEntity implements Removeable {
|
||||
abstract class MixinEntity implements EntityDuck {
|
||||
@Override
|
||||
@Accessor
|
||||
public abstract void setRemovalReason(RemovalReason reason);
|
||||
|
|
|
@ -15,14 +15,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||
import com.minelittlepony.unicopia.ability.magic.SpellPredicate;
|
||||
import com.minelittlepony.unicopia.ability.magic.spell.AbstractDisguiseSpell;
|
||||
import com.minelittlepony.unicopia.entity.Creature;
|
||||
import com.minelittlepony.unicopia.entity.PonyContainer;
|
||||
import com.minelittlepony.unicopia.entity.*;
|
||||
import com.minelittlepony.unicopia.entity.behaviour.EntityAppearance;
|
||||
import com.minelittlepony.unicopia.entity.duck.*;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.entity.Equine;
|
||||
import com.minelittlepony.unicopia.entity.ItemWielder;
|
||||
import com.minelittlepony.unicopia.entity.Jumper;
|
||||
import com.minelittlepony.unicopia.entity.Leaner;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
@ -34,7 +30,7 @@ import net.minecraft.util.Hand;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
@Mixin(LivingEntity.class)
|
||||
abstract class MixinLivingEntity extends Entity implements PonyContainer<Equine<?>>, ItemWielder, Jumper, Leaner {
|
||||
abstract class MixinLivingEntity extends Entity implements PonyContainer<Equine<?>>, LivingEntityDuck {
|
||||
@Shadow
|
||||
protected ItemStack activeItemStack;
|
||||
@Shadow
|
||||
|
|
|
@ -6,11 +6,9 @@ import org.spongepowered.asm.mixin.Shadow;
|
|||
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.Creature;
|
||||
import com.minelittlepony.unicopia.entity.PonyContainer;
|
||||
import com.minelittlepony.unicopia.entity.RotatedView;
|
||||
import com.minelittlepony.unicopia.entity.Equine;
|
||||
import com.minelittlepony.unicopia.entity.Living;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.*;
|
||||
import com.minelittlepony.unicopia.entity.duck.RotatedView;
|
||||
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
|
|
@ -8,7 +8,7 @@ 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.CapeHolder;
|
||||
import com.minelittlepony.unicopia.entity.duck.PlayerEntityDuck;
|
||||
import com.minelittlepony.unicopia.entity.Equine;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.mojang.datafixers.util.Either;
|
||||
|
@ -28,7 +28,7 @@ import net.minecraft.util.math.BlockPos;
|
|||
import net.minecraft.world.World;
|
||||
|
||||
@Mixin(PlayerEntity.class)
|
||||
abstract class MixinPlayerEntity extends LivingEntity implements PonyContainer<Pony>, CapeHolder {
|
||||
abstract class MixinPlayerEntity extends LivingEntity implements PonyContainer<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.MotionChecker;
|
||||
import com.minelittlepony.unicopia.entity.duck.ServerPlayerEntityDuck;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
|
||||
import net.minecraft.network.NetworkThreadUtils;
|
||||
|
@ -45,7 +45,7 @@ abstract class MixinServerPlayNetworkHandler implements EntityTrackingListener,
|
|||
private void setPreventMotionChecks(boolean motionChecks) {
|
||||
ServerPlayerEntity player = ((ServerPlayNetworkHandler)(Object)this).player;
|
||||
prevMotionChecks = player.isInTeleportationState();
|
||||
((MotionChecker)player).setPreventMotionChecks(motionChecks);
|
||||
((ServerPlayerEntityDuck)player).setPreventMotionChecks(motionChecks);
|
||||
player.fallDistance = 0;
|
||||
floating = false;
|
||||
floatingTicks = 0;
|
||||
|
|
|
@ -7,7 +7,7 @@ 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.MotionChecker;
|
||||
import com.minelittlepony.unicopia.entity.duck.ServerPlayerEntityDuck;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
@ -15,7 +15,7 @@ import net.minecraft.screen.ScreenHandlerListener;
|
|||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
||||
@Mixin(ServerPlayerEntity.class)
|
||||
abstract class MixinServerPlayerEntity extends PlayerEntity implements ScreenHandlerListener, PonyContainer<Pony>, MotionChecker {
|
||||
abstract class MixinServerPlayerEntity extends PlayerEntity implements ScreenHandlerListener, PonyContainer<Pony>, ServerPlayerEntityDuck {
|
||||
MixinServerPlayerEntity() {super(null, null, 0, null, null);}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,8 +13,8 @@ import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
|||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import com.minelittlepony.unicopia.BlockDestructionManager;
|
||||
import com.minelittlepony.unicopia.entity.RotatedView;
|
||||
import com.minelittlepony.unicopia.entity.behaviour.EntityAppearance;
|
||||
import com.minelittlepony.unicopia.entity.duck.RotatedView;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.spongepowered.asm.mixin.Mixin;
|
|||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.RotatedView;
|
||||
import com.minelittlepony.unicopia.entity.duck.RotatedView;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.chunk.WorldChunk;
|
||||
|
|
Loading…
Reference in a new issue