From a52116bf0b79c44e3b9eae9a352803eb315d63dc Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Wed, 6 Jul 2022 12:06:27 -0700 Subject: [PATCH] Clean CT - Move code from CTSpriteShiftEntry subclasses into CTType enum fields - Add ContextRequirement to specify which context directions should be populated - Rename CTType to AllCTTypes and add CTType interface and CTTypeRegistry - Add methods and fields to QuadHelper to simplify vertex data manipulation - Make no bracket mean null instead of air to prevent issues with non-empty air models - Remove unused palette classes - Organize imports --- .../com/simibubi/create/AllSpriteShifts.java | 72 +++--- .../crafter/CrafterCTBehaviour.java | 7 +- .../steam/whistle/WhistleSoundInstance.java | 2 +- .../chassis/LinearChassisBlock.java | 7 +- .../fluids/PipeAttachmentModel.java | 8 +- .../fluids/pipes/AxisPipeBlock.java | 6 +- .../fluids/pipes/BracketBlockItem.java | 3 +- .../fluids/pipes/FluidPipeBlock.java | 6 +- .../fluids/tank/FluidTankCTBehaviour.java | 12 +- .../contraptions/processing/BasinRecipe.java | 3 +- .../contraptions/relays/belt/BeltModel.java | 32 +-- .../elementary/AbstractSimpleShaftBlock.java | 6 +- .../BracketedKineticBlockModel.java | 11 +- .../BracketedTileEntityBehaviour.java | 44 ++-- .../relays/encased/EncasedCTBehaviour.java | 7 +- .../relays/encased/EncasedCogCTBehaviour.java | 7 +- .../curiosities/deco/TrapdoorCTBehaviour.java | 7 +- .../curiosities/girder/GirderBlock.java | 2 +- .../curiosities/girder/GirderCTBehaviour.java | 7 +- .../weapons/PotatoProjectileRenderMode.java | 2 + .../block/belts/tunnel/BeltTunnelItem.java | 1 + .../belts/tunnel/BrassTunnelCTBehaviour.java | 27 +- .../block/vault/ItemVaultCTBehaviour.java | 7 +- .../content/palettes/AllPaletteBlocks.java | 4 +- .../palettes/ConnectedOreCTBehaviour.java | 139 ----------- .../palettes/ConnectedSixwayBlock.java | 22 -- .../content/palettes/PaletteBlockPattern.java | 9 +- .../block/connected/AllCTTypes.java | 133 ++++++++++ .../foundation/block/connected/CTModel.java | 79 +++--- .../block/connected/CTSpriteShiftEntry.java | 183 +------------- .../block/connected/CTSpriteShifter.java | 45 +--- .../foundation/block/connected/CTType.java | 16 ++ .../block/connected/CTTypeRegistry.java | 24 ++ .../connected/ConnectedTextureBehaviour.java | 230 ++++++++++++++---- .../block/connected/GlassPaneCTBehaviour.java | 2 +- .../connected/HorizontalCTBehaviour.java | 11 +- .../connected/RotatedPillarCTBehaviour.java | 7 +- .../block/connected/SimpleCTBehaviour.java | 22 ++ .../block/connected/StandardCTBehaviour.java | 19 -- .../foundation/block/render/QuadHelper.java | 31 +++ .../block/render/SpriteShiftEntry.java | 18 ++ .../block/render/SpriteShifter.java | 8 +- .../foundation/render/SuperByteBuffer.java | 21 +- .../tileEntity/IMultiTileContainer.java | 4 +- 44 files changed, 656 insertions(+), 657 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/content/palettes/ConnectedOreCTBehaviour.java delete mode 100644 src/main/java/com/simibubi/create/content/palettes/ConnectedSixwayBlock.java create mode 100644 src/main/java/com/simibubi/create/foundation/block/connected/AllCTTypes.java create mode 100644 src/main/java/com/simibubi/create/foundation/block/connected/CTType.java create mode 100644 src/main/java/com/simibubi/create/foundation/block/connected/CTTypeRegistry.java create mode 100644 src/main/java/com/simibubi/create/foundation/block/connected/SimpleCTBehaviour.java delete mode 100644 src/main/java/com/simibubi/create/foundation/block/connected/StandardCTBehaviour.java diff --git a/src/main/java/com/simibubi/create/AllSpriteShifts.java b/src/main/java/com/simibubi/create/AllSpriteShifts.java index 0cb24a5bd..31abb134d 100644 --- a/src/main/java/com/simibubi/create/AllSpriteShifts.java +++ b/src/main/java/com/simibubi/create/AllSpriteShifts.java @@ -1,16 +1,14 @@ package com.simibubi.create; -import static com.simibubi.create.foundation.block.connected.CTSpriteShifter.getCT; -import static com.simibubi.create.foundation.block.connected.CTSpriteShifter.CTType.HORIZONTAL; -import static com.simibubi.create.foundation.block.connected.CTSpriteShifter.CTType.OMNIDIRECTIONAL; -import static com.simibubi.create.foundation.block.connected.CTSpriteShifter.CTType.VERTICAL; - import java.util.Arrays; +import java.util.EnumMap; import java.util.IdentityHashMap; import java.util.Map; +import com.simibubi.create.foundation.block.connected.AllCTTypes; import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry; -import com.simibubi.create.foundation.block.connected.CTSpriteShifter.CTType; +import com.simibubi.create.foundation.block.connected.CTSpriteShifter; +import com.simibubi.create.foundation.block.connected.CTType; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import com.simibubi.create.foundation.block.render.SpriteShifter; import com.simibubi.create.foundation.utility.Couple; @@ -22,22 +20,22 @@ public class AllSpriteShifts { private static final Map WOODEN_WINDOWS = new IdentityHashMap<>(); - public static final Map DYED_BELTS = new IdentityHashMap<>(), - DYED_OFFSET_BELTS = new IdentityHashMap<>(), DYED_DIAGONAL_BELTS = new IdentityHashMap<>(); + public static final Map DYED_BELTS = new EnumMap<>(DyeColor.class), + DYED_OFFSET_BELTS = new EnumMap<>(DyeColor.class), DYED_DIAGONAL_BELTS = new EnumMap<>(DyeColor.class); public static final SpriteShiftEntry BURNER_FLAME = - SpriteShifter.get("block/blaze_burner_flame", "block/blaze_burner_flame_scroll"), + get("block/blaze_burner_flame", "block/blaze_burner_flame_scroll"), SUPER_BURNER_FLAME = - SpriteShifter.get("block/blaze_burner_flame", "block/blaze_burner_flame_superheated_scroll"); + get("block/blaze_burner_flame", "block/blaze_burner_flame_superheated_scroll"); public static final CTSpriteShiftEntry FRAMED_GLASS = - getCT(OMNIDIRECTIONAL, "palettes/framed_glass", "palettes/framed_glass"), + getCT(AllCTTypes.OMNIDIRECTIONAL, "palettes/framed_glass", "palettes/framed_glass"), HORIZONTAL_FRAMED_GLASS = - getCT(CTType.HORIZONTAL_KRYPPERS, "palettes/framed_glass", "palettes/horizontal_framed_glass"), - VERTICAL_FRAMED_GLASS = getCT(VERTICAL, "palettes/framed_glass", "palettes/vertical_framed_glass"), + getCT(AllCTTypes.HORIZONTAL_KRYPPERS, "palettes/framed_glass", "palettes/horizontal_framed_glass"), + VERTICAL_FRAMED_GLASS = getCT(AllCTTypes.VERTICAL, "palettes/framed_glass", "palettes/vertical_framed_glass"), ORNATE_IRON_WINDOW = vertical("palettes/ornate_iron_window"); - public static final CTSpriteShiftEntry CRAFTER_FRONT = getCT(CTType.OMNIDIRECTIONAL, "crafter_top", "brass_casing"), + public static final CTSpriteShiftEntry CRAFTER_FRONT = getCT(AllCTTypes.OMNIDIRECTIONAL, "crafter_top", "brass_casing"), CRAFTER_SIDE = vertical("crafter_side"), CRAFTER_OTHERSIDE = horizontal("crafter_side"), ANDESITE_ENCASED_COGWHEEL_SIDE = vertical("andesite_encased_cogwheel_side"), ANDESITE_ENCASED_COGWHEEL_OTHERSIDE = horizontal("andesite_encased_cogwheel_side"), @@ -49,25 +47,25 @@ public class AllSpriteShifts { BRASS_CASING = omni("brass_casing"), COPPER_CASING = omni("copper_casing"), SHADOW_STEEL_CASING = omni("shadow_steel_casing"), REFINED_RADIANCE_CASING = omni("refined_radiance_casing"), RAILWAY_CASING = omni("railway_casing"), RAILWAY_CASING_SIDE = omni("railway_casing_side"), - CREATIVE_CASING = getCT(CTType.CROSS, "creative_casing"); + CREATIVE_CASING = getCT(AllCTTypes.CROSS, "creative_casing"); public static final CTSpriteShiftEntry CHASSIS_SIDE = omni("linear_chassis_side"), SECONDARY_CHASSIS_SIDE = omni("secondary_linear_chassis_side"), CHASSIS = omni("linear_chassis_end"), CHASSIS_STICKY = omni("linear_chassis_end_sticky"); public static final CTSpriteShiftEntry BRASS_TUNNEL_TOP = vertical("brass_tunnel_top"), - FLUID_TANK = getCT(CTType.RECTANGLE, "fluid_tank"), FLUID_TANK_TOP = getCT(CTType.RECTANGLE, "fluid_tank_top"), - FLUID_TANK_INNER = getCT(CTType.RECTANGLE, "fluid_tank_inner"), - CREATIVE_FLUID_TANK = getCT(CTType.CROSS, "creative_fluid_tank"); + FLUID_TANK = getCT(AllCTTypes.RECTANGLE, "fluid_tank"), FLUID_TANK_TOP = getCT(AllCTTypes.RECTANGLE, "fluid_tank_top"), + FLUID_TANK_INNER = getCT(AllCTTypes.RECTANGLE, "fluid_tank_inner"), + CREATIVE_FLUID_TANK = getCT(AllCTTypes.CROSS, "creative_fluid_tank"); public static final Couple VAULT_TOP = vault("top"), VAULT_FRONT = vault("front"), VAULT_SIDE = vault("side"), VAULT_BOTTOM = vault("bottom"); - public static final SpriteShiftEntry BELT = SpriteShifter.get("block/belt", "block/belt_scroll"), - BELT_OFFSET = SpriteShifter.get("block/belt_offset", "block/belt_scroll"), - BELT_DIAGONAL = SpriteShifter.get("block/belt_diagonal", "block/belt_diagonal_scroll"), - ANDESIDE_BELT_CASING = SpriteShifter.get("block/brass_casing_belt", "block/andesite_casing_belt"), - CRAFTER_THINGIES = SpriteShifter.get("block/crafter_thingies", "block/crafter_thingies"); + public static final SpriteShiftEntry BELT = get("block/belt", "block/belt_scroll"), + BELT_OFFSET = get("block/belt_offset", "block/belt_scroll"), + BELT_DIAGONAL = get("block/belt_diagonal", "block/belt_diagonal_scroll"), + ANDESIDE_BELT_CASING = get("block/brass_casing_belt", "block/andesite_casing_belt"), + CRAFTER_THINGIES = get("block/crafter_thingies", "block/crafter_thingies"); static { populateMaps(); @@ -81,30 +79,44 @@ public class AllSpriteShifts { for (DyeColor color : DyeColor.values()) { String id = color.getSerializedName(); - DYED_BELTS.put(color, SpriteShifter.get("block/belt", "block/belt/" + id + "_scroll")); - DYED_OFFSET_BELTS.put(color, SpriteShifter.get("block/belt_offset", "block/belt/" + id + "_scroll")); + DYED_BELTS.put(color, get("block/belt", "block/belt/" + id + "_scroll")); + DYED_OFFSET_BELTS.put(color, get("block/belt_offset", "block/belt/" + id + "_scroll")); DYED_DIAGONAL_BELTS.put(color, - SpriteShifter.get("block/belt_diagonal", "block/belt/" + id + "_diagonal_scroll")); + get("block/belt_diagonal", "block/belt/" + id + "_diagonal_scroll")); } } private static Couple vault(String name) { final String prefixed = "vault_" + name; - return Couple.createWithContext(b -> getCT(CTType.CROSS, prefixed, b ? prefixed : prefixed + "_large")); + return Couple.createWithContext(b -> getCT(AllCTTypes.CROSS, prefixed, b ? prefixed : prefixed + "_large")); } // private static CTSpriteShiftEntry omni(String name) { - return getCT(OMNIDIRECTIONAL, name); + return getCT(AllCTTypes.OMNIDIRECTIONAL, name); } private static CTSpriteShiftEntry horizontal(String name) { - return getCT(HORIZONTAL, name); + return getCT(AllCTTypes.HORIZONTAL, name); } private static CTSpriteShiftEntry vertical(String name) { - return getCT(VERTICAL, name); + return getCT(AllCTTypes.VERTICAL, name); + } + + // + + private static SpriteShiftEntry get(String originalLocation, String targetLocation) { + return SpriteShifter.get(Create.asResource(originalLocation), Create.asResource(targetLocation)); + } + + private static CTSpriteShiftEntry getCT(CTType type, String blockTextureName, String connectedTextureName) { + return CTSpriteShifter.getCT(type, Create.asResource("block/" + blockTextureName), Create.asResource("block/" + connectedTextureName + "_connected")); + } + + private static CTSpriteShiftEntry getCT(CTType type, String blockTextureName) { + return getCT(type, blockTextureName, blockTextureName); } // diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/CrafterCTBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/CrafterCTBehaviour.java index 1ead5b41a..369d36908 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/CrafterCTBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/CrafterCTBehaviour.java @@ -2,11 +2,14 @@ package com.simibubi.create.content.contraptions.components.crafter; import static com.simibubi.create.content.contraptions.base.HorizontalKineticBlock.HORIZONTAL_FACING; +import org.jetbrains.annotations.Nullable; + import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.content.contraptions.components.crafter.ConnectedInputHandler.ConnectedInput; import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry; import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; @@ -14,7 +17,7 @@ import net.minecraft.core.Direction.AxisDirection; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; -public class CrafterCTBehaviour extends ConnectedTextureBehaviour { +public class CrafterCTBehaviour extends ConnectedTextureBehaviour.Base { @Override public boolean connectsTo(BlockState state, BlockState other, BlockAndTintGetter reader, BlockPos pos, BlockPos otherPos, @@ -58,7 +61,7 @@ public class CrafterCTBehaviour extends ConnectedTextureBehaviour { } @Override - public CTSpriteShiftEntry get(BlockState state, Direction direction) { + public CTSpriteShiftEntry getShift(BlockState state, Direction direction, @Nullable TextureAtlasSprite sprite) { Direction facing = state.getValue(HORIZONTAL_FACING); boolean isFront = facing.getAxis() == direction.getAxis(); boolean isVertical = direction.getAxis() diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/steam/whistle/WhistleSoundInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/steam/whistle/WhistleSoundInstance.java index 0a91e3340..4919b895b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/steam/whistle/WhistleSoundInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/steam/whistle/WhistleSoundInstance.java @@ -1,8 +1,8 @@ package com.simibubi.create.content.contraptions.components.steam.whistle; -import static com.simibubi.create.AllSoundEvents.WHISTLE_MEDIUM; import static com.simibubi.create.AllSoundEvents.WHISTLE_HIGH; import static com.simibubi.create.AllSoundEvents.WHISTLE_LOW; +import static com.simibubi.create.AllSoundEvents.WHISTLE_MEDIUM; import com.simibubi.create.content.contraptions.components.steam.whistle.WhistleBlock.WhistleSize; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/LinearChassisBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/LinearChassisBlock.java index fd745eeee..6545e64ec 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/LinearChassisBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/LinearChassisBlock.java @@ -1,10 +1,13 @@ package com.simibubi.create.content.contraptions.components.structureMovement.chassis; +import org.jetbrains.annotations.Nullable; + import com.simibubi.create.AllBlocks; import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry; import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; @@ -83,10 +86,10 @@ public class LinearChassisBlock extends AbstractChassisBlock { return state1.getBlock() == state2.getBlock(); } - public static class ChassisCTBehaviour extends ConnectedTextureBehaviour { + public static class ChassisCTBehaviour extends ConnectedTextureBehaviour.Base { @Override - public CTSpriteShiftEntry get(BlockState state, Direction direction) { + public CTSpriteShiftEntry getShift(BlockState state, Direction direction, @Nullable TextureAtlasSprite sprite) { Block block = state.getBlock(); BooleanProperty glueableSide = ((LinearChassisBlock) block).getGlueableSide(state, direction); if (glueableSide == null) 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 b07ec662a..c4ab64276 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 @@ -98,9 +98,11 @@ public class PipeAttachmentModel extends BakedModelWrapperWithData { } public void putBracket(BlockState state) { - this.bracket = Minecraft.getInstance() - .getBlockRenderer() - .getBlockModel(state); + if (state != null) { + this.bracket = Minecraft.getInstance() + .getBlockRenderer() + .getBlockModel(state); + } } public BakedModel getBracket() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/AxisPipeBlock.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/AxisPipeBlock.java index 3f3de42c4..1bcb6bbb1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/AxisPipeBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/AxisPipeBlock.java @@ -29,7 +29,6 @@ import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.RotatedPillarBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BooleanProperty; @@ -138,9 +137,8 @@ public class AxisPipeBlock extends RotatedPillarBlock implements IWrenchableWith BracketedTileEntityBehaviour behaviour = TileEntityBehaviour.get(world, pos, BracketedTileEntityBehaviour.TYPE); if (behaviour == null) return Optional.empty(); - BlockState bracket = behaviour.getBracket(); - behaviour.removeBracket(inOnReplacedContext); - if (bracket == Blocks.AIR.defaultBlockState()) + BlockState bracket = behaviour.removeBracket(inOnReplacedContext); + if (bracket == null) return Optional.empty(); return Optional.of(new ItemStack(bracket.getBlock())); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/BracketBlockItem.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/BracketBlockItem.java index 8e9322d94..71cfe2755 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/BracketBlockItem.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/BracketBlockItem.java @@ -15,7 +15,6 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; public class BracketBlockItem extends BlockItem { @@ -62,7 +61,7 @@ public class BracketBlockItem extends BlockItem { if (player == null || !player.isCreative()) { context.getItemInHand() .shrink(1); - if (bracket != Blocks.AIR.defaultBlockState()) { + if (bracket != null) { ItemStack returnedStack = new ItemStack(bracket.getBlock()); if (player == null) Block.popResource(world, pos, returnedStack); diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlock.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlock.java index 310534c25..b9d8d4be0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlock.java @@ -35,7 +35,6 @@ import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.PipeBlock; import net.minecraft.world.level.block.SimpleWaterloggedBlock; import net.minecraft.world.level.block.entity.BlockEntityType; @@ -312,9 +311,8 @@ public class FluidPipeBlock extends PipeBlock BracketedTileEntityBehaviour.get(world, pos, BracketedTileEntityBehaviour.TYPE); if (behaviour == null) return Optional.empty(); - BlockState bracket = behaviour.getBracket(); - behaviour.removeBracket(inOnReplacedContext); - if (bracket == Blocks.AIR.defaultBlockState()) + BlockState bracket = behaviour.removeBracket(inOnReplacedContext); + if (bracket == null) return Optional.empty(); return Optional.of(new ItemStack(bracket.getBlock())); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankCTBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankCTBehaviour.java index e6407879f..845fecb94 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankCTBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankCTBehaviour.java @@ -1,5 +1,7 @@ package com.simibubi.create.content.contraptions.fluids.tank; +import org.jetbrains.annotations.Nullable; + import com.simibubi.create.api.connectivity.ConnectivityHandler; import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry; import com.simibubi.create.foundation.block.connected.HorizontalCTBehaviour; @@ -19,12 +21,12 @@ public class FluidTankCTBehaviour extends HorizontalCTBehaviour { super(layerShift, topShift); this.innerShift = innerShift; } - + @Override - public CTSpriteShiftEntry get(BlockState state, Direction direction, TextureAtlasSprite sprite) { - if (direction.getAxis() == Axis.Y && innerShift.getOriginal() == sprite) + public CTSpriteShiftEntry getShift(BlockState state, Direction direction, @Nullable TextureAtlasSprite sprite) { + if (sprite != null && direction.getAxis() == Axis.Y && innerShift.getOriginal() == sprite) return innerShift; - return super.get(state, direction, sprite); + return super.getShift(state, direction, sprite); } public boolean buildContextForOccludedDirections() { @@ -34,6 +36,6 @@ public class FluidTankCTBehaviour extends HorizontalCTBehaviour { @Override public boolean connectsTo(BlockState state, BlockState other, BlockAndTintGetter reader, BlockPos pos, BlockPos otherPos, Direction face) { - return state.getBlock() == other.getBlock() && ConnectivityHandler.isConnected(reader, pos, otherPos); //FluidTankConnectivityHandler.isConnected(reader, pos, otherPos); + return state.getBlock() == other.getBlock() && ConnectivityHandler.isConnected(reader, pos, otherPos); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinRecipe.java index b51643b44..7e213f2e8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinRecipe.java @@ -8,8 +8,6 @@ import java.util.List; import javax.annotation.Nonnull; - -import com.simibubi.create.foundation.utility.recipe.IRecipeTypeInfo; import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.content.contraptions.processing.ProcessingRecipeBuilder.ProcessingRecipeParams; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel; @@ -19,6 +17,7 @@ import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBe import com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour.TankSegment; import com.simibubi.create.foundation.utility.Iterate; +import com.simibubi.create.foundation.utility.recipe.IRecipeTypeInfo; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; 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 8a6c713d8..e510303b3 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 @@ -6,13 +6,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.VertexFormat; import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity.CasingType; import com.simibubi.create.foundation.block.render.QuadHelper; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -24,6 +21,8 @@ import net.minecraftforge.client.model.data.IModelData; public class BeltModel extends BakedModelWrapper { + private static final SpriteShiftEntry SPRITE_SHIFT = AllSpriteShifts.ANDESIDE_BELT_CASING; + public BeltModel(BakedModel template) { super(template); } @@ -36,37 +35,28 @@ public class BeltModel extends BakedModelWrapper { CasingType type = extraData.getData(CASING_PROPERTY); if (type == CasingType.NONE || type == CasingType.BRASS) return quads; - quads = new ArrayList<>(quads); - SpriteShiftEntry spriteShift = AllSpriteShifts.ANDESIDE_BELT_CASING; - VertexFormat format = DefaultVertexFormat.BLOCK; + quads = new ArrayList<>(quads); for (int i = 0; i < quads.size(); i++) { BakedQuad quad = quads.get(i); - if (spriteShift == null) - continue; - if (quad.getSprite() != spriteShift.getOriginal()) + TextureAtlasSprite original = quad.getSprite(); + if (original != SPRITE_SHIFT.getOriginal()) continue; - TextureAtlasSprite original = quad.getSprite(); - TextureAtlasSprite target = spriteShift.getTarget(); BakedQuad newQuad = QuadHelper.clone(quad); int[] vertexData = newQuad.getVertices(); - for (int vertex = 0; vertex < vertexData.length; vertex += format.getIntegerSize()) { - int uvOffset = 16 / 4; - int uIndex = vertex + uvOffset; - int vIndex = vertex + uvOffset + 1; - float u = Float.intBitsToFloat(vertexData[uIndex]); - float v = Float.intBitsToFloat(vertexData[vIndex]); - vertexData[uIndex] = - Float.floatToRawIntBits(target.getU(SuperByteBuffer.getUnInterpolatedU(original, u))); - vertexData[vIndex] = - Float.floatToRawIntBits(target.getV(SuperByteBuffer.getUnInterpolatedV(original, v))); + 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)); } quads.set(i, newQuad); } + return quads; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/AbstractSimpleShaftBlock.java b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/AbstractSimpleShaftBlock.java index 85f84b697..192183709 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/AbstractSimpleShaftBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/AbstractSimpleShaftBlock.java @@ -14,7 +14,6 @@ import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.PushReaction; @@ -48,9 +47,8 @@ public abstract class AbstractSimpleShaftBlock extends AbstractShaftBlock implem BracketedTileEntityBehaviour behaviour = TileEntityBehaviour.get(world, pos, BracketedTileEntityBehaviour.TYPE); if (behaviour == null) return Optional.empty(); - BlockState bracket = behaviour.getBracket(); - behaviour.removeBracket(inOnReplacedContext); - if (bracket == Blocks.AIR.defaultBlockState()) + BlockState bracket = behaviour.removeBracket(inOnReplacedContext); + if (bracket == null) return Optional.empty(); return Optional.of(new ItemStack(bracket.getBlock())); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockModel.java b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockModel.java index b3c941eb8..dc52fdd69 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockModel.java @@ -55,18 +55,19 @@ public class BracketedKineticBlockModel extends BakedModelWrapper { } private static class BracketedModelData { - BakedModel bracket; + private BakedModel bracket; public void putBracket(BlockState state) { - this.bracket = Minecraft.getInstance() - .getBlockRenderer() - .getBlockModel(state); + if (state != null) { + this.bracket = Minecraft.getInstance() + .getBlockRenderer() + .getBlockModel(state); + } } public BakedModel getBracket() { return bracket; } - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedTileEntityBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedTileEntityBehaviour.java index 727c08699..8c5ae2e3b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedTileEntityBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedTileEntityBehaviour.java @@ -1,8 +1,9 @@ package com.simibubi.create.content.contraptions.relays.elementary; -import java.util.Optional; import java.util.function.Predicate; +import org.jetbrains.annotations.Nullable; + import com.simibubi.create.content.contraptions.components.structureMovement.StructureTransform; import com.simibubi.create.content.schematics.ItemRequirement; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; @@ -14,14 +15,13 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtUtils; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; public class BracketedTileEntityBehaviour extends TileEntityBehaviour { public static final BehaviourType TYPE = new BehaviourType<>(); - private Optional bracket; + private BlockState bracket; private boolean reRender; private Predicate pred; @@ -33,7 +33,6 @@ public class BracketedTileEntityBehaviour extends TileEntityBehaviour { public BracketedTileEntityBehaviour(SmartTileEntity te, Predicate pred) { super(te); this.pred = pred; - bracket = Optional.empty(); } @Override @@ -42,7 +41,7 @@ public class BracketedTileEntityBehaviour extends TileEntityBehaviour { } public void applyBracket(BlockState state) { - this.bracket = Optional.of(state); + this.bracket = state; reRender = true; tileEntity.notifyUpdate(); Level world = getWorld(); @@ -54,35 +53,42 @@ public class BracketedTileEntityBehaviour extends TileEntityBehaviour { public void transformBracket(StructureTransform transform) { if (isBracketPresent()) { - BlockState bracket = getBracket(); BlockState transformedBracket = transform.apply(bracket); applyBracket(transformedBracket); } } - public void removeBracket(boolean inOnReplacedContext) { + @Nullable + public BlockState removeBracket(boolean inOnReplacedContext) { + if (bracket == null) { + return null; + } + + BlockState removed = this.bracket; Level world = getWorld(); if (!world.isClientSide) - world.levelEvent(2001, getPos(), Block.getId(getBracket())); - this.bracket = Optional.empty(); + world.levelEvent(2001, getPos(), Block.getId(bracket)); + this.bracket = null; reRender = true; if (inOnReplacedContext) { tileEntity.sendData(); - return; + return removed; } tileEntity.notifyUpdate(); if (world.isClientSide) - return; + return removed; tileEntity.getBlockState() .updateNeighbourShapes(world, getPos(), 3); + return removed; } public boolean isBracketPresent() { - return bracket.isPresent(); + return bracket != null; } + @Nullable public BlockState getBracket() { - return bracket.orElse(Blocks.AIR.defaultBlockState()); + return bracket; } public boolean canHaveBracket() { @@ -91,7 +97,10 @@ public class BracketedTileEntityBehaviour extends TileEntityBehaviour { @Override public ItemRequirement getRequiredItems() { - return ItemRequirement.of(getBracket(), null); + if (!isBracketPresent()) { + return ItemRequirement.NONE; + } + return ItemRequirement.of(bracket, null); } @Override @@ -101,7 +110,9 @@ public class BracketedTileEntityBehaviour extends TileEntityBehaviour { @Override public void write(CompoundTag nbt, boolean clientPacket) { - bracket.ifPresent(p -> nbt.put("Bracket", NbtUtils.writeBlockState(p))); + if (isBracketPresent()) { + nbt.put("Bracket", NbtUtils.writeBlockState(bracket)); + } if (clientPacket && reRender) { NBTHelper.putMarker(nbt, "Redraw"); reRender = false; @@ -111,9 +122,8 @@ public class BracketedTileEntityBehaviour extends TileEntityBehaviour { @Override public void read(CompoundTag nbt, boolean clientPacket) { - bracket = Optional.empty(); if (nbt.contains("Bracket")) - bracket = Optional.of(NbtUtils.readBlockState(nbt.getCompound("Bracket"))); + bracket = NbtUtils.readBlockState(nbt.getCompound("Bracket")); if (clientPacket && nbt.contains("Redraw")) getWorld().sendBlockUpdated(getPos(), tileEntity.getBlockState(), tileEntity.getBlockState(), 16); super.read(nbt, clientPacket); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedCTBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedCTBehaviour.java index 10e3eb003..9afdaacb9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedCTBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedCTBehaviour.java @@ -1,15 +1,18 @@ package com.simibubi.create.content.contraptions.relays.encased; +import org.jetbrains.annotations.Nullable; + import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry; import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; -public class EncasedCTBehaviour extends ConnectedTextureBehaviour { +public class EncasedCTBehaviour extends ConnectedTextureBehaviour.Base { private CTSpriteShiftEntry shift; @@ -35,7 +38,7 @@ public class EncasedCTBehaviour extends ConnectedTextureBehaviour { } @Override - public CTSpriteShiftEntry get(BlockState state, Direction direction) { + public CTSpriteShiftEntry getShift(BlockState state, Direction direction, @Nullable TextureAtlasSprite sprite) { return shift; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedCogCTBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedCogCTBehaviour.java index f97f20404..bebb607d5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedCogCTBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedCogCTBehaviour.java @@ -2,11 +2,14 @@ package com.simibubi.create.content.contraptions.relays.encased; import static com.simibubi.create.content.contraptions.base.RotatedPillarKineticBlock.AXIS; +import org.jetbrains.annotations.Nullable; + import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel; import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry; import com.simibubi.create.foundation.utility.Couple; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; @@ -80,14 +83,14 @@ public class EncasedCogCTBehaviour extends EncasedCTBehaviour { } @Override - public CTSpriteShiftEntry get(BlockState state, Direction direction) { + public CTSpriteShiftEntry getShift(BlockState state, Direction direction, @Nullable TextureAtlasSprite sprite) { Axis axis = state.getValue(AXIS); if (large || axis == direction.getAxis()) { if (axis == direction.getAxis() && state .getValue(direction.getAxisDirection() == AxisDirection.POSITIVE ? EncasedCogwheelBlock.TOP_SHAFT : EncasedCogwheelBlock.BOTTOM_SHAFT)) return null; - return super.get(state, direction); + return super.getShift(state, direction, sprite); } return sideShifts.get(axis == Axis.X || axis == Axis.Z && direction.getAxis() == Axis.X); } diff --git a/src/main/java/com/simibubi/create/content/curiosities/deco/TrapdoorCTBehaviour.java b/src/main/java/com/simibubi/create/content/curiosities/deco/TrapdoorCTBehaviour.java index 5f4bc7f13..8856fa52e 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/deco/TrapdoorCTBehaviour.java +++ b/src/main/java/com/simibubi/create/content/curiosities/deco/TrapdoorCTBehaviour.java @@ -1,18 +1,21 @@ package com.simibubi.create.content.curiosities.deco; +import org.jetbrains.annotations.Nullable; + import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry; import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; -public class TrapdoorCTBehaviour extends ConnectedTextureBehaviour { +public class TrapdoorCTBehaviour extends ConnectedTextureBehaviour.Base { @Override - public CTSpriteShiftEntry get(BlockState state, Direction direction) { + public CTSpriteShiftEntry getShift(BlockState state, Direction direction, @Nullable TextureAtlasSprite sprite) { return AllSpriteShifts.FRAMED_GLASS; } diff --git a/src/main/java/com/simibubi/create/content/curiosities/girder/GirderBlock.java b/src/main/java/com/simibubi/create/content/curiosities/girder/GirderBlock.java index 09466fffe..ff20a1c6b 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/girder/GirderBlock.java +++ b/src/main/java/com/simibubi/create/content/curiosities/girder/GirderBlock.java @@ -242,7 +242,7 @@ public class GirderBlock extends Block implements SimpleWaterloggedBlock, IWrenc if (behaviour == null) return false; BlockState bracket = behaviour.getBracket(); - if (!bracket.hasProperty(BracketBlock.FACING)) + if (bracket == null || !bracket.hasProperty(BracketBlock.FACING)) return false; return bracket.getValue(BracketBlock.FACING) == d; } diff --git a/src/main/java/com/simibubi/create/content/curiosities/girder/GirderCTBehaviour.java b/src/main/java/com/simibubi/create/content/curiosities/girder/GirderCTBehaviour.java index 91fe3cfde..31eb029c1 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/girder/GirderCTBehaviour.java +++ b/src/main/java/com/simibubi/create/content/curiosities/girder/GirderCTBehaviour.java @@ -1,19 +1,22 @@ package com.simibubi.create.content.curiosities.girder; +import org.jetbrains.annotations.Nullable; + import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry; import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; -public class GirderCTBehaviour extends ConnectedTextureBehaviour { +public class GirderCTBehaviour extends ConnectedTextureBehaviour.Base { @Override - public CTSpriteShiftEntry get(BlockState state, Direction direction) { + public CTSpriteShiftEntry getShift(BlockState state, Direction direction, @Nullable TextureAtlasSprite sprite) { if (!state.hasProperty(GirderBlock.X)) return null; return !state.getValue(GirderBlock.X) && !state.getValue(GirderBlock.Z) && direction.getAxis() != Axis.Y diff --git a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileRenderMode.java b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileRenderMode.java index 449c7d8f8..46c96baab 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileRenderMode.java +++ b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileRenderMode.java @@ -1,5 +1,7 @@ package com.simibubi.create.content.curiosities.weapons; +import static com.simibubi.create.content.curiosities.weapons.PotatoProjectileRenderMode.entityRandom; + import com.jozufozu.flywheel.util.transform.TransformStack; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.foundation.utility.AngleHelper; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelItem.java b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelItem.java index 5fb2741b5..106c2a608 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelItem.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelItem.java @@ -4,6 +4,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.relays.belt.BeltHelper; import com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity; import com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity.CasingType; + import net.minecraft.core.BlockPos; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.BlockItem; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BrassTunnelCTBehaviour.java b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BrassTunnelCTBehaviour.java index 03ff7c696..a903c7497 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BrassTunnelCTBehaviour.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BrassTunnelCTBehaviour.java @@ -1,19 +1,22 @@ package com.simibubi.create.content.logistics.block.belts.tunnel; +import org.jetbrains.annotations.Nullable; + import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry; import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -public class BrassTunnelCTBehaviour extends ConnectedTextureBehaviour { +public class BrassTunnelCTBehaviour extends ConnectedTextureBehaviour.Base { @Override - public CTSpriteShiftEntry get(BlockState state, Direction direction) { + public CTSpriteShiftEntry getShift(BlockState state, Direction direction, @Nullable TextureAtlasSprite sprite) { return direction == Direction.UP ? AllSpriteShifts.BRASS_TUNNEL_TOP : null; } @@ -33,24 +36,4 @@ public class BrassTunnelCTBehaviour extends ConnectedTextureBehaviour { return tunnelTE.isConnected(leftSide); } - @Override - public CTContext buildContext(BlockAndTintGetter reader, BlockPos pos, BlockState state, Direction face) { - return super.buildContext(reader, pos, state, face); - } - - @Override - protected boolean reverseUVs(BlockState state, Direction face) { - return super.reverseUVs(state, face); - } - - @Override - protected boolean reverseUVsHorizontally(BlockState state, Direction face) { - return super.reverseUVsHorizontally(state, face); - } - - @Override - protected boolean reverseUVsVertically(BlockState state, Direction face) { - return super.reverseUVsVertically(state, face); - } - } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/vault/ItemVaultCTBehaviour.java b/src/main/java/com/simibubi/create/content/logistics/block/vault/ItemVaultCTBehaviour.java index d2ae059e8..808876277 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/vault/ItemVaultCTBehaviour.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/vault/ItemVaultCTBehaviour.java @@ -1,10 +1,13 @@ package com.simibubi.create.content.logistics.block.vault; +import org.jetbrains.annotations.Nullable; + import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.api.connectivity.ConnectivityHandler; import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry; import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; @@ -12,10 +15,10 @@ import net.minecraft.core.Direction.AxisDirection; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; -public class ItemVaultCTBehaviour extends ConnectedTextureBehaviour { +public class ItemVaultCTBehaviour extends ConnectedTextureBehaviour.Base { @Override - public CTSpriteShiftEntry get(BlockState state, Direction direction) { + public CTSpriteShiftEntry getShift(BlockState state, Direction direction, @Nullable TextureAtlasSprite sprite) { Axis vaultBlockAxis = ItemVaultBlock.getVaultBlockAxis(state); boolean small = !ItemVaultBlock.isLarge(state); if (vaultBlockAxis == null) diff --git a/src/main/java/com/simibubi/create/content/palettes/AllPaletteBlocks.java b/src/main/java/com/simibubi/create/content/palettes/AllPaletteBlocks.java index bf91cfb1f..228a820b4 100644 --- a/src/main/java/com/simibubi/create/content/palettes/AllPaletteBlocks.java +++ b/src/main/java/com/simibubi/create/content/palettes/AllPaletteBlocks.java @@ -11,7 +11,7 @@ import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.Create; import com.simibubi.create.content.AllSections; import com.simibubi.create.foundation.block.connected.HorizontalCTBehaviour; -import com.simibubi.create.foundation.block.connected.StandardCTBehaviour; +import com.simibubi.create.foundation.block.connected.SimpleCTBehaviour; import com.simibubi.create.foundation.data.BlockStateGen; import com.simibubi.create.foundation.data.CreateRegistrate; import com.simibubi.create.foundation.data.WindowGen; @@ -48,7 +48,7 @@ public class AllPaletteBlocks { .register(); public static final BlockEntry FRAMED_GLASS = - framedGlass("framed_glass", () -> new StandardCTBehaviour(AllSpriteShifts.FRAMED_GLASS)), + framedGlass("framed_glass", () -> new SimpleCTBehaviour(AllSpriteShifts.FRAMED_GLASS)), HORIZONTAL_FRAMED_GLASS = framedGlass("horizontal_framed_glass", () -> new HorizontalCTBehaviour(AllSpriteShifts.HORIZONTAL_FRAMED_GLASS, AllSpriteShifts.FRAMED_GLASS)), VERTICAL_FRAMED_GLASS = framedGlass("vertical_framed_glass", diff --git a/src/main/java/com/simibubi/create/content/palettes/ConnectedOreCTBehaviour.java b/src/main/java/com/simibubi/create/content/palettes/ConnectedOreCTBehaviour.java deleted file mode 100644 index 890973dac..000000000 --- a/src/main/java/com/simibubi/create/content/palettes/ConnectedOreCTBehaviour.java +++ /dev/null @@ -1,139 +0,0 @@ -package com.simibubi.create.content.palettes; - -import java.util.Map; - -import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry; -import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.properties.BooleanProperty; - -public class ConnectedOreCTBehaviour extends ConnectedTextureBehaviour { - - private CTSpriteShiftEntry entry; - - public ConnectedOreCTBehaviour(CTSpriteShiftEntry entry) { - this.entry = entry; - } - - @Override - public boolean connectsTo(BlockState state, BlockState other, BlockAndTintGetter reader, BlockPos pos, - BlockPos otherPos, Direction face, Direction primaryOffset, Direction secondaryOffset) { - - if (state.getBlock() instanceof ConnectedSixwayBlock) - return true; - - ConnectedSixwayBlock block = (ConnectedSixwayBlock) state.getBlock(); - Map props = ConnectedSixwayBlock.PROPERTY_BY_DIRECTION; - BooleanProperty faceProp = props.get(face); - - // Diagonal Connection - if (secondaryOffset != null && primaryOffset != null) { - BooleanProperty primaryProp = props.get(primaryOffset); - BooleanProperty secondaryProp = props.get(secondaryOffset); - BooleanProperty primaryOppositeProp = props.get(primaryOffset.getOpposite()); - BooleanProperty secondaryOppositeProp = props.get(secondaryOffset.getOpposite()); - BooleanProperty faceOppositeProp = props.get(face.getOpposite()); - - BlockState adjAbove1 = reader.getBlockState(pos.relative(primaryOffset) - .relative(face)); - BlockState adjAbove2 = reader.getBlockState(pos.relative(secondaryOffset) - .relative(face)); - - boolean adjAbove1Connects = block.connectsToState(adjAbove1); - boolean adjAbove2Connects = block.connectsToState(adjAbove2); - - if (adjAbove1Connects && adjAbove2Connects) - return true; - - if (isBeingBlocked(state, reader, pos, otherPos, face)) - return false; - if (adjAbove1Connects && !(adjAbove1.getValue(secondaryProp))) - return false; - if (adjAbove2Connects && !(adjAbove2.getValue(primaryProp))) - return false; - - BlockState diagAbove = reader.getBlockState(pos.relative(primaryOffset) - .relative(secondaryOffset) - .relative(face)); - boolean diagAboveConnects = block.connectsToState(diagAbove); - if (diagAboveConnects - && (!diagAbove.getValue(primaryOppositeProp) || !diagAbove.getValue(secondaryOppositeProp))) - return false; - - BlockState diagSameY = reader.getBlockState(pos.relative(primaryOffset) - .relative(secondaryOffset)); - boolean diagSameYConnects = block.connectsToState(diagSameY); - - BlockState adj1 = reader.getBlockState(pos.relative(primaryOffset)); - BlockState adj2 = reader.getBlockState(pos.relative(secondaryOffset)); - - boolean adj1Connects = block.connectsToState(adj1); - boolean adj2Connects = block.connectsToState(adj2); - boolean coveredDiag = diagAboveConnects || diagSameYConnects; - boolean covered1 = adj1Connects || adjAbove1Connects; - boolean covered2 = adj2Connects || adjAbove2Connects; - boolean fullCover = covered1 && covered2 && coveredDiag; - - if (!fullCover && block.disconnectsFromState(diagSameY)) - return false; - if (!fullCover && diagAboveConnects && !diagAbove.getValue(faceOppositeProp)) - return false; - if (!(fullCover || diagSameYConnects) && adjAbove1Connects && !adjAbove1.getValue(faceOppositeProp)) - return false; - if (!(fullCover || diagSameYConnects) && adjAbove2Connects && !adjAbove2.getValue(faceOppositeProp)) - return false; - - if (diagSameYConnects) - return diagSameY.getValue(faceProp) && (adjAbove1Connects || diagSameY.getValue(secondaryOppositeProp)) - && (adjAbove2Connects || diagSameY.getValue(primaryOppositeProp)); - - if (!fullCover && adj1Connects && !adj1.getValue(secondaryProp)) - return false; - if (!fullCover && adj2Connects && !adj2.getValue(primaryProp)) - return false; - if (!fullCover && !state.getValue(primaryProp)) - return false; - if (!fullCover && !state.getValue(secondaryProp)) - return false; - - return true; - } - - // Orthogonal Connection - else if (secondaryOffset != null || primaryOffset != null) { - - if (isBeingBlocked(state, reader, pos, otherPos, face)) - return false; - - Direction offset = secondaryOffset == null ? primaryOffset : secondaryOffset; - BlockState checkedState = reader.getBlockState(pos.relative(offset) - .relative(face)); - if (block.connectsToState(checkedState)) - return checkedState.getValue(props.get(offset.getOpposite())); - checkedState = reader.getBlockState(pos.relative(offset)); - if (block.connectsToState(checkedState)) - return checkedState.getValue(faceProp); - return state.getValue(props.get(offset)); - } - - return false; - } - - @Override - protected boolean isBeingBlocked(BlockState state, BlockAndTintGetter reader, BlockPos pos, BlockPos otherPos, - Direction face) { - ConnectedSixwayBlock block = (ConnectedSixwayBlock) state.getBlock(); - BlockState blockingState = reader.getBlockState(otherPos.relative(face)); - return block.disconnectsFromState(blockingState); - } - - @Override - public CTSpriteShiftEntry get(BlockState state, Direction direction) { - return state.getValue(ConnectedSixwayBlock.PROPERTY_BY_DIRECTION.get(direction)) ? entry : null; - } - -} diff --git a/src/main/java/com/simibubi/create/content/palettes/ConnectedSixwayBlock.java b/src/main/java/com/simibubi/create/content/palettes/ConnectedSixwayBlock.java deleted file mode 100644 index b420308c3..000000000 --- a/src/main/java/com/simibubi/create/content/palettes/ConnectedSixwayBlock.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.simibubi.create.content.palettes; - -import net.minecraft.world.level.block.PipeBlock; -import net.minecraft.world.level.block.state.BlockState; - -public class ConnectedSixwayBlock extends PipeBlock { - - public ConnectedSixwayBlock(float p_55159_, Properties p_55160_) { - super(p_55159_, p_55160_); - } - - public boolean disconnectsFromState(BlockState blockingState) { - return false; - } - - public boolean connectsToState(BlockState adjAbove1) { - return false; - } - - - -} diff --git a/src/main/java/com/simibubi/create/content/palettes/PaletteBlockPattern.java b/src/main/java/com/simibubi/create/content/palettes/PaletteBlockPattern.java index 2c80a9a02..00e02d172 100644 --- a/src/main/java/com/simibubi/create/content/palettes/PaletteBlockPattern.java +++ b/src/main/java/com/simibubi/create/content/palettes/PaletteBlockPattern.java @@ -11,9 +11,10 @@ import java.util.function.Function; import java.util.function.Supplier; import com.simibubi.create.Create; +import com.simibubi.create.foundation.block.connected.AllCTTypes; import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry; import com.simibubi.create.foundation.block.connected.CTSpriteShifter; -import com.simibubi.create.foundation.block.connected.CTSpriteShifter.CTType; +import com.simibubi.create.foundation.block.connected.CTType; import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour; import com.simibubi.create.foundation.block.connected.HorizontalCTBehaviour; import com.simibubi.create.foundation.block.connected.RotatedPillarCTBehaviour; @@ -250,9 +251,9 @@ public class PaletteBlockPattern { public enum CTs { - PILLAR(CTType.RECTANGLE, s -> toLocation(s, "pillar")), - CAP(CTType.OMNIDIRECTIONAL, s -> toLocation(s, "cap")), - LAYERED(CTType.HORIZONTAL_KRYPPERS, s -> toLocation(s, "layered")) + PILLAR(AllCTTypes.RECTANGLE, s -> toLocation(s, "pillar")), + CAP(AllCTTypes.OMNIDIRECTIONAL, s -> toLocation(s, "cap")), + LAYERED(AllCTTypes.HORIZONTAL_KRYPPERS, s -> toLocation(s, "layered")) ; diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/AllCTTypes.java b/src/main/java/com/simibubi/create/foundation/block/connected/AllCTTypes.java new file mode 100644 index 000000000..c0bec9a52 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/block/connected/AllCTTypes.java @@ -0,0 +1,133 @@ +package com.simibubi.create.foundation.block.connected; + +import com.simibubi.create.Create; +import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour.CTContext; +import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour.ContextRequirement; +import com.simibubi.create.foundation.utility.Lang; + +import net.minecraft.resources.ResourceLocation; + +public enum AllCTTypes implements CTType { + HORIZONTAL(2, ContextRequirement.builder().horizontal().build()) { + @Override + public int getTextureIndex(CTContext context) { + return (context.right ? 1 : 0) + (context.left ? 2 : 0); + } + }, + HORIZONTAL_KRYPPERS(2, ContextRequirement.builder().horizontal().build()) { + @Override + public int getTextureIndex(CTContext context) { + return !context.right && !context.left ? 0 : !context.right ? 3 : !context.left ? 2 : 1; + } + }, + VERTICAL(2, ContextRequirement.builder().vertical().build()) { + @Override + public int getTextureIndex(CTContext context) { + return (context.up ? 1 : 0) + (context.down ? 2 : 0); + } + }, + OMNIDIRECTIONAL(8, ContextRequirement.builder().all().build()) { + @Override + public int getTextureIndex(CTContext context) { + CTContext c = context; + int tileX = 0, tileY = 0; + int borders = (!c.up ? 1 : 0) + (!c.down ? 1 : 0) + (!c.left ? 1 : 0) + (!c.right ? 1 : 0); + + if (c.up) + tileX++; + if (c.down) + tileX += 2; + if (c.left) + tileY++; + if (c.right) + tileY += 2; + + if (borders == 0) { + if (c.topRight) + tileX++; + if (c.topLeft) + tileX += 2; + if (c.bottomRight) + tileY += 2; + if (c.bottomLeft) + tileY++; + } + + if (borders == 1) { + if (!c.right) { + if (c.topLeft || c.bottomLeft) { + tileY = 4; + tileX = -1 + (c.bottomLeft ? 1 : 0) + (c.topLeft ? 1 : 0) * 2; + } + } + if (!c.left) { + if (c.topRight || c.bottomRight) { + tileY = 5; + tileX = -1 + (c.bottomRight ? 1 : 0) + (c.topRight ? 1 : 0) * 2; + } + } + if (!c.down) { + if (c.topLeft || c.topRight) { + tileY = 6; + tileX = -1 + (c.topLeft ? 1 : 0) + (c.topRight ? 1 : 0) * 2; + } + } + if (!c.up) { + if (c.bottomLeft || c.bottomRight) { + tileY = 7; + tileX = -1 + (c.bottomLeft ? 1 : 0) + (c.bottomRight ? 1 : 0) * 2; + } + } + } + + if (borders == 2) { + if ((c.up && c.left && c.topLeft) || (c.down && c.left && c.bottomLeft) + || (c.up && c.right && c.topRight) || (c.down && c.right && c.bottomRight)) + tileX += 3; + } + + return tileX + 8 * tileY; + } + }, + CROSS(4, ContextRequirement.builder().axisAligned().build()) { + @Override + public int getTextureIndex(CTContext context) { + return (context.up ? 1 : 0) + (context.down ? 2 : 0) + (context.left ? 4 : 0) + (context.right ? 8 : 0); + } + }, + RECTANGLE(4, ContextRequirement.builder().axisAligned().build()) { + @Override + public int getTextureIndex(CTContext context) { + int x = context.left && context.right ? 2 : context.left ? 3 : context.right ? 1 : 0; + int y = context.up && context.down ? 1 : context.up ? 2 : context.down ? 0 : 3; + return x + y * 4; + } + }; + + private final ResourceLocation id; + private final int sheetSize; + private final ContextRequirement contextRequirement; + + AllCTTypes(int sheetSize, ContextRequirement contextRequirement) { + this.id = Create.asResource(Lang.asId(name())); + this.sheetSize = sheetSize; + this.contextRequirement = contextRequirement; + + CTTypeRegistry.register(this); + } + + @Override + public ResourceLocation getId() { + return id; + } + + @Override + public int getSheetSize() { + return sheetSize; + } + + @Override + public ContextRequirement getContextRequirement() { + return contextRequirement; + } +} 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 82dec5065..4dd338b18 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 @@ -5,8 +5,6 @@ import java.util.Arrays; import java.util.List; import java.util.Random; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.VertexFormat; import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour.CTContext; import com.simibubi.create.foundation.block.render.QuadHelper; import com.simibubi.create.foundation.utility.Iterate; @@ -14,6 +12,7 @@ import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.BlockPos; +import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.Block; @@ -24,25 +23,9 @@ import net.minecraftforge.client.model.data.ModelProperty; public class CTModel extends BakedModelWrapperWithData { - protected static final ModelProperty CT_PROPERTY = new ModelProperty<>(); - private ConnectedTextureBehaviour behaviour; + private static final ModelProperty CT_PROPERTY = new ModelProperty<>(); - private class CTData { - int[] indices; - - public CTData() { - indices = new int[6]; - Arrays.fill(indices, -1); - } - - void put(Direction face, int texture) { - indices[face.get3DDataValue()] = texture; - } - - int get(Direction face) { - return indices[face.get3DDataValue()]; - } - } + private final ConnectedTextureBehaviour behaviour; public CTModel(BakedModel originalModel, ConnectedTextureBehaviour behaviour) { super(originalModel); @@ -56,15 +39,16 @@ public class CTModel extends BakedModelWrapperWithData { protected CTData createCTData(BlockAndTintGetter world, BlockPos pos, BlockState state) { CTData data = new CTData(); + MutableBlockPos mutablePos = new MutableBlockPos(); for (Direction face : Iterate.directions) { - if (!Block.shouldRenderFace(state, world, pos, face, pos.relative(face)) - && !behaviour.buildContextForOccludedDirections()) + if (!behaviour.buildContextForOccludedDirections() + && !Block.shouldRenderFace(state, world, pos, face, mutablePos.setWithOffset(pos, face))) continue; - CTSpriteShiftEntry spriteShift = behaviour.get(state, face); - if (spriteShift == null) + CTType dataType = behaviour.getDataType(state, face); + if (dataType == null) continue; - CTContext ctContext = behaviour.buildContext(world, pos, state, face); - data.put(face, spriteShift.getTextureIndex(ctContext)); + CTContext context = behaviour.buildContext(world, pos, state, face, dataType.getContextRequirement()); + data.put(face, dataType.getTextureIndex(context)); } return data; } @@ -74,39 +58,54 @@ public class CTModel extends BakedModelWrapperWithData { List quads = super.getQuads(state, side, rand, extraData); if (!extraData.hasProperty(CT_PROPERTY)) return quads; + CTData data = extraData.getData(CT_PROPERTY); quads = new ArrayList<>(quads); - VertexFormat format = DefaultVertexFormat.BLOCK; - for (int i = 0; i < quads.size(); i++) { BakedQuad quad = quads.get(i); - CTSpriteShiftEntry spriteShift = behaviour.get(state, quad.getDirection(), quad.getSprite()); + int index = data.get(quad.getDirection()); + if (index == -1) + continue; + + CTSpriteShiftEntry spriteShift = behaviour.getShift(state, quad.getDirection(), quad.getSprite()); if (spriteShift == null) continue; if (quad.getSprite() != spriteShift.getOriginal()) continue; - int index = data.get(quad.getDirection()); - if (index == -1) - continue; BakedQuad newQuad = QuadHelper.clone(quad); int[] vertexData = newQuad.getVertices(); - for (int vertex = 0; vertex < vertexData.length; vertex += format.getIntegerSize()) { - int uvOffset = 16 / 4; - int uIndex = vertex + uvOffset; - int vIndex = vertex + uvOffset + 1; - float u = Float.intBitsToFloat(vertexData[uIndex]); - float v = Float.intBitsToFloat(vertexData[vIndex]); - vertexData[uIndex] = Float.floatToRawIntBits(spriteShift.getTargetU(u, index)); - vertexData[vIndex] = Float.floatToRawIntBits(spriteShift.getTargetV(v, index)); + 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)); } quads.set(i, newQuad); } + return quads; } + private static class CTData { + private final int[] indices; + + public CTData() { + indices = new int[6]; + Arrays.fill(indices, -1); + } + + public void put(Direction face, int texture) { + indices[face.get3DDataValue()] = texture; + } + + public int get(Direction face) { + return indices[face.get3DDataValue()]; + } + } + } 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 4b75e7c48..eea270bc4 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 @@ -1,188 +1,29 @@ package com.simibubi.create.foundation.block.connected; -import com.simibubi.create.foundation.block.connected.CTSpriteShifter.CTType; -import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour.CTContext; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.render.SuperByteBuffer; -public abstract class CTSpriteShiftEntry extends SpriteShiftEntry { +public class CTSpriteShiftEntry extends SpriteShiftEntry { - protected int textureSheetSize; + protected final CTType type; - public CTSpriteShiftEntry(int sheetSize) { - this.textureSheetSize = sheetSize; + public CTSpriteShiftEntry(CTType type) { + this.type = type; + } + + public CTType getType() { + return type; } public float getTargetU(float localU, int index) { - float uOffset = (index % textureSheetSize); + float uOffset = (index % type.getSheetSize()); return getTarget().getU( - (SuperByteBuffer.getUnInterpolatedU(getOriginal(), localU) + (uOffset * 16)) / ((float) textureSheetSize)); + (getUnInterpolatedU(getOriginal(), localU) + (uOffset * 16)) / ((float) type.getSheetSize())); } public float getTargetV(float localV, int index) { - float vOffset = (index / textureSheetSize); + float vOffset = (index / type.getSheetSize()); return getTarget().getV( - (SuperByteBuffer.getUnInterpolatedV(getOriginal(), localV) + (vOffset * 16)) / ((float) textureSheetSize)); - } - - public abstract int getTextureIndex(CTContext context); - - public abstract CTType getType(); - - public static class Horizontal extends CTSpriteShiftEntry { - - // Different sheet arrangement - private boolean kryppers; - - public Horizontal(boolean kryppers) { - super(2); - this.kryppers = kryppers; - } - - @Override - public int getTextureIndex(CTContext context) { - if (kryppers) - return !context.right && !context.left ? 0 : !context.right ? 3 : !context.left ? 2 : 1; - return (context.right ? 1 : 0) + (context.left ? 2 : 0); - } - - @Override - public CTType getType() { - return CTType.HORIZONTAL; - } - - } - - public static class Vertical extends CTSpriteShiftEntry { - - public Vertical() { - super(2); - } - - @Override - public int getTextureIndex(CTContext context) { - return (context.up ? 1 : 0) + (context.down ? 2 : 0); - } - - @Override - public CTType getType() { - return CTType.VERTICAL; - } - - } - - public static class Cross extends CTSpriteShiftEntry { - - public Cross() { - super(4); - } - - @Override - public int getTextureIndex(CTContext context) { - return (context.up ? 1 : 0) + (context.down ? 2 : 0) + (context.left ? 4 : 0) + (context.right ? 8 : 0); - } - - @Override - public CTType getType() { - return CTType.CROSS; - } - - } - - // Same as cross with different sheet arrangement - public static class Rect extends CTSpriteShiftEntry { - - public Rect() { - super(4); - } - - @Override - public int getTextureIndex(CTContext context) { - int x = context.left && context.right ? 2 : context.left ? 3 : context.right ? 1 : 0; - int y = context.up && context.down ? 1 : context.up ? 2 : context.down ? 0 : 3; - return x + y * 4; - } - - @Override - public CTType getType() { - return CTType.RECTANGLE; - } - - } - - public static class Omnidirectional extends CTSpriteShiftEntry { - - public Omnidirectional() { - super(8); - } - - @Override - public int getTextureIndex(CTContext context) { - CTContext c = context; - int tileX = 0, tileY = 0; - int borders = (!c.up ? 1 : 0) + (!c.down ? 1 : 0) + (!c.left ? 1 : 0) + (!c.right ? 1 : 0); - - if (c.up) - tileX++; - if (c.down) - tileX += 2; - if (c.left) - tileY++; - if (c.right) - tileY += 2; - - if (borders == 0) { - if (c.topRight) - tileX++; - if (c.topLeft) - tileX += 2; - if (c.bottomRight) - tileY += 2; - if (c.bottomLeft) - tileY++; - } - - if (borders == 1) { - if (!c.right) { - if (c.topLeft || c.bottomLeft) { - tileY = 4; - tileX = -1 + (c.bottomLeft ? 1 : 0) + (c.topLeft ? 1 : 0) * 2; - } - } - if (!c.left) { - if (c.topRight || c.bottomRight) { - tileY = 5; - tileX = -1 + (c.bottomRight ? 1 : 0) + (c.topRight ? 1 : 0) * 2; - } - } - if (!c.down) { - if (c.topLeft || c.topRight) { - tileY = 6; - tileX = -1 + (c.topLeft ? 1 : 0) + (c.topRight ? 1 : 0) * 2; - } - } - if (!c.up) { - if (c.bottomLeft || c.bottomRight) { - tileY = 7; - tileX = -1 + (c.bottomLeft ? 1 : 0) + (c.bottomRight ? 1 : 0) * 2; - } - } - } - - if (borders == 2) { - if ((c.up && c.left && c.topLeft) || (c.down && c.left && c.bottomLeft) - || (c.up && c.right && c.topRight) || (c.down && c.right && c.bottomRight)) - tileX += 3; - } - - return tileX + 8 * tileY; - } - - @Override - public CTType getType() { - return CTType.OMNIDIRECTIONAL; - } - + (getUnInterpolatedV(getOriginal(), localV) + (vOffset * 16)) / ((float) type.getSheetSize())); } } diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/CTSpriteShifter.java b/src/main/java/com/simibubi/create/foundation/block/connected/CTSpriteShifter.java index e660b1d65..e3c61883c 100644 --- a/src/main/java/com/simibubi/create/foundation/block/connected/CTSpriteShifter.java +++ b/src/main/java/com/simibubi/create/foundation/block/connected/CTSpriteShifter.java @@ -1,52 +1,25 @@ package com.simibubi.create.foundation.block.connected; -import com.simibubi.create.Create; -import com.simibubi.create.foundation.block.render.SpriteShifter; +import java.util.HashMap; +import java.util.Map; + +import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import net.minecraft.resources.ResourceLocation; -public class CTSpriteShifter extends SpriteShifter { +public class CTSpriteShifter { + + private static final Map ENTRY_CACHE = new HashMap<>(); public static CTSpriteShiftEntry getCT(CTType type, ResourceLocation blockTexture, ResourceLocation connectedTexture) { - String key = type.name() + ":" + blockTexture + "->" + connectedTexture; + String key = blockTexture + "->" + connectedTexture + "+" + type.getId(); if (ENTRY_CACHE.containsKey(key)) return (CTSpriteShiftEntry) ENTRY_CACHE.get(key); - CTSpriteShiftEntry entry = create(type); + CTSpriteShiftEntry entry = new CTSpriteShiftEntry(type); entry.set(blockTexture, connectedTexture); ENTRY_CACHE.put(key, entry); return entry; } - public static CTSpriteShiftEntry getCT(CTType type, String blockTextureName, String connectedTextureName) { - return getCT(type, Create.asResource("block/" + blockTextureName), Create.asResource("block/" + connectedTextureName + "_connected")); - } - - public static CTSpriteShiftEntry getCT(CTType type, String blockTextureName) { - return getCT(type, blockTextureName, blockTextureName); - } - - private static CTSpriteShiftEntry create(CTType type) { - switch (type) { - case HORIZONTAL: - return new CTSpriteShiftEntry.Horizontal(false); - case HORIZONTAL_KRYPPERS: - return new CTSpriteShiftEntry.Horizontal(true); - case OMNIDIRECTIONAL: - return new CTSpriteShiftEntry.Omnidirectional(); - case VERTICAL: - return new CTSpriteShiftEntry.Vertical(); - case CROSS: - return new CTSpriteShiftEntry.Cross(); - case RECTANGLE: - return new CTSpriteShiftEntry.Rect(); - default: - return null; - } - } - - public enum CTType { - OMNIDIRECTIONAL, HORIZONTAL, VERTICAL, CROSS, RECTANGLE, HORIZONTAL_KRYPPERS; - } - } diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/CTType.java b/src/main/java/com/simibubi/create/foundation/block/connected/CTType.java new file mode 100644 index 000000000..b51a7ad28 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/block/connected/CTType.java @@ -0,0 +1,16 @@ +package com.simibubi.create.foundation.block.connected; + +import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour.CTContext; +import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour.ContextRequirement; + +import net.minecraft.resources.ResourceLocation; + +public interface CTType { + ResourceLocation getId(); + + int getSheetSize(); + + ContextRequirement getContextRequirement(); + + int getTextureIndex(CTContext context); +} diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/CTTypeRegistry.java b/src/main/java/com/simibubi/create/foundation/block/connected/CTTypeRegistry.java new file mode 100644 index 000000000..8219b2d45 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/block/connected/CTTypeRegistry.java @@ -0,0 +1,24 @@ +package com.simibubi.create.foundation.block.connected; + +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.Nullable; + +import net.minecraft.resources.ResourceLocation; + +public class CTTypeRegistry { + private static final Map TYPES = new HashMap<>(); + + public static void register(CTType type) { + ResourceLocation id = type.getId(); + if (TYPES.containsKey(id)) + throw new IllegalArgumentException("Tried to override CTType registration for id '" + id + "'. This is not supported!"); + TYPES.put(id, type); + } + + @Nullable + public static CTType get(ResourceLocation id) { + return TYPES.get(id); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/ConnectedTextureBehaviour.java b/src/main/java/com/simibubi/create/foundation/block/connected/ConnectedTextureBehaviour.java index 40324a23d..906273a80 100644 --- a/src/main/java/com/simibubi/create/foundation/block/connected/ConnectedTextureBehaviour.java +++ b/src/main/java/com/simibubi/create/foundation/block/connected/ConnectedTextureBehaviour.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation.block.connected; -import com.simibubi.create.foundation.block.connected.CTSpriteShifter.CTType; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; @@ -12,17 +13,44 @@ import net.minecraft.world.level.block.state.BlockState; public abstract class ConnectedTextureBehaviour { - public class CTContext { - boolean up, down, left, right; - boolean topLeft, topRight, bottomLeft, bottomRight; + @Nullable + public abstract CTSpriteShiftEntry getShift(BlockState state, Direction direction, @NotNull TextureAtlasSprite sprite); + + // TODO: allow more than one data type per state/face? + @Nullable + public abstract CTType getDataType(BlockState state, Direction direction); + + public boolean buildContextForOccludedDirections() { + return false; } - public CTSpriteShiftEntry get(BlockState state, Direction direction, TextureAtlasSprite sprite) { - return get(state, direction); + protected boolean isBeingBlocked(BlockState state, BlockAndTintGetter reader, BlockPos pos, BlockPos otherPos, + Direction face) { + BlockPos blockingPos = otherPos.relative(face); + return face.getAxis() + .choose(pos.getX(), pos.getY(), pos.getZ()) == face.getAxis() + .choose(otherPos.getX(), otherPos.getY(), otherPos.getZ()) + && connectsTo(state, reader.getBlockState(blockingPos), reader, pos, blockingPos, face); } - - public CTSpriteShiftEntry get(BlockState state, Direction direction) { - return null; + + public boolean connectsTo(BlockState state, BlockState other, BlockAndTintGetter reader, BlockPos pos, + BlockPos otherPos, Direction face, Direction primaryOffset, Direction secondaryOffset) { + return connectsTo(state, other, reader, pos, otherPos, face); + } + + public boolean connectsTo(BlockState state, BlockState other, BlockAndTintGetter reader, BlockPos pos, + BlockPos otherPos, Direction face) { + return !isBeingBlocked(state, reader, pos, otherPos, face) && state.getBlock() == other.getBlock(); + } + + private boolean testConnection(BlockAndTintGetter reader, BlockPos pos, BlockState state, Direction face, + final Direction horizontal, final Direction vertical, int sh, int sv) { + BlockPos p = pos.relative(horizontal, sh) + .relative(vertical, sv); + boolean test = connectsTo(state, reader.getBlockState(p), reader, pos, p, face, + sh == 0 ? null : sh == -1 ? horizontal.getOpposite() : horizontal, + sv == 0 ? null : sv == -1 ? vertical.getOpposite() : vertical); + return test; } protected boolean reverseUVs(BlockState state, Direction face) { @@ -37,36 +65,17 @@ public abstract class ConnectedTextureBehaviour { return reverseUVs(state, face); } - public boolean buildContextForOccludedDirections() { - return false; + protected Direction getUpDirection(BlockAndTintGetter reader, BlockPos pos, BlockState state, Direction face) { + Axis axis = face.getAxis(); + return axis.isHorizontal() ? Direction.UP : Direction.NORTH; } - public boolean connectsTo(BlockState state, BlockState other, BlockAndTintGetter reader, BlockPos pos, - BlockPos otherPos, Direction face, Direction primaryOffset, Direction secondaryOffset) { - return connectsTo(state, other, reader, pos, otherPos, face); + protected Direction getRightDirection(BlockAndTintGetter reader, BlockPos pos, BlockState state, Direction face) { + Axis axis = face.getAxis(); + return axis == Axis.X ? Direction.SOUTH : Direction.WEST; } - public boolean connectsTo(BlockState state, BlockState other, BlockAndTintGetter reader, BlockPos pos, - BlockPos otherPos, Direction face) { - return !isBeingBlocked(state, reader, pos, otherPos, face) && state.getBlock() == other.getBlock(); - } - - protected boolean isBeingBlocked(BlockState state, BlockAndTintGetter reader, BlockPos pos, BlockPos otherPos, - Direction face) { - BlockPos blockingPos = otherPos.relative(face); - return face.getAxis() - .choose(pos.getX(), pos.getY(), pos.getZ()) == face.getAxis() - .choose(otherPos.getX(), otherPos.getY(), otherPos.getZ()) - && connectsTo(state, reader.getBlockState(blockingPos), reader, pos, blockingPos, face); - } - - public CTContext buildContext(BlockAndTintGetter reader, BlockPos pos, BlockState state, Direction face) { - CTContext context = new CTContext(); - CTSpriteShiftEntry textureEntry = get(state, face); - - if (textureEntry == null) - return context; - + public CTContext buildContext(BlockAndTintGetter reader, BlockPos pos, BlockState state, Direction face, ContextRequirement requirement) { boolean positive = face.getAxisDirection() == AxisDirection.POSITIVE; Direction h = getRightDirection(reader, pos, state, face); Direction v = getUpDirection(reader, pos, state, face); @@ -84,25 +93,34 @@ public abstract class ConnectedTextureBehaviour { int sh = flipH ? -1 : 1; int sv = flipV ? -1 : 1; - CTType type = textureEntry.getType(); + CTContext context = new CTContext(); - if (type != CTType.HORIZONTAL) { + if (requirement.up) { context.up = testConnection(reader, pos, state, face, horizontal, vertical, 0, sv); + } + if (requirement.down) { context.down = testConnection(reader, pos, state, face, horizontal, vertical, 0, -sv); } - - if (type != CTType.VERTICAL) { + if (requirement.left) { context.left = testConnection(reader, pos, state, face, horizontal, vertical, -sh, 0); + } + if (requirement.right) { context.right = testConnection(reader, pos, state, face, horizontal, vertical, sh, 0); } - if (type == CTType.OMNIDIRECTIONAL) { + if (requirement.topLeft) { context.topLeft = context.up && context.left && testConnection(reader, pos, state, face, horizontal, vertical, -sh, sv); + } + if (requirement.topRight) { context.topRight = context.up && context.right && testConnection(reader, pos, state, face, horizontal, vertical, sh, sv); + } + if (requirement.bottomLeft) { context.bottomLeft = context.down && context.left && testConnection(reader, pos, state, face, horizontal, vertical, -sh, -sv); + } + if (requirement.bottomRight) { context.bottomRight = context.down && context.right && testConnection(reader, pos, state, face, horizontal, vertical, sh, -sv); } @@ -110,24 +128,128 @@ public abstract class ConnectedTextureBehaviour { return context; } - protected Direction getUpDirection(BlockAndTintGetter reader, BlockPos pos, BlockState state, Direction face) { - Axis axis = face.getAxis(); - return axis.isHorizontal() ? Direction.UP : Direction.NORTH; + public static class CTContext { + public static final CTContext EMPTY = new CTContext(); + + public boolean up, down, left, right; + public boolean topLeft, topRight, bottomLeft, bottomRight; } - protected Direction getRightDirection(BlockAndTintGetter reader, BlockPos pos, BlockState state, Direction face) { - Axis axis = face.getAxis(); - return axis == Axis.X ? Direction.SOUTH : Direction.WEST; + public static class ContextRequirement { + public final boolean up, down, left, right; + public final boolean topLeft, topRight, bottomLeft, bottomRight; + + public ContextRequirement(boolean up, boolean down, boolean left, boolean right, boolean topLeft, boolean topRight, boolean bottomLeft, boolean bottomRight) { + this.up = up; + this.down = down; + this.left = left; + this.right = right; + this.topLeft = topLeft; + this.topRight = topRight; + this.bottomLeft = bottomLeft; + this.bottomRight = bottomRight; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private boolean up, down, left, right; + private boolean topLeft, topRight, bottomLeft, bottomRight; + + public Builder up() { + up = true; + return this; + } + + public Builder down() { + down = true; + return this; + } + + public Builder left() { + left = true; + return this; + } + + public Builder right() { + right = true; + return this; + } + + public Builder topLeft() { + topLeft = true; + return this; + } + + public Builder topRight() { + topRight = true; + return this; + } + + public Builder bottomLeft() { + bottomLeft = true; + return this; + } + + public Builder bottomRight() { + bottomRight = true; + return this; + } + + public Builder horizontal() { + left(); + right(); + return this; + } + + public Builder vertical() { + up(); + down(); + return this; + } + + public Builder axisAligned() { + horizontal(); + vertical(); + return this; + } + + public Builder corners() { + topLeft(); + topRight(); + bottomLeft(); + bottomRight(); + return this; + } + + public Builder all() { + axisAligned(); + corners(); + return this; + } + + public ContextRequirement build() { + return new ContextRequirement(up, down, left, right, topLeft, topRight, bottomLeft, bottomRight); + } + } } - private boolean testConnection(BlockAndTintGetter reader, BlockPos pos, BlockState state, Direction face, - final Direction horizontal, final Direction vertical, int sh, int sv) { - BlockPos p = pos.relative(horizontal, sh) - .relative(vertical, sv); - boolean test = connectsTo(state, reader.getBlockState(p), reader, pos, p, face, - sh == 0 ? null : sh == -1 ? horizontal.getOpposite() : horizontal, - sv == 0 ? null : sv == -1 ? vertical.getOpposite() : vertical); - return test; + public static abstract class Base extends ConnectedTextureBehaviour { + @Override + @Nullable + public abstract CTSpriteShiftEntry getShift(BlockState state, Direction direction, @Nullable TextureAtlasSprite sprite); + + @Override + @Nullable + public CTType getDataType(BlockState state, Direction direction) { + CTSpriteShiftEntry shift = getShift(state, direction, null); + if (shift == null) { + return null; + } + return shift.getType(); + } } } diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/GlassPaneCTBehaviour.java b/src/main/java/com/simibubi/create/foundation/block/connected/GlassPaneCTBehaviour.java index b31fea92f..5593aad72 100644 --- a/src/main/java/com/simibubi/create/foundation/block/connected/GlassPaneCTBehaviour.java +++ b/src/main/java/com/simibubi/create/foundation/block/connected/GlassPaneCTBehaviour.java @@ -6,7 +6,7 @@ import net.minecraft.core.Direction.AxisDirection; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; -public class GlassPaneCTBehaviour extends StandardCTBehaviour { +public class GlassPaneCTBehaviour extends SimpleCTBehaviour { public GlassPaneCTBehaviour(CTSpriteShiftEntry shift) { super(shift); diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/HorizontalCTBehaviour.java b/src/main/java/com/simibubi/create/foundation/block/connected/HorizontalCTBehaviour.java index 260ce8815..e40f2fb49 100644 --- a/src/main/java/com/simibubi/create/foundation/block/connected/HorizontalCTBehaviour.java +++ b/src/main/java/com/simibubi/create/foundation/block/connected/HorizontalCTBehaviour.java @@ -1,12 +1,15 @@ package com.simibubi.create.foundation.block.connected; +import org.jetbrains.annotations.Nullable; + +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.Direction; import net.minecraft.world.level.block.state.BlockState; -public class HorizontalCTBehaviour extends ConnectedTextureBehaviour { +public class HorizontalCTBehaviour extends ConnectedTextureBehaviour.Base { - CTSpriteShiftEntry topShift; - CTSpriteShiftEntry layerShift; + protected CTSpriteShiftEntry topShift; + protected CTSpriteShiftEntry layerShift; public HorizontalCTBehaviour(CTSpriteShiftEntry layerShift) { this(layerShift, null); @@ -18,7 +21,7 @@ public class HorizontalCTBehaviour extends ConnectedTextureBehaviour { } @Override - public CTSpriteShiftEntry get(BlockState state, Direction direction) { + public CTSpriteShiftEntry getShift(BlockState state, Direction direction, @Nullable TextureAtlasSprite sprite) { return direction.getAxis() .isHorizontal() ? layerShift : topShift; } diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/RotatedPillarCTBehaviour.java b/src/main/java/com/simibubi/create/foundation/block/connected/RotatedPillarCTBehaviour.java index bf069d3ce..55611e2bf 100644 --- a/src/main/java/com/simibubi/create/foundation/block/connected/RotatedPillarCTBehaviour.java +++ b/src/main/java/com/simibubi/create/foundation/block/connected/RotatedPillarCTBehaviour.java @@ -3,6 +3,7 @@ package com.simibubi.create.foundation.block.connected; import com.simibubi.create.content.palettes.ConnectedPillarBlock; import com.simibubi.create.content.palettes.LayeredBlock; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; @@ -100,9 +101,9 @@ public class RotatedPillarCTBehaviour extends HorizontalCTBehaviour { } @Override - public CTSpriteShiftEntry get(BlockState state, Direction direction) { - return super.get(state, - direction.getAxis() == state.getValue(LayeredBlock.AXIS) ? Direction.UP : Direction.SOUTH); + public CTSpriteShiftEntry getShift(BlockState state, Direction direction, TextureAtlasSprite sprite) { + return super.getShift(state, + direction.getAxis() == state.getValue(LayeredBlock.AXIS) ? Direction.UP : Direction.SOUTH, sprite); } } diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/SimpleCTBehaviour.java b/src/main/java/com/simibubi/create/foundation/block/connected/SimpleCTBehaviour.java new file mode 100644 index 000000000..dc763201b --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/block/connected/SimpleCTBehaviour.java @@ -0,0 +1,22 @@ +package com.simibubi.create.foundation.block.connected; + +import org.jetbrains.annotations.Nullable; + +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.core.Direction; +import net.minecraft.world.level.block.state.BlockState; + +public class SimpleCTBehaviour extends ConnectedTextureBehaviour.Base { + + protected CTSpriteShiftEntry shift; + + public SimpleCTBehaviour(CTSpriteShiftEntry shift) { + this.shift = shift; + } + + @Override + public CTSpriteShiftEntry getShift(BlockState state, Direction direction, @Nullable TextureAtlasSprite sprite) { + return shift; + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/StandardCTBehaviour.java b/src/main/java/com/simibubi/create/foundation/block/connected/StandardCTBehaviour.java deleted file mode 100644 index 693ccb5c1..000000000 --- a/src/main/java/com/simibubi/create/foundation/block/connected/StandardCTBehaviour.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.simibubi.create.foundation.block.connected; - -import net.minecraft.core.Direction; -import net.minecraft.world.level.block.state.BlockState; - -public class StandardCTBehaviour extends ConnectedTextureBehaviour { - - CTSpriteShiftEntry shift; - - public StandardCTBehaviour(CTSpriteShiftEntry shift) { - this.shift = shift; - } - - @Override - public CTSpriteShiftEntry get(BlockState state, Direction direction) { - return shift; - } - -} diff --git a/src/main/java/com/simibubi/create/foundation/block/render/QuadHelper.java b/src/main/java/com/simibubi/create/foundation/block/render/QuadHelper.java index c6ce5aa9a..8c59fccc3 100644 --- a/src/main/java/com/simibubi/create/foundation/block/render/QuadHelper.java +++ b/src/main/java/com/simibubi/create/foundation/block/render/QuadHelper.java @@ -2,10 +2,25 @@ package com.simibubi.create.foundation.block.render; import java.util.Arrays; +import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.VertexFormat; + import net.minecraft.client.renderer.block.model.BakedQuad; public final class QuadHelper { + public static final VertexFormat FORMAT = DefaultVertexFormat.BLOCK; + public static final int VERTEX_STRIDE = FORMAT.getIntegerSize(); + + public static final int X_OFFSET = 0; + public static final int Y_OFFSET = 1; + public static final int Z_OFFSET = 2; + public static final int COLOR_OFFSET = 3; + public static final int U_OFFSET = 4; + public static final int V_OFFSET = 5; + public static final int LIGHT_OFFSET = 6; + public static final int NORMAL_OFFSET = 7; + private QuadHelper() {} public static BakedQuad clone(BakedQuad quad) { @@ -13,4 +28,20 @@ public final class QuadHelper { quad.getTintIndex(), quad.getDirection(), quad.getSprite(), quad.isShade()); } + public static float getU(int[] vertexData, int vertex) { + return Float.intBitsToFloat(vertexData[vertex * VERTEX_STRIDE + U_OFFSET]); + } + + public static float getV(int[] vertexData, int vertex) { + return Float.intBitsToFloat(vertexData[vertex * VERTEX_STRIDE + V_OFFSET]); + } + + public static void setU(int[] vertexData, int vertex, float u) { + vertexData[vertex * VERTEX_STRIDE + U_OFFSET] = Float.floatToRawIntBits(u); + } + + public static void setV(int[] vertexData, int vertex, float v) { + vertexData[vertex * VERTEX_STRIDE + V_OFFSET] = Float.floatToRawIntBits(v); + } + } diff --git a/src/main/java/com/simibubi/create/foundation/block/render/SpriteShiftEntry.java b/src/main/java/com/simibubi/create/foundation/block/render/SpriteShiftEntry.java index c4efb9b35..537ff9d68 100644 --- a/src/main/java/com/simibubi/create/foundation/block/render/SpriteShiftEntry.java +++ b/src/main/java/com/simibubi/create/foundation/block/render/SpriteShiftEntry.java @@ -29,4 +29,22 @@ public class SpriteShiftEntry { public TextureAtlasSprite getTarget() { return target.get(); } + + public float getTargetU(float localU) { + return getTarget().getU(getUnInterpolatedU(getOriginal(), localU)); + } + + public float getTargetV(float localV) { + return getTarget().getV(getUnInterpolatedV(getOriginal(), localV)); + } + + public static float getUnInterpolatedU(TextureAtlasSprite sprite, float u) { + float f = sprite.getU1() - sprite.getU0(); + return (u - sprite.getU0()) / f * 16.0F; + } + + public static float getUnInterpolatedV(TextureAtlasSprite sprite, float v) { + float f = sprite.getV1() - sprite.getV0(); + return (v - sprite.getV0()) / f * 16.0F; + } } diff --git a/src/main/java/com/simibubi/create/foundation/block/render/SpriteShifter.java b/src/main/java/com/simibubi/create/foundation/block/render/SpriteShifter.java index 04a0cc605..0b97d60b7 100644 --- a/src/main/java/com/simibubi/create/foundation/block/render/SpriteShifter.java +++ b/src/main/java/com/simibubi/create/foundation/block/render/SpriteShifter.java @@ -3,13 +3,11 @@ package com.simibubi.create.foundation.block.render; import java.util.HashMap; import java.util.Map; -import com.simibubi.create.Create; - import net.minecraft.resources.ResourceLocation; public class SpriteShifter { - protected static final Map ENTRY_CACHE = new HashMap<>(); + private static final Map ENTRY_CACHE = new HashMap<>(); public static SpriteShiftEntry get(ResourceLocation originalLocation, ResourceLocation targetLocation) { String key = originalLocation + "->" + targetLocation; @@ -22,8 +20,4 @@ public class SpriteShifter { return entry; } - public static SpriteShiftEntry get(String originalLocation, String targetLocation) { - return get(Create.asResource(originalLocation), Create.asResource(targetLocation)); - } - } diff --git a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java index 76bb4cd4f..d2400064c 100644 --- a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java @@ -27,7 +27,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.texture.OverlayTexture; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.util.Mth; @@ -350,11 +349,7 @@ public class SuperByteBuffer implements Transform, TStack { - float targetU = entry.getTarget() - .getU((getUnInterpolatedU(entry.getOriginal(), u))); - float targetV = entry.getTarget() - .getV((getUnInterpolatedV(entry.getOriginal(), v))); - builder.uv(targetU, targetV); + builder.uv(entry.getTargetU(u), entry.getTargetV(v)); }; return this; } @@ -381,9 +376,9 @@ public class SuperByteBuffer implements Transform, TStack { float targetU = entry.getTarget() - .getU((getUnInterpolatedU(entry.getOriginal(), u) / sheetSize) + uTarget * 16); + .getU((SpriteShiftEntry.getUnInterpolatedU(entry.getOriginal(), u) / sheetSize) + uTarget * 16); float targetV = entry.getTarget() - .getV((getUnInterpolatedV(entry.getOriginal(), v) / sheetSize) + vTarget * 16); + .getV((SpriteShiftEntry.getUnInterpolatedV(entry.getOriginal(), v) / sheetSize) + vTarget * 16); builder.uv(targetU, targetV); }; return this; @@ -457,16 +452,6 @@ public class SuperByteBuffer implements Transform, TStack