mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 23:27:59 +01:00
You can now disguise yourself as beds and chests, and they will preserve their direction
This commit is contained in:
parent
e83c552d93
commit
e8b970bd82
5 changed files with 42 additions and 16 deletions
|
@ -6,6 +6,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell;
|
||||||
import com.minelittlepony.unicopia.entity.behaviour.Disguise;
|
import com.minelittlepony.unicopia.entity.behaviour.Disguise;
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||||
|
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.model.Model;
|
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.Entity;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
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.MathHelper;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
|
@ -99,7 +102,14 @@ public class WorldRenderDelegate {
|
||||||
blockEntity.setPos(e.getBlockPos());
|
blockEntity.setPos(e.getBlockPos());
|
||||||
matrices.push();
|
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.translate(x, y, z);
|
||||||
|
|
||||||
|
matrices.multiply(direction.getRotationQuaternion());
|
||||||
|
matrices.multiply(Vector3f.NEGATIVE_X.getDegreesQuaternion(90));
|
||||||
|
|
||||||
matrices.translate(-0.5, 0, -0.5);
|
matrices.translate(-0.5, 0, -0.5);
|
||||||
|
|
||||||
BlockEntityRenderDispatcher.INSTANCE.get(blockEntity).render(blockEntity, 1, matrices, vertexConsumers, light, OverlayTexture.DEFAULT_UV);
|
BlockEntityRenderDispatcher.INSTANCE.get(blockEntity).render(blockEntity, 1, matrices, vertexConsumers, light, OverlayTexture.DEFAULT_UV);
|
||||||
|
|
|
@ -49,9 +49,6 @@ public class Disguise implements NbtSerialisable {
|
||||||
@Nullable
|
@Nullable
|
||||||
private CompoundTag entityNbt;
|
private CompoundTag entityNbt;
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private CompoundTag blockEntityNbt;
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Entity getAppearance() {
|
public Entity getAppearance() {
|
||||||
return entity;
|
return entity;
|
||||||
|
@ -113,7 +110,6 @@ public class Disguise implements NbtSerialisable {
|
||||||
if (entity == null && entityNbt != null) {
|
if (entity == null && entityNbt != null) {
|
||||||
CompoundTag nbt = entityNbt;
|
CompoundTag nbt = entityNbt;
|
||||||
entityNbt = null;
|
entityNbt = null;
|
||||||
blockEntityNbt = null;
|
|
||||||
attachments.clear();
|
attachments.clear();
|
||||||
|
|
||||||
if ("player".equals(entityId)) {
|
if ("player".equals(entityId)) {
|
||||||
|
@ -227,12 +223,6 @@ public class Disguise implements NbtSerialisable {
|
||||||
} else if (entity != null) {
|
} else if (entity != null) {
|
||||||
compound.put("entity", encodeEntityToNBT(entity));
|
compound.put("entity", encodeEntityToNBT(entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blockEntityNbt != null) {
|
|
||||||
compound.put("blockEntity", blockEntityNbt);
|
|
||||||
} else if (blockEntity != null) {
|
|
||||||
compound.put("blockEntity", blockEntity.toInitialChunkDataTag());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -241,14 +231,9 @@ public class Disguise implements NbtSerialisable {
|
||||||
|
|
||||||
if (!newId.contentEquals(entityId)) {
|
if (!newId.contentEquals(entityId)) {
|
||||||
entityNbt = null;
|
entityNbt = null;
|
||||||
blockEntityNbt = null;
|
|
||||||
remove();
|
remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compound.contains("blockEntity")) {
|
|
||||||
blockEntityNbt = compound.getCompound("blockEntityNbt");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (compound.contains("entity")) {
|
if (compound.contains("entity")) {
|
||||||
entityId = newId;
|
entityId = newId;
|
||||||
|
|
||||||
|
|
|
@ -5,15 +5,18 @@ import java.util.List;
|
||||||
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;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell;
|
import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell;
|
||||||
|
import com.minelittlepony.unicopia.mixin.MixinBlockEntity;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockEntityProvider;
|
import net.minecraft.block.BlockEntityProvider;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.DoorBlock;
|
import net.minecraft.block.DoorBlock;
|
||||||
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
import net.minecraft.block.enums.DoubleBlockHalf;
|
import net.minecraft.block.enums.DoubleBlockHalf;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.FallingBlockEntity;
|
import net.minecraft.entity.FallingBlockEntity;
|
||||||
|
import net.minecraft.state.property.Properties;
|
||||||
import net.minecraft.tag.BlockTags;
|
import net.minecraft.tag.BlockTags;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
@ -42,7 +45,9 @@ public class FallingBlockBehaviour extends EntityBehaviour<FallingBlockEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block instanceof BlockEntityProvider) {
|
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;
|
return entity;
|
||||||
|
@ -50,6 +55,18 @@ public class FallingBlockBehaviour extends EntityBehaviour<FallingBlockEntity> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Caster<?> source, FallingBlockEntity entity, Spell spell) {
|
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();
|
List<Entity> attachments = ((DisguiseSpell)spell).getDisguise().getAttachments();
|
||||||
if (attachments.size() > 0) {
|
if (attachments.size() > 0) {
|
||||||
copyBaseAttributes(source.getOwner(), attachments.get(0), UP);
|
copyBaseAttributes(source.getOwner(), attachments.get(0), UP);
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -5,6 +5,7 @@
|
||||||
"refmap": "unicopia.mixin.refmap.json",
|
"refmap": "unicopia.mixin.refmap.json",
|
||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
"MixinBlockEntity",
|
||||||
"MixinBlockItem",
|
"MixinBlockItem",
|
||||||
"MixinItem",
|
"MixinItem",
|
||||||
"MixinItemEntity",
|
"MixinItemEntity",
|
||||||
|
|
Loading…
Reference in a new issue