diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DisguiseSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DisguiseSpell.java index d0eacf15..5322374d 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DisguiseSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DisguiseSpell.java @@ -268,7 +268,7 @@ public class DisguiseSpell extends AbstractSpell implements AttachableSpell, Sup entity.tick(); } - behaviour.update(source, entity); + behaviour.update(source, entity, this); if (source instanceof Pony) { Pony player = (Pony)source; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ChickenBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ChickenBehaviour.java index d763eda0..846d2008 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ChickenBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ChickenBehaviour.java @@ -1,6 +1,7 @@ package com.minelittlepony.unicopia.entity.behaviour; import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.ability.magic.Spell; import com.minelittlepony.unicopia.entity.player.Pony; import net.minecraft.entity.Entity; @@ -20,7 +21,7 @@ public class ChickenBehaviour extends EntityBehaviour { } @Override - public void update(Caster source, ChickenEntity entity) { + public void update(Caster source, ChickenEntity entity, Spell spell) { entity.eggLayTime = Integer.MAX_VALUE; if (source instanceof Pony) { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java index 9d8f6fe2..99094449 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java @@ -1,11 +1,13 @@ package com.minelittlepony.unicopia.entity.behaviour; import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.ability.magic.Spell; + import net.minecraft.entity.mob.CreeperEntity; public class CreeperBehaviour extends EntityBehaviour { @Override - public void update(Caster source, CreeperEntity entity) { + public void update(Caster source, CreeperEntity entity, Spell spell) { if (source.getEntity().isSneaking()) { entity.setFuseSpeed(1); } else { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EndermanBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EndermanBehaviour.java index 6aeac619..22e57c67 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EndermanBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EndermanBehaviour.java @@ -1,6 +1,7 @@ package com.minelittlepony.unicopia.entity.behaviour; import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.ability.magic.Spell; import net.minecraft.block.Blocks; import net.minecraft.entity.mob.EndermanEntity; @@ -10,7 +11,7 @@ import net.minecraft.util.Hand; public class EndermanBehaviour extends EntityBehaviour { @Override - public void update(Caster source, EndermanEntity entity) { + public void update(Caster source, EndermanEntity entity, Spell spell) { if (source.getOwner().isSneaking() || source.getOwner().isSprinting()) { entity.setTarget(entity); } else { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java index c748904c..6202378b 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java @@ -5,6 +5,7 @@ import java.util.function.Supplier; import javax.annotation.Nullable; import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.ability.magic.Spell; import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; import com.minelittlepony.unicopia.util.Registries; @@ -24,7 +25,7 @@ public class EntityBehaviour { private static final EntityBehaviour DEFAULT = new EntityBehaviour<>(); private static final Registry> REGISTRY = Registries.createSimple(new Identifier("unicopia", "entity_behaviour")); - public void update(Caster source, T entity) { + public void update(Caster source, T entity, Spell spell) { } @@ -175,6 +176,7 @@ public class EntityBehaviour { } static { + register(SheepBehaviour::new, EntityType.SHEEP); register(EndermanBehaviour::new, EntityType.ENDERMAN); register(SpellcastingIllagerBehaviour::new, EntityType.ILLUSIONER, EntityType.EVOKER); register(ShulkerBehaviour::new, EntityType.SHULKER); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MinecartBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MinecartBehaviour.java index b308f18c..c6067ce2 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MinecartBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MinecartBehaviour.java @@ -1,6 +1,7 @@ package com.minelittlepony.unicopia.entity.behaviour; import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.ability.magic.Spell; import net.minecraft.client.MinecraftClient; import net.minecraft.client.sound.MovingMinecartSoundInstance; @@ -18,7 +19,7 @@ public class MinecartBehaviour extends EntityBehaviour { } @Override - public void update(Caster source, AbstractMinecartEntity entity) { + public void update(Caster source, AbstractMinecartEntity entity, Spell spell) { entity.yaw -= 90; entity.prevYaw -= 90; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SheepBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SheepBehaviour.java new file mode 100644 index 00000000..e37407c7 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SheepBehaviour.java @@ -0,0 +1,77 @@ +package com.minelittlepony.unicopia.entity.behaviour; + +import java.util.Random; + +import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.ability.magic.Spell; +import com.minelittlepony.unicopia.entity.player.Pony; +import com.minelittlepony.unicopia.mixin.MixinSheepEntity; +import com.minelittlepony.unicopia.util.WorldEvent; + +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.entity.ItemEntity; +import net.minecraft.entity.passive.SheepEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; +import net.minecraft.util.math.BlockPos; + +public class SheepBehaviour extends EntityBehaviour { + @Override + public void update(Caster source, SheepEntity entity, Spell spell) { + if (source instanceof Pony) { + Pony player = (Pony)source; + + if (player.sneakingChanged()) { + + BlockPos pos = entity.getBlockPos().down(); + BlockState state = entity.world.getBlockState(pos); + boolean grass = state.isOf(Blocks.GRASS_BLOCK); + + if (player.getOwner().isSneaking()) { + if (grass && entity.world.isClient && entity.isSheared()) { + entity.handleStatus((byte)10); + } + } else { + if (entity.isSheared() && grass) { + WorldEvent.play(WorldEvent.DESTROY_BLOCK, entity.world, pos, state); + entity.world.setBlockState(pos, Blocks.DIRT.getDefaultState(), 2); + + entity.onEatingGrass(); + } else if (!entity.isSheared()) { + ItemStack dropType = new ItemStack(MixinSheepEntity.getDrops().get(entity.getColor()).asItem()); + + player.getOwner().playSound(SoundEvents.ENTITY_SHEEP_SHEAR, SoundCategory.PLAYERS, 1, 1); + entity.setSheared(true); + + Random rng = entity.world.random; + PlayerInventory inv = player.getOwner().inventory; + + int dropAmount = rng.nextInt(3); + int slot; + + do { + slot = inv.method_7371(dropType); + if (slot < 0) { + break; + } + inv.removeStack(slot, 1); + ItemEntity itemEntity = entity.dropItem(dropType.getItem(), 1); + if (itemEntity != null) { + itemEntity.setVelocity(itemEntity.getVelocity().add( + (rng.nextFloat() - rng.nextFloat()) * 0.1F, + rng.nextFloat() * 0.05F, + (rng.nextFloat() - rng.nextFloat()) * 0.1F + )); + itemEntity.setPickupDelay(40); + } + } while (dropAmount-- > 0); + } + spell.setDirty(true); + } + } + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ShulkerBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ShulkerBehaviour.java index 8e86731e..1af79c3c 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ShulkerBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ShulkerBehaviour.java @@ -1,6 +1,7 @@ package com.minelittlepony.unicopia.entity.behaviour; import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.ability.magic.Spell; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.mixin.MixinShulkerEntity; @@ -15,7 +16,7 @@ import net.minecraft.util.math.Vec3d; public class ShulkerBehaviour extends EntityBehaviour { @Override - public void update(Caster source, ShulkerEntity shulker) { + public void update(Caster source, ShulkerEntity shulker, Spell spell) { shulker.yaw = 0; shulker.prevBodyYaw = 0; shulker.bodyYaw = 0; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SilverfishBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SilverfishBehaviour.java index a0a147f1..62cf7b40 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SilverfishBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SilverfishBehaviour.java @@ -1,6 +1,7 @@ package com.minelittlepony.unicopia.entity.behaviour; import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.ability.magic.Spell; import com.minelittlepony.unicopia.block.state.StateMaps; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.util.WorldEvent; @@ -11,7 +12,7 @@ import net.minecraft.util.math.BlockPos; public class SilverfishBehaviour extends EntityBehaviour { @Override - public void update(Caster source, SilverfishEntity entity) { + public void update(Caster source, SilverfishEntity entity, Spell spell) { if (source instanceof Pony && !source.isClient()) { Pony player = (Pony)source; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SpellcastingIllagerBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SpellcastingIllagerBehaviour.java index 41f36988..a13579f4 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SpellcastingIllagerBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SpellcastingIllagerBehaviour.java @@ -1,13 +1,14 @@ package com.minelittlepony.unicopia.entity.behaviour; import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.ability.magic.Spell; import com.minelittlepony.unicopia.entity.player.Pony; import net.minecraft.entity.mob.SpellcastingIllagerEntity; public class SpellcastingIllagerBehaviour extends EntityBehaviour { @Override - public void update(Caster source, SpellcastingIllagerEntity entity) { + public void update(Caster source, SpellcastingIllagerEntity entity, Spell s) { if (source instanceof Pony) { Pony player = (Pony)source; diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinSheepEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinSheepEntity.java new file mode 100644 index 00000000..3d51be76 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinSheepEntity.java @@ -0,0 +1,18 @@ +package com.minelittlepony.unicopia.mixin; + +import java.util.Map; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import net.minecraft.entity.passive.SheepEntity; +import net.minecraft.item.ItemConvertible; +import net.minecraft.util.DyeColor; + +@Mixin(SheepEntity.class) +public interface MixinSheepEntity { + @Accessor("DROPS") + static Map getDrops() { + return null; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/network/EffectSync.java b/src/main/java/com/minelittlepony/unicopia/network/EffectSync.java index 85e5f60b..a3030ee8 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/EffectSync.java +++ b/src/main/java/com/minelittlepony/unicopia/network/EffectSync.java @@ -27,6 +27,9 @@ public class EffectSync { private final TrackedData param; + @Nullable + private CompoundTag lastValue; + public EffectSync(Caster owned, TrackedData param) { this.owned = owned; this.param = param; @@ -68,14 +71,18 @@ public class EffectSync { @SuppressWarnings("unchecked") public E get(Class type, boolean update) { - if (!update) { - if (effect == null || type == null || type.isAssignableFrom(effect.getClass())) { - return (E)effect; - } - - return null; + if (update) { + sync(); } + if (effect == null || type == null || type.isAssignableFrom(effect.getClass())) { + return (E)effect; + } + + return null; + } + + private void sync() { CompoundTag comp = owned.getEntity().getDataTracker().get(param); if (comp == null || !comp.contains("effect_id")) { @@ -83,6 +90,7 @@ public class EffectSync { effect.setDead(); effect = null; } + return; } else { String id = comp.getString("effect_id"); @@ -92,17 +100,14 @@ public class EffectSync { } effect = SpellRegistry.instance().createEffectFromNBT(comp); } else if (owned.getEntity().world.isClient()) { - effect.fromNBT(comp); + if (lastValue != comp || !(comp == null || comp.equals(lastValue))) { + lastValue = comp; + effect.fromNBT(comp); + } } else if (effect.isDirty()) { set(effect); } } - - if (effect == null || type == null || type.isAssignableFrom(effect.getClass())) { - return (E)effect; - } - - return null; } public void set(@Nullable Spell effect) { diff --git a/src/main/resources/unicopia.mixin.json b/src/main/resources/unicopia.mixin.json index ec20a04d..d8ff26c9 100644 --- a/src/main/resources/unicopia.mixin.json +++ b/src/main/resources/unicopia.mixin.json @@ -13,6 +13,7 @@ "MixinPlayerEntity", "MixinProjectileEntity", "MixinServerPlayerEntity", + "MixinSheepEntity", "MixinShulkerEntity", "MixinTargetPredicate" ],