You can now disguise yourself as beds and chests, and they will preserve their direction

This commit is contained in:
Sollace 2020-09-27 18:49:08 +02:00
parent e83c552d93
commit e8b970bd82
5 changed files with 42 additions and 16 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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<FallingBlockEntity> {
}
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<FallingBlockEntity> {
@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<Entity> attachments = ((DisguiseSpell)spell).getDisguise().getAttachments();
if (attachments.size() > 0) {
copyBaseAttributes(source.getOwner(), attachments.get(0), UP);

View file

@ -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);
}

View file

@ -5,6 +5,7 @@
"refmap": "unicopia.mixin.refmap.json",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinBlockEntity",
"MixinBlockItem",
"MixinItem",
"MixinItemEntity",