From ed19a65b9f8d353366df61cf05dc6671b6a84773 Mon Sep 17 00:00:00 2001 From: tterrag Date: Sun, 12 Apr 2020 16:27:08 -0400 Subject: [PATCH] Port new code to 1.15 --- .../block/connected/CTSpriteShiftEntry.java | 5 +++-- .../foundation/utility/SuperByteBuffer.java | 15 +++++++++++++-- .../create/modules/contraptions/IWrenchable.java | 9 +++++---- 3 files changed, 21 insertions(+), 8 deletions(-) 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 7401bb472..0ac5d7a1a 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 @@ -2,6 +2,7 @@ package com.simibubi.create.foundation.block.connected; import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour.CTContext; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; +import com.simibubi.create.foundation.utility.SuperByteBuffer; public abstract class CTSpriteShiftEntry extends SpriteShiftEntry { @@ -14,13 +15,13 @@ public abstract class CTSpriteShiftEntry extends SpriteShiftEntry { public float getTargetU(float localU, int index) { float uOffset = (index % textureSheetSize); return getTarget().getInterpolatedU( - (getOriginal().getUnInterpolatedU(localU) + (uOffset * 16)) / ((float) textureSheetSize)); + (SuperByteBuffer.getUnInterpolatedU(getOriginal(), localU) + (uOffset * 16)) / ((float) textureSheetSize)); } public float getTargetV(float localV, int index) { float vOffset = (index / textureSheetSize); return getTarget().getInterpolatedV( - (getOriginal().getUnInterpolatedV(localV) + (vOffset * 16)) / ((float) textureSheetSize)); + (SuperByteBuffer.getUnInterpolatedV(getOriginal(), localV) + (vOffset * 16)) / ((float) textureSheetSize)); } public abstract int getTextureIndex(CTContext context); 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 7cb230390..f2100d5a9 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java @@ -10,6 +10,7 @@ import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.BufferBuilder.DrawState; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.GLAllocation; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.Vector4f; @@ -88,9 +89,9 @@ public class SuperByteBuffer { float u = getU(original, vertex); float v = getV(original, vertex); float targetU = spriteShift.getTarget() - .getInterpolatedU((spriteShift.getOriginal().getUnInterpolatedU(u) / sheetSize) + uTarget * 16); + .getInterpolatedU((getUnInterpolatedU(spriteShift.getOriginal(), u) / sheetSize) + uTarget * 16); float targetV = spriteShift.getTarget() - .getInterpolatedV((spriteShift.getOriginal().getUnInterpolatedV(v) / sheetSize) + vTarget * 16); + .getInterpolatedV((getUnInterpolatedV(spriteShift.getOriginal(), v) / sheetSize) + vTarget * 16); putUV(mutable, vertex, targetU, targetV); } @@ -113,6 +114,16 @@ public class SuperByteBuffer { mutable.rewind(); return mutable; } + + public static float getUnInterpolatedU(TextureAtlasSprite sprite, float u) { + float f = sprite.getMaxU() - sprite.getMinU(); + return (u - sprite.getMinU()) / f * 16.0F; + } + + public static float getUnInterpolatedV(TextureAtlasSprite sprite, float v) { + float f = sprite.getMaxV() - sprite.getMinV(); + return (v - sprite.getMinV()) / f * 16.0F; + } public void renderInto(MatrixStack input, IVertexBuilder buffer) { if (original.limit() == 0) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/IWrenchable.java b/src/main/java/com/simibubi/create/modules/contraptions/IWrenchable.java index 667c32468..71756a241 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/IWrenchable.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/IWrenchable.java @@ -1,5 +1,6 @@ package com.simibubi.create.modules.contraptions; +import com.simibubi.create.foundation.utility.DirectionHelper; import com.simibubi.create.foundation.utility.VoxelShaper; import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock; import com.simibubi.create.modules.contraptions.base.DirectionalKineticBlock; @@ -43,13 +44,13 @@ public interface IWrenchable { if (targetedFace.getAxis() == Direction.Axis.Y) { if (originalState.has(HorizontalAxisKineticBlock.HORIZONTAL_AXIS)) - return originalState.with(HorizontalAxisKineticBlock.HORIZONTAL_AXIS, VoxelShaper.axisAsFace(originalState.get(HorizontalAxisKineticBlock.HORIZONTAL_AXIS)).rotateAround(targetedFace.getAxis()).getAxis()); + return originalState.with(HorizontalAxisKineticBlock.HORIZONTAL_AXIS, DirectionHelper.rotateAround(VoxelShaper.axisAsFace(originalState.get(HorizontalAxisKineticBlock.HORIZONTAL_AXIS)), targetedFace.getAxis()).getAxis()); if (originalState.has(HorizontalKineticBlock.HORIZONTAL_FACING)) - return originalState.with(HorizontalKineticBlock.HORIZONTAL_FACING, originalState.get(HorizontalKineticBlock.HORIZONTAL_FACING).rotateAround(targetedFace.getAxis())); + return originalState.with(HorizontalKineticBlock.HORIZONTAL_FACING, DirectionHelper.rotateAround(originalState.get(HorizontalKineticBlock.HORIZONTAL_FACING), targetedFace.getAxis())); } if (originalState.has(RotatedPillarKineticBlock.AXIS)) - return originalState.with(RotatedPillarKineticBlock.AXIS, VoxelShaper.axisAsFace(originalState.get(RotatedPillarKineticBlock.AXIS)).rotateAround(targetedFace.getAxis()).getAxis()); + return originalState.with(RotatedPillarKineticBlock.AXIS, DirectionHelper.rotateAround(VoxelShaper.axisAsFace(originalState.get(RotatedPillarKineticBlock.AXIS)), targetedFace.getAxis()).getAxis()); if (!originalState.has(DirectionalKineticBlock.FACING)) return originalState; @@ -60,7 +61,7 @@ public interface IWrenchable { else return originalState; } else { do { - newState = newState.with(DirectionalKineticBlock.FACING, newState.get(DirectionalKineticBlock.FACING).rotateAround(targetedFace.getAxis())); + newState = newState.with(DirectionalKineticBlock.FACING, DirectionHelper.rotateAround(newState.get(DirectionalKineticBlock.FACING), targetedFace.getAxis())); if (targetedFace.getAxis() == Direction.Axis.Y && newState.has(DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE)) newState = newState.cycle(DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE); } while (newState.get(DirectionalKineticBlock.FACING).getAxis().equals(targetedFace.getAxis())); }