From d1ff9f4e30f4055393ed49724625a30645e9c718 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Wed, 8 Apr 2020 20:31:06 +0200 Subject: [PATCH] Broken UVs - Fixed UV shifts not working consistently with high-res resource packs - Fixed window panes not connecting their textures with windowlogged blocks - Fixed buttons and pressure plates not resetting after being moved - Fixed missing tooltips on custom swords - Redstone links now move when the block they are attached to is moved --- .../foundation/block/connected/CTModel.java | 12 ++---- .../block/connected/CTSpriteShiftEntry.java | 14 +++--- .../create/foundation/item/TooltipHelper.java | 12 +++--- .../foundation/utility/SuperByteBuffer.java | 43 +++++++++++++------ .../contraptions/BlockMovementTraits.java | 5 +++ .../components/contraptions/Contraption.java | 10 +++++ .../MechanicalCrafterTileEntityRenderer.java | 5 +-- .../relays/belt/BeltTileEntityRenderer.java | 5 +-- .../partialWindows/WindowInABlockModel.java | 14 ++++-- .../inventories/FlexcrateTileEntity.java | 7 ++- .../modules/palettes/CTGlassPaneBlock.java | 13 +++++- 11 files changed, 96 insertions(+), 44 deletions(-) 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 426212ac4..075303e0a 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 @@ -9,6 +9,7 @@ import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour. import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.block.PaneBlock; import net.minecraft.client.renderer.model.BakedQuad; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.vertex.VertexFormat; @@ -55,7 +56,7 @@ public class CTModel extends BakedModelWrapper { CTData data = new CTData(); for (Direction face : Direction.values()) { - if (!Block.shouldSideBeRendered(state, world, pos, face)) + if (!Block.shouldSideBeRendered(state, world, pos, face) && !(state.getBlock() instanceof PaneBlock)) continue; CTSpriteShiftEntry spriteShift = behaviour.get(state, face); if (spriteShift == null) @@ -85,9 +86,6 @@ public class CTModel extends BakedModelWrapper { if (index == -1) continue; - float uShift = spriteShift.getUShift(index); - float vShift = spriteShift.getVShift(index); - BakedQuad newQuad = new BakedQuad(Arrays.copyOf(quad.getVertexData(), quad.getVertexData().length), quad.getTintIndex(), quad.getFace(), quad.getSprite(), quad.shouldApplyDiffuseLighting(), quad.getFormat()); @@ -100,10 +98,8 @@ public class CTModel extends BakedModelWrapper { int vIndex = vertex + uvOffset + 1; float u = Float.intBitsToFloat(vertexData[uIndex]); float v = Float.intBitsToFloat(vertexData[vIndex]); - u += uShift; - v += vShift; - vertexData[uIndex] = Float.floatToIntBits(u); - vertexData[vIndex] = Float.floatToIntBits(v); + vertexData[uIndex] = Float.floatToRawIntBits(spriteShift.getTargetU(u, index)); + vertexData[vIndex] = Float.floatToRawIntBits(spriteShift.getTargetV(v, index)); } quads.set(i, newQuad); } diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/CTSpriteShiftEntry.java b/src/main/java/com/simibubi/create/foundation/block/connected/CTSpriteShiftEntry.java index b9a564137..7401bb472 100644 --- a/src/main/java/com/simibubi/create/foundation/block/connected/CTSpriteShiftEntry.java +++ b/src/main/java/com/simibubi/create/foundation/block/connected/CTSpriteShiftEntry.java @@ -11,14 +11,16 @@ public abstract class CTSpriteShiftEntry extends SpriteShiftEntry { this.textureSheetSize = sheetSize; } - public float getUShift(int index) { - return getTarget().getInterpolatedU((index % textureSheetSize) * (16 / textureSheetSize)) - - getOriginal().getMinU(); + public float getTargetU(float localU, int index) { + float uOffset = (index % textureSheetSize); + return getTarget().getInterpolatedU( + (getOriginal().getUnInterpolatedU(localU) + (uOffset * 16)) / ((float) textureSheetSize)); } - public float getVShift(int index) { - return getTarget().getInterpolatedV((index / textureSheetSize) * (16 / textureSheetSize)) - - getOriginal().getMinV(); + public float getTargetV(float localV, int index) { + float vOffset = (index / textureSheetSize); + return getTarget().getInterpolatedV( + (getOriginal().getUnInterpolatedV(localV) + (vOffset * 16)) / ((float) textureSheetSize)); } public abstract int getTextureIndex(CTContext context); diff --git a/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java b/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java index e4347f52a..d7afff84c 100644 --- a/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java +++ b/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java @@ -22,7 +22,9 @@ import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.resources.I18n; import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.TieredItem; import net.minecraft.util.text.TextFormatting; public class TooltipHelper { @@ -169,11 +171,11 @@ public class TooltipHelper { } public static String getTooltipTranslationKey(ItemStack stack) { - - if (stack.getItem() instanceof AbstractToolItem) { - AbstractToolItem abstractToolItem = (AbstractToolItem) stack.getItem(); - if (abstractToolItem.getTier() instanceof AllToolTiers) { - AllToolTiers allToolTiers = (AllToolTiers) abstractToolItem.getTier(); + Item item = stack.getItem(); + if (item instanceof TieredItem) { + TieredItem tieredItem = (TieredItem) stack.getItem(); + if (tieredItem.getTier() instanceof AllToolTiers) { + AllToolTiers allToolTiers = (AllToolTiers) tieredItem.getTier(); return "tool.create." + Lang.asId(allToolTiers.name()) + ".tooltip"; } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java index e74dc2c64..f5d3a9dd4 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java @@ -4,9 +4,10 @@ import java.nio.ByteBuffer; import javax.vecmath.Matrix4f; +import com.simibubi.create.foundation.block.render.SpriteShiftEntry; + import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GLAllocation; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.Direction.Axis; @@ -26,7 +27,9 @@ public class SuperByteBuffer { // Vertex Texture Coords private boolean shouldShiftUV; - private float uShift, vShift; + private boolean resetUV; + private SpriteShiftEntry spriteShift; + private float uTarget, vTarget; // Vertex Lighting private boolean shouldLight; @@ -37,6 +40,7 @@ public class SuperByteBuffer { // Vertex Coloring private boolean shouldColor; private int r, g, b, a; + private float sheetSize; public SuperByteBuffer(ByteBuffer original) { original.rewind(); @@ -80,8 +84,18 @@ public class SuperByteBuffer { putColor(mutable, vertex, (byte) r2, (byte) g2, (byte) b2, (byte) a); } - if (shouldShiftUV) - putUV(mutable, vertex, getU(original, vertex) + uShift, getV(original, vertex) + vShift); + if (shouldShiftUV) { + float u = getU(original, vertex); + float v = getV(original, vertex); + float targetU = spriteShift.getTarget() + .getInterpolatedU((spriteShift.getOriginal().getUnInterpolatedU(u) / sheetSize) + uTarget * 16); + float targetV = spriteShift.getTarget() + .getInterpolatedV((spriteShift.getOriginal().getUnInterpolatedV(v) / sheetSize) + vTarget * 16); + putUV(mutable, vertex, targetU, targetV); + } + + if (resetUV) + putUV(mutable, vertex, getU(original, vertex), getV(original, vertex)); if (shouldLight) { if (vertexLighter != null) @@ -134,24 +148,29 @@ public class SuperByteBuffer { return translate(-.5f, -.5f, -.5f).rotate(axis, angle).translate(.5f, .5f, .5f); } - public SuperByteBuffer shiftUV(TextureAtlasSprite from, TextureAtlasSprite to) { + public SuperByteBuffer shiftUV(SpriteShiftEntry entry) { shouldShiftUV = true; - uShift = to.getMinU() - from.getMinU(); - vShift = to.getMinV() - from.getMinV(); + resetUV = false; + spriteShift = entry; + uTarget = 0; + vTarget = 0; + sheetSize = 1; return this; } - public SuperByteBuffer shiftUVtoSheet(TextureAtlasSprite from, TextureAtlasSprite to, int sheetX, int sheetY) { + public SuperByteBuffer shiftUVtoSheet(SpriteShiftEntry entry, float uTarget, float vTarget, int sheetSize) { shouldShiftUV = true; - uShift = to.getInterpolatedU(sheetX * 16f / to.getWidth()) - from.getMinU(); - vShift = to.getInterpolatedV(sheetY * 16f / to.getHeight()) - from.getMinV(); + resetUV = false; + spriteShift = entry; + this.uTarget = uTarget; + this.vTarget = vTarget; + this.sheetSize = sheetSize; return this; } public SuperByteBuffer dontShiftUV() { shouldShiftUV = false; - uShift = 0; - vShift = 0; + resetUV = true; return this; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/BlockMovementTraits.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/BlockMovementTraits.java index 66812cd98..39e8a6b0e 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/BlockMovementTraits.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/BlockMovementTraits.java @@ -5,6 +5,7 @@ import com.simibubi.create.modules.contraptions.components.actors.HarvesterBlock import com.simibubi.create.modules.contraptions.components.actors.PortableStorageInterfaceBlock; import com.simibubi.create.modules.contraptions.components.contraptions.chassis.AbstractChassisBlock; import com.simibubi.create.modules.logistics.block.AttachedLogisticalBlock; +import com.simibubi.create.modules.logistics.block.RedstoneLinkBlock; import com.simibubi.create.modules.logistics.block.extractor.ExtractorBlock; import com.simibubi.create.modules.logistics.block.funnel.FunnelBlock; import com.simibubi.create.modules.logistics.block.transposer.TransposerBlock; @@ -94,6 +95,8 @@ public class BlockMovementTraits { return true; if (block instanceof RedstoneWireBlock) return true; + if (block instanceof RedstoneLinkBlock) + return true; return false; } @@ -112,6 +115,8 @@ public class BlockMovementTraits { return direction == Direction.DOWN; if (block instanceof AttachedLogisticalBlock && !(block instanceof TransposerBlock)) return direction == AttachedLogisticalBlock.getBlockFacing(state); + if (block instanceof RedstoneLinkBlock) + return direction.getOpposite() == state.get(RedstoneLinkBlock.FACING); if (block instanceof FlowerPotBlock) return direction == Direction.DOWN; if (block instanceof RedstoneDiodeBlock) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/Contraption.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/Contraption.java index 84dd90e5f..d02b8aab7 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/Contraption.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/Contraption.java @@ -31,11 +31,13 @@ import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock; import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity; import com.simibubi.create.modules.logistics.block.inventories.FlexcrateBlock; +import net.minecraft.block.AbstractButtonBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.ChestBlock; import net.minecraft.block.DoorBlock; +import net.minecraft.block.PressurePlateBlock; import net.minecraft.block.SlimeBlock; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.ListNBT; @@ -216,6 +218,14 @@ public abstract class Contraption { blockstate = blockstate.with(FlexcrateBlock.DOUBLE, false); if (AllBlocks.CONTACT.typeOf(blockstate)) blockstate = blockstate.with(ContactBlock.POWERED, true); + if (blockstate.getBlock() instanceof AbstractButtonBlock) { + blockstate = blockstate.with(AbstractButtonBlock.POWERED, false); + world.getPendingBlockTicks().scheduleTick(pos, blockstate.getBlock(), -1); + } + if (blockstate.getBlock() instanceof PressurePlateBlock) { + blockstate = blockstate.with(PressurePlateBlock.POWERED, false); + world.getPendingBlockTicks().scheduleTick(pos, blockstate.getBlock(), -1); + } CompoundNBT compoundnbt = getTileEntityNBT(world, pos); TileEntity tileentity = world.getTileEntity(pos); return Pair.of(new BlockInfo(pos, blockstate, compoundnbt), tileentity); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/crafter/MechanicalCrafterTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/components/crafter/MechanicalCrafterTileEntityRenderer.java index 079d571cb..833413322 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/crafter/MechanicalCrafterTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/crafter/MechanicalCrafterTileEntityRenderer.java @@ -162,10 +162,9 @@ public class MechanicalCrafterTileEntityRenderer extends SafeTileEntityRenderer< if (te.phase == Phase.EXPORTING) { int textureIndex = (int) ((te.getCountDownSpeed() / 128f * AnimationTickHolder.ticks)); - beltBuffer.shiftUVtoSheet(animatedTexture.getOriginal(), animatedTexture.getTarget(), - (textureIndex % 4) * 4, 0); + beltBuffer.shiftUVtoSheet(animatedTexture, (textureIndex % 4) / 4f, 0, 1); } else { - beltBuffer.shiftUVtoSheet(animatedTexture.getOriginal(), animatedTexture.getTarget(), 0, 0); + beltBuffer.dontShiftUV(); } beltBuffer.translate(x, y, z).renderInto(buffer); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntityRenderer.java index 822d55cca..9f7a7d5ea 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntityRenderer.java @@ -74,10 +74,9 @@ public class BeltTileEntityRenderer extends SafeTileEntityRenderer { Direction face = q.getFace(); - if (face != null && windowState.isSideInvisible(world.getBlockState(position), face)) + if (face != null + && world.getBlockState(position.offset(face)).isSideInvisible(windowState, face)) return false; if (face != null && Block.hasSolidSide(partialState, world, position, face)) return false; diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/inventories/FlexcrateTileEntity.java b/src/main/java/com/simibubi/create/modules/logistics/block/inventories/FlexcrateTileEntity.java index 7b5fd303a..2b9dea2cf 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/inventories/FlexcrateTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/inventories/FlexcrateTileEntity.java @@ -193,8 +193,11 @@ public class FlexcrateTileEntity extends SyncedTileEntity implements INamedConta @Override public LazyOptional getCapability(Capability capability, Direction facing) { - if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) - return getMainCrate().invHandler.cast(); + if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { + FlexcrateTileEntity mainCrate = getMainCrate(); + if (mainCrate != null && mainCrate.invHandler.isPresent()) + return mainCrate.invHandler.cast(); + } return super.getCapability(capability, facing); } diff --git a/src/main/java/com/simibubi/create/modules/palettes/CTGlassPaneBlock.java b/src/main/java/com/simibubi/create/modules/palettes/CTGlassPaneBlock.java index 91e01c4b2..79be37c75 100644 --- a/src/main/java/com/simibubi/create/modules/palettes/CTGlassPaneBlock.java +++ b/src/main/java/com/simibubi/create/modules/palettes/CTGlassPaneBlock.java @@ -4,10 +4,12 @@ import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry; import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour; import com.simibubi.create.foundation.block.connected.IHaveConnectedTextures; import com.simibubi.create.foundation.block.connected.StandardCTBehaviour; +import com.simibubi.create.modules.curiosities.partialWindows.WindowInABlockTileEntity; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.Direction; import net.minecraft.util.Direction.AxisDirection; @@ -34,8 +36,6 @@ public class CTGlassPaneBlock extends GlassPaneBlock implements IHaveConnectedTe return adjacentBlockState == state; return super.isSideInvisible(state, adjacentBlockState, side); } - - protected ConnectedTextureBehaviour createBehaviour() { for (CTSpriteShiftEntry ctSpriteShiftEntry : ctGlass.getBehaviour().getAllCTShifts()) { @@ -43,6 +43,15 @@ public class CTGlassPaneBlock extends GlassPaneBlock implements IHaveConnectedTe @Override public boolean connectsTo(BlockState state, BlockState other, IEnviromentBlockReader reader, BlockPos pos, BlockPos otherPos, Direction face) { + + TileEntity te = reader.getTileEntity(pos); + if (te instanceof WindowInABlockTileEntity) + state = ((WindowInABlockTileEntity) te).getWindowBlock(); + + TileEntity otherTE = reader.getTileEntity(otherPos); + if (otherTE instanceof WindowInABlockTileEntity) + other = ((WindowInABlockTileEntity) otherTE).getWindowBlock(); + return state.getBlock() == other.getBlock(); }