diff --git a/src/main/java/com/simibubi/create/AllBlockEntityTypes.java b/src/main/java/com/simibubi/create/AllBlockEntityTypes.java index cedf07a6f..9cf202c81 100644 --- a/src/main/java/com/simibubi/create/AllBlockEntityTypes.java +++ b/src/main/java/com/simibubi/create/AllBlockEntityTypes.java @@ -831,8 +831,8 @@ public class AllBlockEntityTypes { .validBlocks(AllBlocks.TRAIN_DOOR, AllBlocks.FRAMED_GLASS_DOOR) .register(); - public static final BlockEntityEntry UNIVERSAL_FRAME = REGISTRATE - .blockEntity("universal_frame", CopycatBlockEntity::new) + public static final BlockEntityEntry COPYCAT = REGISTRATE + .blockEntity("copycat", CopycatBlockEntity::new) .validBlocks(AllBlocks.COPYCAT_PANEL, AllBlocks.COPYCAT_STEP) .register(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ITransformableTE.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ITransformableBlockEntity.java similarity index 74% rename from src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ITransformableTE.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ITransformableBlockEntity.java index 64d77b497..49fb7d38e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ITransformableTE.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ITransformableBlockEntity.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement; -public interface ITransformableTE { +public interface ITransformableBlockEntity { void transform(StructureTransform transform); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/StructureTransform.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/StructureTransform.java index e47c124d8..446b105dc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/StructureTransform.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/StructureTransform.java @@ -111,8 +111,8 @@ public class StructureTransform { } public void apply(BlockEntity be) { - if (be instanceof ITransformableTE) - ((ITransformableTE) be).transform(this); + if (be instanceof ITransformableBlockEntity) + ((ITransformableBlockEntity) be).transform(this); } /** diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PipeAttachmentModel.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PipeAttachmentModel.java index 27370bf8d..10f2ad635 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PipeAttachmentModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PipeAttachmentModel.java @@ -10,8 +10,8 @@ import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour.A import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour.AttachmentTypes.ComponentPartials; import com.simibubi.create.content.contraptions.fluids.pipes.FluidPipeBlock; import com.simibubi.create.content.contraptions.relays.elementary.BracketedBlockEntityBehaviour; -import com.simibubi.create.foundation.block.connected.BakedModelWrapperWithData; import com.simibubi.create.foundation.blockEntity.BlockEntityBehaviour; +import com.simibubi.create.foundation.model.BakedModelWrapperWithData; import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.client.Minecraft; @@ -34,7 +34,7 @@ public class PipeAttachmentModel extends BakedModelWrapperWithData { } @Override - protected Builder gatherModelData(Builder builder, BlockAndTintGetter world, BlockPos pos, BlockState state, + protected void gatherModelData(Builder builder, BlockAndTintGetter world, BlockPos pos, BlockState state, IModelData blockEntityData) { PipeModelData data = new PipeModelData(); FluidTransportBehaviour transport = BlockEntityBehaviour.get(world, pos, FluidTransportBehaviour.TYPE); @@ -47,7 +47,7 @@ public class PipeAttachmentModel extends BakedModelWrapperWithData { data.putBracket(bracket.getBracket()); data.setEncased(FluidPipeBlock.shouldDrawCasing(world, pos, state)); - return builder.withInitial(PIPE_PROPERTY, data); + builder.withInitial(PIPE_PROPERTY, data); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlockEntity.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlockEntity.java index 329ae5353..4f9ac3d24 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlockEntity.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.fluids.pipes; import java.util.List; import com.simibubi.create.AllBlocks; -import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableTE; +import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableBlockEntity; import com.simibubi.create.content.contraptions.components.structureMovement.StructureTransform; import com.simibubi.create.content.contraptions.fluids.FluidPropagator; import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour; @@ -17,7 +17,7 @@ import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -public class FluidPipeBlockEntity extends SmartBlockEntity implements ITransformableTE { +public class FluidPipeBlockEntity extends SmartBlockEntity implements ITransformableBlockEntity { public FluidPipeBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankModel.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankModel.java index a8d2ac913..652b4ee97 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankModel.java @@ -42,12 +42,13 @@ public class FluidTankModel extends CTModel { } @Override - protected Builder gatherModelData(Builder builder, BlockAndTintGetter world, BlockPos pos, BlockState state, + protected void gatherModelData(Builder builder, BlockAndTintGetter world, BlockPos pos, BlockState state, IModelData blockEntityData) { + super.gatherModelData(builder, world, pos, state, blockEntityData); CullData cullData = new CullData(); for (Direction d : Iterate.horizontalDirections) cullData.setCulled(d, ConnectivityHandler.isConnected(world, pos, pos.relative(d))); - return super.gatherModelData(builder, world, pos, state, blockEntityData).withInitial(CULL_PROPERTY, cullData); + builder.withInitial(CULL_PROPERTY, cullData); } @Override @@ -66,7 +67,7 @@ public class FluidTankModel extends CTModel { return quads; } - private class CullData { + private static class CullData { boolean[] culledFaces; public CullData() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltBlockEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltBlockEntity.java index 7d904909c..b6ab1e923 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltBlockEntity.java @@ -56,7 +56,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.model.data.IModelData; import net.minecraftforge.client.model.data.ModelDataMap; -import net.minecraftforge.client.model.data.ModelProperty; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fml.DistExecutor; @@ -517,11 +516,9 @@ public class BeltBlockEntity extends KineticBlockEntity { return empty; } - public static final ModelProperty CASING_PROPERTY = new ModelProperty<>(); - @Override public IModelData getModelData() { - return new ModelDataMap.Builder().withInitial(CASING_PROPERTY, casing) + return new ModelDataMap.Builder().withInitial(BeltModel.CASING_PROPERTY, casing) .build(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltModel.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltModel.java index 331b9af4c..a3d8c453d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltModel.java @@ -1,15 +1,13 @@ package com.simibubi.create.content.contraptions.relays.belt; -import static com.simibubi.create.content.contraptions.relays.belt.BeltBlockEntity.CASING_PROPERTY; - import java.util.ArrayList; import java.util.List; import java.util.Random; import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.content.contraptions.relays.belt.BeltBlockEntity.CasingType; -import com.simibubi.create.foundation.block.render.QuadHelper; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; +import com.simibubi.create.foundation.model.BakedQuadHelper; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -18,9 +16,12 @@ import net.minecraft.core.Direction; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.client.model.BakedModelWrapper; import net.minecraftforge.client.model.data.IModelData; +import net.minecraftforge.client.model.data.ModelProperty; public class BeltModel extends BakedModelWrapper { + public static final ModelProperty CASING_PROPERTY = new ModelProperty<>(); + private static final SpriteShiftEntry SPRITE_SHIFT = AllSpriteShifts.ANDESIDE_BELT_CASING; public BeltModel(BakedModel template) { @@ -44,14 +45,14 @@ public class BeltModel extends BakedModelWrapper { if (original != SPRITE_SHIFT.getOriginal()) continue; - BakedQuad newQuad = QuadHelper.clone(quad); + BakedQuad newQuad = BakedQuadHelper.clone(quad); int[] vertexData = newQuad.getVertices(); for (int vertex = 0; vertex < 4; vertex++) { - float u = QuadHelper.getU(vertexData, vertex); - float v = QuadHelper.getV(vertexData, vertex); - QuadHelper.setU(vertexData, vertex, SPRITE_SHIFT.getTargetU(u)); - QuadHelper.setV(vertexData, vertex, SPRITE_SHIFT.getTargetV(v)); + float u = BakedQuadHelper.getU(vertexData, vertex); + float v = BakedQuadHelper.getV(vertexData, vertex); + BakedQuadHelper.setU(vertexData, vertex, SPRITE_SHIFT.getTargetU(u)); + BakedQuadHelper.setV(vertexData, vertex, SPRITE_SHIFT.getTargetV(v)); } quads.set(i, newQuad); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockEntity.java index deb009d09..44a0f33fe 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockEntity.java @@ -2,7 +2,7 @@ package com.simibubi.create.content.contraptions.relays.elementary; import java.util.List; -import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableTE; +import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableBlockEntity; import com.simibubi.create.content.contraptions.components.structureMovement.StructureTransform; import com.simibubi.create.foundation.blockEntity.BlockEntityBehaviour; @@ -10,7 +10,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -public class BracketedKineticBlockEntity extends SimpleKineticBlockEntity implements ITransformableTE { +public class BracketedKineticBlockEntity extends SimpleKineticBlockEntity implements ITransformableBlockEntity { public BracketedKineticBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); diff --git a/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatBlock.java b/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatBlock.java index a53431577..866d60fb1 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatBlock.java +++ b/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatBlock.java @@ -81,7 +81,7 @@ public abstract class CopycatBlock extends Block implements IBE ufte.setItem(ItemStack.EMPTY)); + withBlockEntityDo(pLevel, pPos, ufte -> ufte.setConsumedItem(ItemStack.EMPTY)); } @Override @@ -225,7 +225,7 @@ public abstract class CopycatBlock extends Block implements IBE getBlockEntityType() { - return AllBlockEntityTypes.UNIVERSAL_FRAME.get(); + return AllBlockEntityTypes.COPYCAT.get(); } // Connected Textures diff --git a/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatBlockEntity.java b/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatBlockEntity.java index c5c99d3c9..af906c220 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatBlockEntity.java @@ -5,7 +5,7 @@ import java.util.List; import com.google.gson.JsonParser; import com.mojang.serialization.JsonOps; import com.simibubi.create.AllBlocks; -import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableTE; +import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableBlockEntity; import com.simibubi.create.content.contraptions.components.structureMovement.StructureTransform; import com.simibubi.create.content.logistics.block.redstone.RoseQuartzLampBlock; import com.simibubi.create.content.schematics.ISpecialBlockEntityItemRequirement; @@ -24,55 +24,46 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraftforge.client.model.data.IModelData; import net.minecraftforge.client.model.data.ModelDataMap; -import net.minecraftforge.client.model.data.ModelProperty; import net.minecraftforge.items.ItemHandlerHelper; -public class CopycatBlockEntity extends SmartBlockEntity implements ISpecialBlockEntityItemRequirement, ITransformableTE { +public class CopycatBlockEntity extends SmartBlockEntity implements ISpecialBlockEntityItemRequirement, ITransformableBlockEntity { - ItemStack consumedItem; - BlockState baseBlock; + private BlockState material; + private ItemStack consumedItem; public CopycatBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); - baseBlock = AllBlocks.COPYCAT_BASE.getDefaultState(); + material = AllBlocks.COPYCAT_BASE.getDefaultState(); consumedItem = ItemStack.EMPTY; } - public void setItem(ItemStack item) { - consumedItem = ItemHandlerHelper.copyStackWithSize(item, 1); - setChanged(); + public BlockState getMaterial() { + return material; } - public ItemStack getConsumedItem() { - return consumedItem; - } - - @Override - public ItemRequirement getRequiredItems(BlockState state) { - if (consumedItem.isEmpty()) - return ItemRequirement.NONE; - return new ItemRequirement(ItemUseType.CONSUME, consumedItem); + public boolean hasCustomMaterial() { + return !AllBlocks.COPYCAT_BASE.has(getMaterial()); } public void setMaterial(BlockState blockState) { BlockState wrapperState = getBlockState(); - if (!baseBlock.is(blockState.getBlock())) + if (!material.is(blockState.getBlock())) for (Direction side : Iterate.directions) { BlockPos neighbour = worldPosition.relative(side); BlockState neighbourState = level.getBlockState(neighbour); if (neighbourState != wrapperState) continue; - if (!(level.getBlockEntity(neighbour)instanceof CopycatBlockEntity ufte)) + if (!(level.getBlockEntity(neighbour) instanceof CopycatBlockEntity cbe)) continue; - BlockState otherMaterial = ufte.getMaterial(); + BlockState otherMaterial = cbe.getMaterial(); if (!otherMaterial.is(blockState.getBlock())) continue; blockState = otherMaterial; break; } - baseBlock = blockState; + material = blockState; if (!level.isClientSide()) { notifyUpdate(); return; @@ -80,50 +71,32 @@ public class CopycatBlockEntity extends SmartBlockEntity implements ISpecialBloc redraw(); } - public boolean hasCustomMaterial() { - return !AllBlocks.COPYCAT_BASE.has(getMaterial()); - } - - public BlockState getMaterial() { - return baseBlock; - } - public boolean cycleMaterial() { - if (baseBlock.hasProperty(BlockStateProperties.FACING)) - setMaterial(baseBlock.cycle(BlockStateProperties.FACING)); - else if (baseBlock.hasProperty(BlockStateProperties.HORIZONTAL_FACING)) - setMaterial(baseBlock.cycle(BlockStateProperties.HORIZONTAL_FACING)); - else if (baseBlock.hasProperty(BlockStateProperties.AXIS)) - setMaterial(baseBlock.cycle(BlockStateProperties.AXIS)); - else if (baseBlock.hasProperty(BlockStateProperties.HORIZONTAL_AXIS)) - setMaterial(baseBlock.cycle(BlockStateProperties.HORIZONTAL_AXIS)); - else if (baseBlock.hasProperty(BlockStateProperties.LIT)) - setMaterial(baseBlock.cycle(BlockStateProperties.LIT)); - else if (baseBlock.hasProperty(RoseQuartzLampBlock.POWERING)) - setMaterial(baseBlock.cycle(RoseQuartzLampBlock.POWERING)); + if (material.hasProperty(BlockStateProperties.FACING)) + setMaterial(material.cycle(BlockStateProperties.FACING)); + else if (material.hasProperty(BlockStateProperties.HORIZONTAL_FACING)) + setMaterial(material.cycle(BlockStateProperties.HORIZONTAL_FACING)); + else if (material.hasProperty(BlockStateProperties.AXIS)) + setMaterial(material.cycle(BlockStateProperties.AXIS)); + else if (material.hasProperty(BlockStateProperties.HORIZONTAL_AXIS)) + setMaterial(material.cycle(BlockStateProperties.HORIZONTAL_AXIS)); + else if (material.hasProperty(BlockStateProperties.LIT)) + setMaterial(material.cycle(BlockStateProperties.LIT)); + else if (material.hasProperty(RoseQuartzLampBlock.POWERING)) + setMaterial(material.cycle(RoseQuartzLampBlock.POWERING)); else return false; return true; } - @Override - protected void read(CompoundTag tag, boolean clientPacket) { - super.read(tag, clientPacket); + public ItemStack getConsumedItem() { + return consumedItem; + } - consumedItem = ItemStack.of(tag.getCompound("Item")); - - BlockState prevMaterial = baseBlock; - if (!tag.contains("Material")) - return; - - JsonOps ops = JsonOps.INSTANCE; - BlockState.CODEC.decode(ops, JsonParser.parseString(tag.getString("Material"))) - .result() - .ifPresent(p -> baseBlock = p.getFirst()); - - if (clientPacket && prevMaterial != baseBlock) - redraw(); + public void setConsumedItem(ItemStack stack) { + consumedItem = ItemHandlerHelper.copyStackWithSize(stack, 1); + setChanged(); } private void redraw() { @@ -137,6 +110,41 @@ public class CopycatBlockEntity extends SmartBlockEntity implements ISpecialBloc } } + @Override + public void addBehaviours(List behaviours) {} + + @Override + public ItemRequirement getRequiredItems(BlockState state) { + if (consumedItem.isEmpty()) + return ItemRequirement.NONE; + return new ItemRequirement(ItemUseType.CONSUME, consumedItem); + } + + @Override + public void transform(StructureTransform transform) { + material = transform.apply(material); + notifyUpdate(); + } + + @Override + protected void read(CompoundTag tag, boolean clientPacket) { + super.read(tag, clientPacket); + + consumedItem = ItemStack.of(tag.getCompound("Item")); + + BlockState prevMaterial = material; + if (!tag.contains("Material")) + return; + + JsonOps ops = JsonOps.INSTANCE; + BlockState.CODEC.decode(ops, JsonParser.parseString(tag.getString("Material"))) + .result() + .ifPresent(p -> material = p.getFirst()); + + if (clientPacket && prevMaterial != material) + redraw(); + } + @Override protected void write(CompoundTag tag, boolean clientPacket) { super.write(tag, clientPacket); @@ -144,27 +152,16 @@ public class CopycatBlockEntity extends SmartBlockEntity implements ISpecialBloc tag.put("Item", consumedItem.serializeNBT()); JsonOps ops = JsonOps.INSTANCE; - BlockState.CODEC.encode(baseBlock, ops, ops.empty()) + BlockState.CODEC.encode(material, ops, ops.empty()) .result() .map(je -> je.toString()) .ifPresent(s -> tag.putString("Material", s)); } - public static final ModelProperty MATERIAL_PROPERTY = new ModelProperty<>(); - @Override public IModelData getModelData() { - return new ModelDataMap.Builder().withInitial(MATERIAL_PROPERTY, baseBlock) + return new ModelDataMap.Builder().withInitial(CopycatModel.MATERIAL_PROPERTY, material) .build(); } - @Override - public void addBehaviours(List behaviours) {} - - @Override - public void transform(StructureTransform transform) { - baseBlock = transform.apply(baseBlock); - notifyUpdate(); - } - } diff --git a/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatModel.java b/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatModel.java index 4cac90cf6..88c7704d8 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatModel.java +++ b/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatModel.java @@ -1,20 +1,13 @@ package com.simibubi.create.content.curiosities.frames; -import static com.simibubi.create.content.curiosities.frames.CopycatBlockEntity.MATERIAL_PROPERTY; -import static com.simibubi.create.foundation.block.render.SpriteShiftEntry.getUnInterpolatedU; -import static com.simibubi.create.foundation.block.render.SpriteShiftEntry.getUnInterpolatedV; - -import java.util.Arrays; import java.util.List; import java.util.Random; import javax.annotation.Nullable; import com.simibubi.create.AllBlocks; -import com.simibubi.create.foundation.block.connected.BakedModelWrapperWithData; -import com.simibubi.create.foundation.block.render.QuadHelper; +import com.simibubi.create.foundation.model.BakedModelWrapperWithData; import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ItemBlockRenderTypes; @@ -28,177 +21,94 @@ import net.minecraft.core.Direction; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.Vec3; import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.client.model.data.EmptyModelData; import net.minecraftforge.client.model.data.IModelData; -import net.minecraftforge.client.model.data.ModelDataMap; import net.minecraftforge.client.model.data.ModelDataMap.Builder; import net.minecraftforge.client.model.data.ModelProperty; public abstract class CopycatModel extends BakedModelWrapperWithData { - private static final ModelProperty WRAPPED_DATA_PROPERTY = new ModelProperty<>(); + public static final ModelProperty MATERIAL_PROPERTY = new ModelProperty<>(); private static final ModelProperty OCCLUSION_PROPERTY = new ModelProperty<>(); + private static final ModelProperty WRAPPED_DATA_PROPERTY = new ModelProperty<>(); public CopycatModel(BakedModel originalModel) { super(originalModel); } @Override - protected Builder gatherModelData(Builder builder, BlockAndTintGetter world, BlockPos pos, BlockState state, + protected void gatherModelData(Builder builder, BlockAndTintGetter world, BlockPos pos, BlockState state, IModelData blockEntityData) { - BlockState wrappedState = getMaterial(world, pos, state); + BlockState material = getMaterial(blockEntityData); + if (material == null) + return; - if (wrappedState == null) - return builder; - if (blockEntityData instanceof ModelDataMap mdm && mdm.hasProperty(MATERIAL_PROPERTY)) - builder.withInitial(MATERIAL_PROPERTY, mdm.getData(MATERIAL_PROPERTY)); + builder.withInitial(MATERIAL_PROPERTY, material); OcclusionData occlusionData = new OcclusionData(); - if (state.getBlock()instanceof CopycatBlock ufb) { + if (state.getBlock() instanceof CopycatBlock copycatBlock) { MutableBlockPos mutablePos = new MutableBlockPos(); for (Direction face : Iterate.directions) - if (ufb.canFaceBeOccluded(state, face)) - if (!Block.shouldRenderFace(wrappedState, world, pos, face, mutablePos.setWithOffset(pos, face))) + if (copycatBlock.canFaceBeOccluded(state, face)) + if (!Block.shouldRenderFace(material, world, pos, face, mutablePos.setWithOffset(pos, face))) occlusionData.occlude(face); builder.withInitial(OCCLUSION_PROPERTY, occlusionData); } - IModelData modelData = getModelOf(wrappedState).getModelData(world, pos, wrappedState, EmptyModelData.INSTANCE); - return builder.withInitial(WRAPPED_DATA_PROPERTY, modelData); + IModelData wrappedData = getModelOf(material).getModelData(world, pos, material, EmptyModelData.INSTANCE); + builder.withInitial(WRAPPED_DATA_PROPERTY, wrappedData); } @Override - public List getQuads(BlockState state, Direction side, Random rand, IModelData extraData) { - List quads = super.getQuads(state, side, rand, extraData); - - BlockState material = getMaterial(extraData); - IModelData wrappedData = extraData.getData(WRAPPED_DATA_PROPERTY); + public List getQuads(BlockState state, Direction side, Random rand, IModelData data) { + BlockState material = getMaterial(data); if (material == null) - return quads; - + return super.getQuads(state, side, rand, data); + + OcclusionData occlusionData = data.getData(OCCLUSION_PROPERTY); + if (occlusionData != null && occlusionData.isOccluded(side)) + return super.getQuads(state, side, rand, data); + RenderType renderType = MinecraftForgeClient.getRenderType(); if (renderType != null && !ItemBlockRenderTypes.canRenderInLayer(material, renderType)) - return quads; + return super.getQuads(state, side, rand, data); + + IModelData wrappedData = data.getData(WRAPPED_DATA_PROPERTY); if (wrappedData == null) wrappedData = EmptyModelData.INSTANCE; - OcclusionData occlusionData = extraData.getData(OCCLUSION_PROPERTY); - if (occlusionData != null && occlusionData.isOccluded(side)) - return quads; - return getCroppedQuads(state, side, rand, material, wrappedData); } protected abstract List getCroppedQuads(BlockState state, Direction side, Random rand, BlockState material, IModelData wrappedData); - public static boolean cropAndMove(BakedQuad quad, AABB crop, Vec3 move) { - int[] vertexData = quad.getVertices(); - - Vec3 xyz0 = QuadHelper.getXYZ(vertexData, 0); - Vec3 xyz1 = QuadHelper.getXYZ(vertexData, 1); - Vec3 xyz2 = QuadHelper.getXYZ(vertexData, 2); - Vec3 xyz3 = QuadHelper.getXYZ(vertexData, 3); - - Vec3 uAxis = xyz3.add(xyz2) - .scale(.5); - Vec3 vAxis = xyz1.add(xyz2) - .scale(.5); - Vec3 center = xyz3.add(xyz2) - .add(xyz0) - .add(xyz1) - .scale(.25); - - float u0 = QuadHelper.getU(vertexData, 0); - float u3 = QuadHelper.getU(vertexData, 3); - float v0 = QuadHelper.getV(vertexData, 0); - float v1 = QuadHelper.getV(vertexData, 1); - - TextureAtlasSprite sprite = quad.getSprite(); - - float uScale = (float) Math - .round((getUnInterpolatedU(sprite, u3) - getUnInterpolatedU(sprite, u0)) / xyz3.distanceTo(xyz0)); - float vScale = (float) Math - .round((getUnInterpolatedV(sprite, v1) - getUnInterpolatedV(sprite, v0)) / xyz1.distanceTo(xyz0)); - - if (uScale == 0) { - float v3 = QuadHelper.getV(vertexData, 3); - float u1 = QuadHelper.getU(vertexData, 1); - uAxis = xyz1.add(xyz2) - .scale(.5); - vAxis = xyz3.add(xyz2) - .scale(.5); - uScale = (float) Math - .round((getUnInterpolatedU(sprite, u1) - getUnInterpolatedU(sprite, u0)) / xyz1.distanceTo(xyz0)); - vScale = (float) Math - .round((getUnInterpolatedV(sprite, v3) - getUnInterpolatedV(sprite, v0)) / xyz3.distanceTo(xyz0)); - - } - - uAxis = uAxis.subtract(center) - .normalize(); - vAxis = vAxis.subtract(center) - .normalize(); - - Vec3 min = new Vec3(crop.minX, crop.minY, crop.minZ); - Vec3 max = new Vec3(crop.maxX, crop.maxY, crop.maxZ); - - for (int vertex = 0; vertex < 4; vertex++) { - Vec3 xyz = QuadHelper.getXYZ(vertexData, vertex); - Vec3 newXyz = VecHelper.componentMin(max, VecHelper.componentMax(xyz, min)); - Vec3 diff = newXyz.subtract(xyz); - - if (diff.lengthSqr() > 0) { - float u = QuadHelper.getU(vertexData, vertex); - float v = QuadHelper.getV(vertexData, vertex); - float uDiff = (float) uAxis.dot(diff) * uScale; - float vDiff = (float) vAxis.dot(diff) * vScale; - QuadHelper.setU(vertexData, vertex, sprite.getU(getUnInterpolatedU(sprite, u) + uDiff)); - QuadHelper.setV(vertexData, vertex, sprite.getV(getUnInterpolatedV(sprite, v) + vDiff)); - } - - QuadHelper.setXYZ(vertexData, vertex, newXyz.add(move)); - } - - return true; - } - @Override public TextureAtlasSprite getParticleIcon(IModelData data) { BlockState material = getMaterial(data); - IModelData wrappedData = data.getData(WRAPPED_DATA_PROPERTY); + if (material == null) + return super.getParticleIcon(data); + + IModelData wrappedData = data.getData(WRAPPED_DATA_PROPERTY); if (wrappedData == null) wrappedData = EmptyModelData.INSTANCE; - if (material != null) - return getModelOf(material).getParticleIcon(wrappedData); - return super.getParticleIcon(data); + return getModelOf(material).getParticleIcon(wrappedData); } @Nullable - public BlockState getMaterial(IModelData extraData) { - BlockState material = extraData.getData(MATERIAL_PROPERTY); + public static BlockState getMaterial(IModelData data) { + BlockState material = data.getData(MATERIAL_PROPERTY); return material == null ? AllBlocks.COPYCAT_BASE.getDefaultState() : material; } - @Nullable - public BlockState getMaterial(BlockAndTintGetter world, BlockPos pos, BlockState state) { - if (!(state.getBlock()instanceof CopycatBlock ufb)) - return null; - return ufb.getBlockEntityOptional(world, pos) - .map(CopycatBlockEntity::getMaterial) - .orElse(null); - } - - public BakedModel getModelOf(BlockState wrappedState) { + public static BakedModel getModelOf(BlockState state) { return Minecraft.getInstance() .getBlockRenderer() - .getBlockModel(wrappedState); + .getBlockModel(state); } private static class OcclusionData { @@ -206,7 +116,6 @@ public abstract class CopycatModel extends BakedModelWrapperWithData { public OcclusionData() { occluded = new boolean[6]; - Arrays.fill(occluded, false); } public void occlude(Direction face) { diff --git a/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatPanelModel.java b/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatPanelModel.java index efaac4c3d..51683f5a8 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatPanelModel.java +++ b/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatPanelModel.java @@ -4,7 +4,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; -import com.simibubi.create.foundation.block.render.QuadHelper; +import com.simibubi.create.foundation.model.BakedModelHelper; +import com.simibubi.create.foundation.model.BakedQuadHelper; import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.client.renderer.block.model.BakedQuad; @@ -18,6 +19,8 @@ import net.minecraftforge.client.model.data.IModelData; public class CopycatPanelModel extends CopycatModel { + protected static final AABB CUBE_AABB = new AABB(BlockPos.ZERO); + public CopycatPanelModel(BakedModel originalModel) { super(originalModel); } @@ -28,17 +31,22 @@ public class CopycatPanelModel extends CopycatModel { Direction facing = state.getOptionalValue(CopycatPanelBlock.FACING) .orElse(Direction.UP); - Vec3 normal = Vec3.atLowerCornerOf(facing.getNormal()); - AABB cube = new AABB(BlockPos.ZERO); - BakedModel model = getModelOf(material); List templateQuads = model.getQuads(material, side, rand, wrappedData); int size = templateQuads.size(); List quads = new ArrayList<>(); + Vec3 normal = Vec3.atLowerCornerOf(facing.getNormal()); + Vec3 normalScaled14 = normal.scale(14 / 16f); + // 2 Pieces for (boolean front : Iterate.trueAndFalse) { + Vec3 normalScaledN13 = normal.scale(front ? 0 : -13 / 16f); + float contract = 16 - (front ? 1 : 2); + AABB bb = CUBE_AABB.contract(normal.x * contract / 16, normal.y * contract / 16, normal.z * contract / 16); + if (!front) + bb = bb.move(normalScaled14); for (int i = 0; i < size; i++) { BakedQuad quad = templateQuads.get(i); @@ -49,15 +57,9 @@ public class CopycatPanelModel extends CopycatModel { if (!front && direction == facing.getOpposite()) continue; - float contract = 16 - (front ? 1 : 2); - AABB bb = cube.contract(normal.x * contract / 16, normal.y * contract / 16, normal.z * contract / 16); - - if (!front) - bb = bb.move(normal.scale(14 / 16f)); - - BakedQuad newQuad = QuadHelper.clone(quad); - if (cropAndMove(newQuad, bb, normal.scale(front ? 0 : -13 / 16f))); - quads.add(newQuad); + BakedQuad newQuad = BakedQuadHelper.clone(quad); + BakedModelHelper.cropAndMove(newQuad, bb, normalScaledN13); + quads.add(newQuad); } } diff --git a/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatStepBlock.java b/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatStepBlock.java index 10ac1be0e..a56eceff1 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatStepBlock.java +++ b/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatStepBlock.java @@ -42,8 +42,8 @@ import net.minecraftforge.common.ForgeMod; public class CopycatStepBlock extends WaterloggedCopycatBlock { - public static EnumProperty HALF = BlockStateProperties.HALF; - public static DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; + public static final EnumProperty HALF = BlockStateProperties.HALF; + public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; private static final int placementHelperId = PlacementHelpers.register(new PlacementHelper()); diff --git a/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatStepModel.java b/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatStepModel.java index a13ca5d38..7abc69c96 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatStepModel.java +++ b/src/main/java/com/simibubi/create/content/curiosities/frames/CopycatStepModel.java @@ -4,7 +4,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; -import com.simibubi.create.foundation.block.render.QuadHelper; +import com.simibubi.create.foundation.model.BakedModelHelper; +import com.simibubi.create.foundation.model.BakedQuadHelper; import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.client.renderer.block.model.BakedQuad; @@ -19,6 +20,11 @@ import net.minecraftforge.client.model.data.IModelData; public class CopycatStepModel extends CopycatModel { + protected static final Vec3 VEC_Y_3 = new Vec3(0, .75, 0); + protected static final Vec3 VEC_Y_2 = new Vec3(0, .5, 0); + protected static final Vec3 VEC_Y_N2 = new Vec3(0, -.5, 0); + protected static final AABB CUBE_AABB = new AABB(BlockPos.ZERO); + public CopycatStepModel(BakedModel originalModel) { super(originalModel); } @@ -31,21 +37,33 @@ public class CopycatStepModel extends CopycatModel { boolean upperHalf = state.getOptionalValue(CopycatStepBlock.HALF) .orElse(Half.BOTTOM) == Half.TOP; - Vec3 zero = Vec3.ZERO; - Vec3 up = new Vec3(0, 1, 0); - Vec3 normal = Vec3.atLowerCornerOf(facing.getNormal()); - BakedModel model = getModelOf(material); List templateQuads = model.getQuads(material, side, rand, wrappedData); int size = templateQuads.size(); - AABB cube = new AABB(BlockPos.ZERO); List quads = new ArrayList<>(); + Vec3 normal = Vec3.atLowerCornerOf(facing.getNormal()); + Vec3 normalScaled2 = normal.scale(.5); + Vec3 normalScaledN3 = normal.scale(-.75); + AABB bb = CUBE_AABB.contract(-normal.x * .75, .75, -normal.z * .75); + // 4 Pieces for (boolean top : Iterate.trueAndFalse) { for (boolean front : Iterate.trueAndFalse) { + AABB bb1 = bb; + if (front) + bb1 = bb1.move(normalScaledN3); + if (top) + bb1 = bb1.move(VEC_Y_3); + + Vec3 offset = Vec3.ZERO; + if (front) + offset = offset.add(normalScaled2); + if (top != upperHalf) + offset = offset.add(upperHalf ? VEC_Y_2 : VEC_Y_N2); + for (int i = 0; i < size; i++) { BakedQuad quad = templateQuads.get(i); Direction direction = quad.getDirection(); @@ -59,23 +77,9 @@ public class CopycatStepModel extends CopycatModel { if (top && direction == Direction.DOWN) continue; - AABB bb = cube.contract(-normal.x * .75, .75, -normal.z * .75); - - if (front) - bb = bb.move(normal.scale(-.75)); - if (top) - bb = bb.move(up.scale(.75)); - - Vec3 offset = zero; - - if (front) - offset = offset.add(normal.scale(.5)); - if (top != upperHalf) - offset = offset.add(up.scale(upperHalf ? .5 : -.5)); - - BakedQuad newQuad = QuadHelper.clone(quad); - if (cropAndMove(newQuad, bb, offset)) - quads.add(newQuad); + BakedQuad newQuad = BakedQuadHelper.clone(quad); + BakedModelHelper.cropAndMove(newQuad, bb1, offset); + quads.add(newQuad); } } diff --git a/src/main/java/com/simibubi/create/content/curiosities/girder/ConnectedGirderModel.java b/src/main/java/com/simibubi/create/content/curiosities/girder/ConnectedGirderModel.java index b501aae75..809af8c8a 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/girder/ConnectedGirderModel.java +++ b/src/main/java/com/simibubi/create/content/curiosities/girder/ConnectedGirderModel.java @@ -21,20 +21,20 @@ import net.minecraftforge.client.model.data.ModelProperty; public class ConnectedGirderModel extends CTModel { - protected static ModelProperty CONNECTION_PROPERTY = new ModelProperty<>(); + protected static final ModelProperty CONNECTION_PROPERTY = new ModelProperty<>(); public ConnectedGirderModel(BakedModel originalModel) { super(originalModel, new GirderCTBehaviour()); } @Override - protected Builder gatherModelData(Builder builder, BlockAndTintGetter world, BlockPos pos, BlockState state, + protected void gatherModelData(Builder builder, BlockAndTintGetter world, BlockPos pos, BlockState state, IModelData blockEntityData) { + super.gatherModelData(builder, world, pos, state, blockEntityData); ConnectionData connectionData = new ConnectionData(); for (Direction d : Iterate.horizontalDirections) connectionData.setConnected(d, GirderBlock.isConnected(world, pos, state, d)); - return super.gatherModelData(builder, world, pos, state, blockEntityData).withInitial(CONNECTION_PROPERTY, - connectionData); + builder.withInitial(CONNECTION_PROPERTY, connectionData); } @Override @@ -52,7 +52,7 @@ public class ConnectedGirderModel extends CTModel { return quads; } - private class ConnectionData { + private static class ConnectionData { boolean[] connectedFaces; public ConnectionData() { diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmBlockEntity.java index ca2f76ffc..daacdb7bb 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmBlockEntity.java @@ -7,7 +7,7 @@ import javax.annotation.Nullable; import com.simibubi.create.Create; import com.simibubi.create.content.contraptions.base.KineticBlockEntity; -import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableTE; +import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableBlockEntity; import com.simibubi.create.content.contraptions.components.structureMovement.StructureTransform; import com.simibubi.create.content.logistics.block.mechanicalArm.AllArmInteractionPointTypes.JukeboxPoint; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmInteractionPoint.Mode; @@ -45,7 +45,7 @@ import net.minecraft.world.level.chunk.ChunkSource; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; -public class ArmBlockEntity extends KineticBlockEntity implements ITransformableTE { +public class ArmBlockEntity extends KineticBlockEntity implements ITransformableBlockEntity { // Server List inputs; diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/observer/TrackObserverBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/observer/TrackObserverBlockEntity.java index ef431470a..814eb6add 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/observer/TrackObserverBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/observer/TrackObserverBlockEntity.java @@ -6,7 +6,7 @@ import javax.annotation.Nullable; import com.jozufozu.flywheel.util.transform.TransformStack; import com.mojang.blaze3d.vertex.PoseStack; -import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableTE; +import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableBlockEntity; import com.simibubi.create.content.contraptions.components.structureMovement.StructureTransform; import com.simibubi.create.content.logistics.block.display.DisplayLinkBlock; import com.simibubi.create.content.logistics.trains.management.edgePoint.EdgePointType; @@ -23,7 +23,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; -public class TrackObserverBlockEntity extends SmartBlockEntity implements ITransformableTE { +public class TrackObserverBlockEntity extends SmartBlockEntity implements ITransformableBlockEntity { public TrackTargetingBehaviour edgePoint; diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/signal/SignalBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/signal/SignalBlockEntity.java index 2299a74bc..6c8e31210 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/signal/SignalBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/signal/SignalBlockEntity.java @@ -4,7 +4,7 @@ import java.util.List; import javax.annotation.Nullable; -import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableTE; +import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableBlockEntity; import com.simibubi.create.content.contraptions.components.structureMovement.StructureTransform; import com.simibubi.create.content.logistics.trains.management.edgePoint.EdgePointType; import com.simibubi.create.content.logistics.trains.management.edgePoint.TrackTargetingBehaviour; @@ -19,7 +19,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; -public class SignalBlockEntity extends SmartBlockEntity implements ITransformableTE { +public class SignalBlockEntity extends SmartBlockEntity implements ITransformableBlockEntity { public static enum OverlayState { RENDER, SKIP, DUAL diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationBlockEntity.java index 5f48e73f9..54457b894 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationBlockEntity.java @@ -17,7 +17,7 @@ import com.simibubi.create.AllItems; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.Create; import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; -import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableTE; +import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableBlockEntity; import com.simibubi.create.content.contraptions.components.structureMovement.StructureTransform; import com.simibubi.create.content.logistics.block.depot.DepotBehaviour; import com.simibubi.create.content.logistics.block.display.DisplayLinkBlock; @@ -77,7 +77,7 @@ import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.network.PacketDistributor; -public class StationBlockEntity extends SmartBlockEntity implements ITransformableTE { +public class StationBlockEntity extends SmartBlockEntity implements ITransformableBlockEntity { public TrackTargetingBehaviour edgePoint; public LerpedFloat flag; diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackBlockEntity.java index 127db38f5..23de34c93 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackBlockEntity.java @@ -9,7 +9,7 @@ import java.util.Set; import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import com.simibubi.create.AllBlocks; -import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableTE; +import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableBlockEntity; import com.simibubi.create.content.contraptions.components.structureMovement.StructureTransform; import com.simibubi.create.content.logistics.trains.BezierConnection; import com.simibubi.create.content.logistics.trains.ITrackBlock; @@ -46,7 +46,7 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.DistExecutor; -public class TrackBlockEntity extends SmartBlockEntity implements ITransformableTE, IMergeableBE { +public class TrackBlockEntity extends SmartBlockEntity implements ITransformableBlockEntity, IMergeableBE { Map connections; boolean cancelDrops; diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/CTModel.java b/src/main/java/com/simibubi/create/foundation/block/connected/CTModel.java index b21518836..5ebc760b0 100644 --- a/src/main/java/com/simibubi/create/foundation/block/connected/CTModel.java +++ b/src/main/java/com/simibubi/create/foundation/block/connected/CTModel.java @@ -7,7 +7,8 @@ import java.util.Random; import com.simibubi.create.content.curiosities.frames.CopycatBlock; import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour.CTContext; -import com.simibubi.create.foundation.block.render.QuadHelper; +import com.simibubi.create.foundation.model.BakedModelWrapperWithData; +import com.simibubi.create.foundation.model.BakedQuadHelper; import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.client.renderer.block.model.BakedQuad; @@ -34,9 +35,9 @@ public class CTModel extends BakedModelWrapperWithData { } @Override - protected Builder gatherModelData(Builder builder, BlockAndTintGetter world, BlockPos pos, BlockState state, + protected void gatherModelData(Builder builder, BlockAndTintGetter world, BlockPos pos, BlockState state, IModelData blockEntityData) { - return builder.withInitial(CT_PROPERTY, createCTData(world, pos, state)); + builder.withInitial(CT_PROPERTY, createCTData(world, pos, state)); } protected CTData createCTData(BlockAndTintGetter world, BlockPos pos, BlockState state) { @@ -80,14 +81,14 @@ public class CTModel extends BakedModelWrapperWithData { if (quad.getSprite() != spriteShift.getOriginal()) continue; - BakedQuad newQuad = QuadHelper.clone(quad); + BakedQuad newQuad = BakedQuadHelper.clone(quad); int[] vertexData = newQuad.getVertices(); for (int vertex = 0; vertex < 4; vertex++) { - float u = QuadHelper.getU(vertexData, vertex); - float v = QuadHelper.getV(vertexData, vertex); - QuadHelper.setU(vertexData, vertex, spriteShift.getTargetU(u, index)); - QuadHelper.setV(vertexData, vertex, spriteShift.getTargetV(v, index)); + float u = BakedQuadHelper.getU(vertexData, vertex); + float v = BakedQuadHelper.getV(vertexData, vertex); + BakedQuadHelper.setU(vertexData, vertex, spriteShift.getTargetU(u, index)); + BakedQuadHelper.setV(vertexData, vertex, spriteShift.getTargetV(v, index)); } quads.set(i, newQuad); diff --git a/src/main/java/com/simibubi/create/foundation/model/BakedModelHelper.java b/src/main/java/com/simibubi/create/foundation/model/BakedModelHelper.java new file mode 100644 index 000000000..16f4915c2 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/model/BakedModelHelper.java @@ -0,0 +1,82 @@ +package com.simibubi.create.foundation.model; + +import static com.simibubi.create.foundation.block.render.SpriteShiftEntry.getUnInterpolatedU; +import static com.simibubi.create.foundation.block.render.SpriteShiftEntry.getUnInterpolatedV; + +import com.simibubi.create.foundation.utility.VecHelper; + +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; + +public class BakedModelHelper { + public static void cropAndMove(BakedQuad quad, AABB crop, Vec3 move) { + int[] vertexData = quad.getVertices(); + + Vec3 xyz0 = BakedQuadHelper.getXYZ(vertexData, 0); + Vec3 xyz1 = BakedQuadHelper.getXYZ(vertexData, 1); + Vec3 xyz2 = BakedQuadHelper.getXYZ(vertexData, 2); + Vec3 xyz3 = BakedQuadHelper.getXYZ(vertexData, 3); + + Vec3 uAxis = xyz3.add(xyz2) + .scale(.5); + Vec3 vAxis = xyz1.add(xyz2) + .scale(.5); + Vec3 center = xyz3.add(xyz2) + .add(xyz0) + .add(xyz1) + .scale(.25); + + float u0 = BakedQuadHelper.getU(vertexData, 0); + float u3 = BakedQuadHelper.getU(vertexData, 3); + float v0 = BakedQuadHelper.getV(vertexData, 0); + float v1 = BakedQuadHelper.getV(vertexData, 1); + + TextureAtlasSprite sprite = quad.getSprite(); + + float uScale = (float) Math + .round((getUnInterpolatedU(sprite, u3) - getUnInterpolatedU(sprite, u0)) / xyz3.distanceTo(xyz0)); + float vScale = (float) Math + .round((getUnInterpolatedV(sprite, v1) - getUnInterpolatedV(sprite, v0)) / xyz1.distanceTo(xyz0)); + + if (uScale == 0) { + float v3 = BakedQuadHelper.getV(vertexData, 3); + float u1 = BakedQuadHelper.getU(vertexData, 1); + uAxis = xyz1.add(xyz2) + .scale(.5); + vAxis = xyz3.add(xyz2) + .scale(.5); + uScale = (float) Math + .round((getUnInterpolatedU(sprite, u1) - getUnInterpolatedU(sprite, u0)) / xyz1.distanceTo(xyz0)); + vScale = (float) Math + .round((getUnInterpolatedV(sprite, v3) - getUnInterpolatedV(sprite, v0)) / xyz3.distanceTo(xyz0)); + + } + + uAxis = uAxis.subtract(center) + .normalize(); + vAxis = vAxis.subtract(center) + .normalize(); + + Vec3 min = new Vec3(crop.minX, crop.minY, crop.minZ); + Vec3 max = new Vec3(crop.maxX, crop.maxY, crop.maxZ); + + for (int vertex = 0; vertex < 4; vertex++) { + Vec3 xyz = BakedQuadHelper.getXYZ(vertexData, vertex); + Vec3 newXyz = VecHelper.componentMin(max, VecHelper.componentMax(xyz, min)); + Vec3 diff = newXyz.subtract(xyz); + + if (diff.lengthSqr() > 0) { + float u = BakedQuadHelper.getU(vertexData, vertex); + float v = BakedQuadHelper.getV(vertexData, vertex); + float uDiff = (float) uAxis.dot(diff) * uScale; + float vDiff = (float) vAxis.dot(diff) * vScale; + BakedQuadHelper.setU(vertexData, vertex, sprite.getU(getUnInterpolatedU(sprite, u) + uDiff)); + BakedQuadHelper.setV(vertexData, vertex, sprite.getV(getUnInterpolatedV(sprite, v) + vDiff)); + } + + BakedQuadHelper.setXYZ(vertexData, vertex, newXyz.add(move)); + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/BakedModelWrapperWithData.java b/src/main/java/com/simibubi/create/foundation/model/BakedModelWrapperWithData.java similarity index 80% rename from src/main/java/com/simibubi/create/foundation/block/connected/BakedModelWrapperWithData.java rename to src/main/java/com/simibubi/create/foundation/model/BakedModelWrapperWithData.java index b46e74d8c..25e73476f 100644 --- a/src/main/java/com/simibubi/create/foundation/block/connected/BakedModelWrapperWithData.java +++ b/src/main/java/com/simibubi/create/foundation/model/BakedModelWrapperWithData.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.block.connected; +package com.simibubi.create.foundation.model; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.BlockPos; @@ -21,10 +21,11 @@ public abstract class BakedModelWrapperWithData extends BakedModelWrapper