From e8b970bd82f5d802c7b39e28bfe9c325fc6ed5ae Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 27 Sep 2020 18:49:08 +0200 Subject: [PATCH] You can now disguise yourself as beds and chests, and they will preserve their direction --- .../client/render/WorldRenderDelegate.java | 10 ++++++++++ .../unicopia/entity/behaviour/Disguise.java | 15 --------------- .../behaviour/FallingBlockBehaviour.java | 19 ++++++++++++++++++- .../unicopia/mixin/MixinBlockEntity.java | 13 +++++++++++++ src/main/resources/unicopia.mixin.json | 1 + 5 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/mixin/MixinBlockEntity.java diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/WorldRenderDelegate.java b/src/main/java/com/minelittlepony/unicopia/client/render/WorldRenderDelegate.java index 9c42dfb5..87558b4e 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/WorldRenderDelegate.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/WorldRenderDelegate.java @@ -6,6 +6,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; import com.minelittlepony.unicopia.entity.behaviour.Disguise; import com.minelittlepony.unicopia.entity.player.Pony; +import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; import net.minecraft.client.MinecraftClient; import net.minecraft.client.model.Model; @@ -21,6 +22,8 @@ import net.minecraft.client.util.math.Vector3f; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.state.property.Properties; +import net.minecraft.util.math.Direction; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; @@ -99,7 +102,14 @@ public class WorldRenderDelegate { blockEntity.setPos(e.getBlockPos()); matrices.push(); + BlockState state = blockEntity.getCachedState(); + Direction direction = state.contains(Properties.HORIZONTAL_FACING) ? state.get(Properties.HORIZONTAL_FACING) : Direction.UP; + matrices.translate(x, y, z); + + matrices.multiply(direction.getRotationQuaternion()); + matrices.multiply(Vector3f.NEGATIVE_X.getDegreesQuaternion(90)); + matrices.translate(-0.5, 0, -0.5); BlockEntityRenderDispatcher.INSTANCE.get(blockEntity).render(blockEntity, 1, matrices, vertexConsumers, light, OverlayTexture.DEFAULT_UV); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/Disguise.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/Disguise.java index 72fec4af..3e5be153 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/Disguise.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/Disguise.java @@ -49,9 +49,6 @@ public class Disguise implements NbtSerialisable { @Nullable private CompoundTag entityNbt; - @Nullable - private CompoundTag blockEntityNbt; - @Nullable public Entity getAppearance() { return entity; @@ -113,7 +110,6 @@ public class Disguise implements NbtSerialisable { if (entity == null && entityNbt != null) { CompoundTag nbt = entityNbt; entityNbt = null; - blockEntityNbt = null; attachments.clear(); if ("player".equals(entityId)) { @@ -227,12 +223,6 @@ public class Disguise implements NbtSerialisable { } else if (entity != null) { compound.put("entity", encodeEntityToNBT(entity)); } - - if (blockEntityNbt != null) { - compound.put("blockEntity", blockEntityNbt); - } else if (blockEntity != null) { - compound.put("blockEntity", blockEntity.toInitialChunkDataTag()); - } } @Override @@ -241,14 +231,9 @@ public class Disguise implements NbtSerialisable { if (!newId.contentEquals(entityId)) { entityNbt = null; - blockEntityNbt = null; remove(); } - if (compound.contains("blockEntity")) { - blockEntityNbt = compound.getCompound("blockEntityNbt"); - } - if (compound.contains("entity")) { entityId = newId; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/FallingBlockBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/FallingBlockBehaviour.java index 31f3d399..767ae71b 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/FallingBlockBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/FallingBlockBehaviour.java @@ -5,15 +5,18 @@ import java.util.List; 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.mixin.MixinBlockEntity; import net.minecraft.block.Block; import net.minecraft.block.BlockEntityProvider; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.DoorBlock; +import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.enums.DoubleBlockHalf; import net.minecraft.entity.Entity; import net.minecraft.entity.FallingBlockEntity; +import net.minecraft.state.property.Properties; import net.minecraft.tag.BlockTags; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; @@ -42,7 +45,9 @@ public class FallingBlockBehaviour extends EntityBehaviour { } if (block instanceof BlockEntityProvider) { - context.addBlockEntity(((BlockEntityProvider)block).createBlockEntity(entity.world)); + BlockEntity b = ((BlockEntityProvider)block).createBlockEntity(entity.world); + ((MixinBlockEntity)b).setCachedState(state); + context.addBlockEntity(b); } return entity; @@ -50,6 +55,18 @@ public class FallingBlockBehaviour extends EntityBehaviour { @Override public void update(Caster source, FallingBlockEntity entity, Spell spell) { + + BlockState state = entity.getBlockState(); + if (state.contains(Properties.WATERLOGGED)) { + boolean logged = entity.world.isWater(entity.getBlockPos()); + + if (state.get(Properties.WATERLOGGED) != logged) { + entity = new FallingBlockEntity(entity.world, entity.getX(), entity.getY(), entity.getZ(), state.with(Properties.WATERLOGGED, logged)); + ((DisguiseSpell)spell).getDisguise().setAppearance(entity); + return; + } + } + List attachments = ((DisguiseSpell)spell).getDisguise().getAttachments(); if (attachments.size() > 0) { copyBaseAttributes(source.getOwner(), attachments.get(0), UP); diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinBlockEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinBlockEntity.java new file mode 100644 index 00000000..726a1c07 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinBlockEntity.java @@ -0,0 +1,13 @@ +package com.minelittlepony.unicopia.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; + +@Mixin(BlockEntity.class) +public interface MixinBlockEntity { + @Accessor("cachedState") + void setCachedState(BlockState state); +} diff --git a/src/main/resources/unicopia.mixin.json b/src/main/resources/unicopia.mixin.json index 9bc4e1ad..1a29e3da 100644 --- a/src/main/resources/unicopia.mixin.json +++ b/src/main/resources/unicopia.mixin.json @@ -5,6 +5,7 @@ "refmap": "unicopia.mixin.refmap.json", "compatibilityLevel": "JAVA_8", "mixins": [ + "MixinBlockEntity", "MixinBlockItem", "MixinItem", "MixinItemEntity",