mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Add behaviour for sheep
This commit is contained in:
parent
63cc8903c9
commit
2bb6df8b1b
13 changed files with 133 additions and 22 deletions
|
@ -268,7 +268,7 @@ public class DisguiseSpell extends AbstractSpell implements AttachableSpell, Sup
|
||||||
entity.tick();
|
entity.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
behaviour.update(source, entity);
|
behaviour.update(source, entity, this);
|
||||||
|
|
||||||
if (source instanceof Pony) {
|
if (source instanceof Pony) {
|
||||||
Pony player = (Pony)source;
|
Pony player = (Pony)source;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.minelittlepony.unicopia.entity.behaviour;
|
package com.minelittlepony.unicopia.entity.behaviour;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
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.entity.player.Pony;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
@ -20,7 +21,7 @@ public class ChickenBehaviour extends EntityBehaviour<ChickenEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Caster<?> source, ChickenEntity entity) {
|
public void update(Caster<?> source, ChickenEntity entity, Spell spell) {
|
||||||
entity.eggLayTime = Integer.MAX_VALUE;
|
entity.eggLayTime = Integer.MAX_VALUE;
|
||||||
|
|
||||||
if (source instanceof Pony) {
|
if (source instanceof Pony) {
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package com.minelittlepony.unicopia.entity.behaviour;
|
package com.minelittlepony.unicopia.entity.behaviour;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||||
|
import com.minelittlepony.unicopia.ability.magic.Spell;
|
||||||
|
|
||||||
import net.minecraft.entity.mob.CreeperEntity;
|
import net.minecraft.entity.mob.CreeperEntity;
|
||||||
|
|
||||||
public class CreeperBehaviour extends EntityBehaviour<CreeperEntity> {
|
public class CreeperBehaviour extends EntityBehaviour<CreeperEntity> {
|
||||||
@Override
|
@Override
|
||||||
public void update(Caster<?> source, CreeperEntity entity) {
|
public void update(Caster<?> source, CreeperEntity entity, Spell spell) {
|
||||||
if (source.getEntity().isSneaking()) {
|
if (source.getEntity().isSneaking()) {
|
||||||
entity.setFuseSpeed(1);
|
entity.setFuseSpeed(1);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.minelittlepony.unicopia.entity.behaviour;
|
package com.minelittlepony.unicopia.entity.behaviour;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||||
|
import com.minelittlepony.unicopia.ability.magic.Spell;
|
||||||
|
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.entity.mob.EndermanEntity;
|
import net.minecraft.entity.mob.EndermanEntity;
|
||||||
|
@ -10,7 +11,7 @@ import net.minecraft.util.Hand;
|
||||||
|
|
||||||
public class EndermanBehaviour extends EntityBehaviour<EndermanEntity> {
|
public class EndermanBehaviour extends EntityBehaviour<EndermanEntity> {
|
||||||
@Override
|
@Override
|
||||||
public void update(Caster<?> source, EndermanEntity entity) {
|
public void update(Caster<?> source, EndermanEntity entity, Spell spell) {
|
||||||
if (source.getOwner().isSneaking() || source.getOwner().isSprinting()) {
|
if (source.getOwner().isSneaking() || source.getOwner().isSprinting()) {
|
||||||
entity.setTarget(entity);
|
entity.setTarget(entity);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.function.Supplier;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
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.ability.magic.spell.DisguiseSpell;
|
||||||
import com.minelittlepony.unicopia.util.Registries;
|
import com.minelittlepony.unicopia.util.Registries;
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ public class EntityBehaviour<T extends Entity> {
|
||||||
private static final EntityBehaviour<Entity> DEFAULT = new EntityBehaviour<>();
|
private static final EntityBehaviour<Entity> DEFAULT = new EntityBehaviour<>();
|
||||||
private static final Registry<EntityBehaviour<?>> REGISTRY = Registries.createSimple(new Identifier("unicopia", "entity_behaviour"));
|
private static final Registry<EntityBehaviour<?>> 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<T extends Entity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
register(SheepBehaviour::new, EntityType.SHEEP);
|
||||||
register(EndermanBehaviour::new, EntityType.ENDERMAN);
|
register(EndermanBehaviour::new, EntityType.ENDERMAN);
|
||||||
register(SpellcastingIllagerBehaviour::new, EntityType.ILLUSIONER, EntityType.EVOKER);
|
register(SpellcastingIllagerBehaviour::new, EntityType.ILLUSIONER, EntityType.EVOKER);
|
||||||
register(ShulkerBehaviour::new, EntityType.SHULKER);
|
register(ShulkerBehaviour::new, EntityType.SHULKER);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.minelittlepony.unicopia.entity.behaviour;
|
package com.minelittlepony.unicopia.entity.behaviour;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||||
|
import com.minelittlepony.unicopia.ability.magic.Spell;
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.sound.MovingMinecartSoundInstance;
|
import net.minecraft.client.sound.MovingMinecartSoundInstance;
|
||||||
|
@ -18,7 +19,7 @@ public class MinecartBehaviour extends EntityBehaviour<AbstractMinecartEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Caster<?> source, AbstractMinecartEntity entity) {
|
public void update(Caster<?> source, AbstractMinecartEntity entity, Spell spell) {
|
||||||
entity.yaw -= 90;
|
entity.yaw -= 90;
|
||||||
entity.prevYaw -= 90;
|
entity.prevYaw -= 90;
|
||||||
|
|
||||||
|
|
|
@ -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<SheepEntity> {
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package com.minelittlepony.unicopia.entity.behaviour;
|
package com.minelittlepony.unicopia.entity.behaviour;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
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.entity.player.Pony;
|
||||||
import com.minelittlepony.unicopia.mixin.MixinShulkerEntity;
|
import com.minelittlepony.unicopia.mixin.MixinShulkerEntity;
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
public class ShulkerBehaviour extends EntityBehaviour<ShulkerEntity> {
|
public class ShulkerBehaviour extends EntityBehaviour<ShulkerEntity> {
|
||||||
@Override
|
@Override
|
||||||
public void update(Caster<?> source, ShulkerEntity shulker) {
|
public void update(Caster<?> source, ShulkerEntity shulker, Spell spell) {
|
||||||
shulker.yaw = 0;
|
shulker.yaw = 0;
|
||||||
shulker.prevBodyYaw = 0;
|
shulker.prevBodyYaw = 0;
|
||||||
shulker.bodyYaw = 0;
|
shulker.bodyYaw = 0;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.minelittlepony.unicopia.entity.behaviour;
|
package com.minelittlepony.unicopia.entity.behaviour;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
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.block.state.StateMaps;
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||||
import com.minelittlepony.unicopia.util.WorldEvent;
|
import com.minelittlepony.unicopia.util.WorldEvent;
|
||||||
|
@ -11,7 +12,7 @@ import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
public class SilverfishBehaviour extends EntityBehaviour<SilverfishEntity> {
|
public class SilverfishBehaviour extends EntityBehaviour<SilverfishEntity> {
|
||||||
@Override
|
@Override
|
||||||
public void update(Caster<?> source, SilverfishEntity entity) {
|
public void update(Caster<?> source, SilverfishEntity entity, Spell spell) {
|
||||||
if (source instanceof Pony && !source.isClient()) {
|
if (source instanceof Pony && !source.isClient()) {
|
||||||
Pony player = (Pony)source;
|
Pony player = (Pony)source;
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
package com.minelittlepony.unicopia.entity.behaviour;
|
package com.minelittlepony.unicopia.entity.behaviour;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
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.entity.player.Pony;
|
||||||
|
|
||||||
import net.minecraft.entity.mob.SpellcastingIllagerEntity;
|
import net.minecraft.entity.mob.SpellcastingIllagerEntity;
|
||||||
|
|
||||||
public class SpellcastingIllagerBehaviour extends EntityBehaviour<SpellcastingIllagerEntity> {
|
public class SpellcastingIllagerBehaviour extends EntityBehaviour<SpellcastingIllagerEntity> {
|
||||||
@Override
|
@Override
|
||||||
public void update(Caster<?> source, SpellcastingIllagerEntity entity) {
|
public void update(Caster<?> source, SpellcastingIllagerEntity entity, Spell s) {
|
||||||
|
|
||||||
if (source instanceof Pony) {
|
if (source instanceof Pony) {
|
||||||
Pony player = (Pony)source;
|
Pony player = (Pony)source;
|
||||||
|
|
|
@ -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<DyeColor, ItemConvertible> getDrops() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,6 +27,9 @@ public class EffectSync {
|
||||||
|
|
||||||
private final TrackedData<CompoundTag> param;
|
private final TrackedData<CompoundTag> param;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private CompoundTag lastValue;
|
||||||
|
|
||||||
public EffectSync(Caster<?> owned, TrackedData<CompoundTag> param) {
|
public EffectSync(Caster<?> owned, TrackedData<CompoundTag> param) {
|
||||||
this.owned = owned;
|
this.owned = owned;
|
||||||
this.param = param;
|
this.param = param;
|
||||||
|
@ -68,14 +71,18 @@ public class EffectSync {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <E extends Spell> E get(Class<E> type, boolean update) {
|
public <E extends Spell> E get(Class<E> type, boolean update) {
|
||||||
if (!update) {
|
if (update) {
|
||||||
if (effect == null || type == null || type.isAssignableFrom(effect.getClass())) {
|
sync();
|
||||||
return (E)effect;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (effect == null || type == null || type.isAssignableFrom(effect.getClass())) {
|
||||||
|
return (E)effect;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sync() {
|
||||||
CompoundTag comp = owned.getEntity().getDataTracker().get(param);
|
CompoundTag comp = owned.getEntity().getDataTracker().get(param);
|
||||||
|
|
||||||
if (comp == null || !comp.contains("effect_id")) {
|
if (comp == null || !comp.contains("effect_id")) {
|
||||||
|
@ -83,6 +90,7 @@ public class EffectSync {
|
||||||
effect.setDead();
|
effect.setDead();
|
||||||
effect = null;
|
effect = null;
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
String id = comp.getString("effect_id");
|
String id = comp.getString("effect_id");
|
||||||
|
|
||||||
|
@ -92,17 +100,14 @@ public class EffectSync {
|
||||||
}
|
}
|
||||||
effect = SpellRegistry.instance().createEffectFromNBT(comp);
|
effect = SpellRegistry.instance().createEffectFromNBT(comp);
|
||||||
} else if (owned.getEntity().world.isClient()) {
|
} 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()) {
|
} else if (effect.isDirty()) {
|
||||||
set(effect);
|
set(effect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (effect == null || type == null || type.isAssignableFrom(effect.getClass())) {
|
|
||||||
return (E)effect;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(@Nullable Spell effect) {
|
public void set(@Nullable Spell effect) {
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
"MixinPlayerEntity",
|
"MixinPlayerEntity",
|
||||||
"MixinProjectileEntity",
|
"MixinProjectileEntity",
|
||||||
"MixinServerPlayerEntity",
|
"MixinServerPlayerEntity",
|
||||||
|
"MixinSheepEntity",
|
||||||
"MixinShulkerEntity",
|
"MixinShulkerEntity",
|
||||||
"MixinTargetPredicate"
|
"MixinTargetPredicate"
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue