simple-tech

Minecraft: Better than Adventure! mod that adds simple blocks to automate tasks
git clone git://memoryshards.xyz/simple-tech.git
Log | Files | Refs | README | LICENSE

commit b44a337832138909f8573cb7173ab76e37c8044f
parent 0591fe121fcac41a1e68cd0cb494015887093a1b
Author: Amb0s <ambos@disroot.org>
Date:   Sat,  2 Sep 2023 23:15:28 +0200

Cleaned up other blocks code

- Use new Block API methods
- Get textures using the default atlas field
- Update inventory rendering code

Diffstat:
Msrc/main/java/turniplabs/simpletech/SimpleTech.java | 58+++++++++++++++++++++++++++++++++++++---------------------
Msrc/main/java/turniplabs/simpletech/block/BlockAllocator.java | 44++++++++------------------------------------
Msrc/main/java/turniplabs/simpletech/mixin/RenderBlocksMixin.java | 17++++++-----------
3 files changed, 51 insertions(+), 68 deletions(-)

diff --git a/src/main/java/turniplabs/simpletech/SimpleTech.java b/src/main/java/turniplabs/simpletech/SimpleTech.java @@ -11,7 +11,6 @@ import net.minecraft.core.world.World; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import turniplabs.halplibe.helper.BlockBuilder; -import turniplabs.halplibe.helper.BlockHelper; import turniplabs.halplibe.helper.EntityHelper; import turniplabs.halplibe.helper.RecipeHelper; import turniplabs.simpletech.block.*; @@ -30,7 +29,6 @@ public class SimpleTech implements ModInitializer { public static final int LIGHT_SENSOR_ID = 3793; public static final int ALLOCATOR_ID = 3794; - // Builders public static final BlockBuilder miscBuilder = new BlockBuilder(MOD_ID) .setTopBottomTexture("misc_top_bottom.png") @@ -51,25 +49,43 @@ public class SimpleTech implements ModInitializer { .setSouthTexture("fan_front_powered.png") .setTags(BlockTags.NOT_IN_CREATIVE_MENU, BlockTags.MINEABLE_BY_PICKAXE) .build(new BlockFan("fan.powered", POWERED_FAN_ID, Material.stone, true)); - public static final Block jumpPad = BlockHelper.createBlock( - MOD_ID, new BlockJumpPad("block.jumppad", JUMP_PAD_ID, Material.wood), - "jump_pad.png", BlockSounds.WOOD, 1.0f, 2.5f, 0.0f) - .withTags(BlockTags.MINEABLE_BY_AXE); - public static final Block trappedChest = BlockHelper.createBlock( - MOD_ID, new BlockTrappedChest("chest.trapped", TRAPPED_CHEST_ID, Material.wood), - BlockSounds.WOOD, 2.5f, 5.0f, 0.0f) - .withTags(BlockTags.FENCES_CONNECT, BlockTags.MINEABLE_BY_AXE); - public static final Block lightSensor = BlockHelper.createBlock( - MOD_ID, new BlockLightSensor("block.lightsensor", LIGHT_SENSOR_ID, Material.wood), - "light_sensor.png", BlockSounds.WOOD, 1.0f, 2.5f, 0.0f) - .withTags(BlockTags.MINEABLE_BY_AXE); - public static final Block allocator = BlockHelper.createBlock( - MOD_ID, new BlockAllocator("block.allocator", ALLOCATOR_ID, Material.stone, - "misc_top_bottom.png", "misc_side.png", "allocator_front.png", - "allocator_back.png", "allocator_front_top_bottom.png", - "allocator_back_top_bottom.png", true, true), - BlockSounds.STONE, 1.5f, 10.0f, 0.0f) - .withTags(BlockTags.MINEABLE_BY_PICKAXE); + public static final Block jumpPad = new BlockBuilder(MOD_ID) + .setTextures("jump_pad.png") + .setHardness(1.0f) + .setResistance(2.5f) + .setLuminance(0) + .setBlockSound(BlockSounds.WOOD) + .setTags(BlockTags.MINEABLE_BY_AXE) + .build(new BlockJumpPad("jumppad", JUMP_PAD_ID, Material.wood)); + public static final Block trappedChest = new BlockBuilder(MOD_ID) + .setHardness(2.5f) + .setResistance(5.0f) + .setLuminance(0) + .setBlockSound(BlockSounds.WOOD) + .setTags(BlockTags.FENCES_CONNECT, BlockTags.MINEABLE_BY_AXE) + .build(new BlockTrappedChest("chest.trapped", TRAPPED_CHEST_ID, Material.wood)); + public static final Block lightSensor = new BlockBuilder(MOD_ID) + .setTextures("light_sensor.png") + .setHardness(1.0f) + .setResistance(2.5f) + .setLuminance(0) + .setBlockSound(BlockSounds.WOOD) + .setTags(BlockTags.MINEABLE_BY_AXE) + .build(new BlockLightSensor("lightsensor", LIGHT_SENSOR_ID, Material.wood)); + public static final Block allocator = new BlockBuilder(MOD_ID) + .setTopTexture("allocator_back_top_bottom.png") + .setBottomTexture("allocator_front_top_bottom.png") + .setEastTexture("misc_side.png") + .setWestTexture("misc_top_bottom.png") + .setNorthTexture("allocator_back.png") + .setSouthTexture("allocator_front.png") + .setHardness(1.5f) + .setResistance(10.0f) + .setLuminance(0) + .setBlockSound(BlockSounds.STONE) + .setTags(BlockTags.MINEABLE_BY_PICKAXE) + .build(new BlockAllocator("allocator", ALLOCATOR_ID, Material.stone, true, + true)); @Override public void onInitialize() { diff --git a/src/main/java/turniplabs/simpletech/block/BlockAllocator.java b/src/main/java/turniplabs/simpletech/block/BlockAllocator.java @@ -20,7 +20,6 @@ import net.minecraft.core.util.helper.Direction; import net.minecraft.core.util.helper.Side; import net.minecraft.core.util.phys.AABB; import net.minecraft.core.world.World; -import turniplabs.halplibe.helper.TextureHelper; import turniplabs.simpletech.gui.GuiAllocator; import turniplabs.simpletech.SimpleTech; import turniplabs.simpletech.block.entity.TileEntityAllocator; @@ -29,40 +28,13 @@ import java.util.List; import java.util.Random; public class BlockAllocator extends BlockTileEntity { - private final int[] top; - private final int[] side; - private final int[] front; - private final int[] back; - private final int[] backTopBottom; - private final int[] frontTopBottom; private final boolean allowFiltering; private final boolean subItemFiltering; - public BlockAllocator(String key, int id, Material material, - String top, String side, String front, String back, - String frontTopBottom, String backTopBottom, - boolean allowFiltering, boolean subItemFiltering) { + public BlockAllocator(String key, int id, Material material, boolean allowFiltering, boolean subItemFiltering) { super(key, id, material); this.allowFiltering = allowFiltering; this.subItemFiltering = subItemFiltering; - this.top = TextureHelper.registerBlockTexture(SimpleTech.MOD_ID, top); - this.side = TextureHelper.registerBlockTexture(SimpleTech.MOD_ID, side); - this.front = TextureHelper.registerBlockTexture(SimpleTech.MOD_ID, front); - this.back = TextureHelper.registerBlockTexture(SimpleTech.MOD_ID, back); - this.frontTopBottom = TextureHelper.registerBlockTexture(SimpleTech.MOD_ID, frontTopBottom); - this.backTopBottom = TextureHelper.registerBlockTexture(SimpleTech.MOD_ID, backTopBottom); - } - - public int[] getTop() { - return this.top; - } - - public int[] getBack() { - return this.back; - } - - public int[] getFront() { - return this.front; } @Override @@ -118,22 +90,22 @@ public class BlockAllocator extends BlockTileEntity { int direction = SimpleTech.get3DDirectionFromMeta(meta); if (direction > 5) { - return texCoordToIndex(this.top[0], this.top[1]); + return this.atlasIndices[Side.WEST.getId()]; // Defaults to top/bottom texture. } else if (side.getId() == SimpleTech.getOppositeDirectionById(direction)) { if (side.getId() == Side.TOP.getId() || side.getId() == Side.BOTTOM.getId()) { - return texCoordToIndex(this.backTopBottom[0], this.backTopBottom[1]); + return this.atlasIndices[Side.TOP.getId()]; // Returns back top/bottom texture. } - return texCoordToIndex(this.back[0], this.back[1]); + return this.atlasIndices[Side.NORTH.getId()]; // Returns back texture. } else if (side.getId() == direction) { if (side.getId() == Side.TOP.getId() || side.getId() == Side.BOTTOM.getId()) { - return texCoordToIndex(this.frontTopBottom[0], this.frontTopBottom[1]); + return this.atlasIndices[Side.BOTTOM.getId()]; // Returns front top/bottom texture. } - return texCoordToIndex(this.front[0], this.front[1]); + return this.atlasIndices[Side.SOUTH.getId()]; // Returns front texture. } else { if (side.getId() == Side.TOP.getId() || side.getId() == Side.BOTTOM.getId()) { - return texCoordToIndex(this.top[0], this.top[1]); + return this.atlasIndices[Side.WEST.getId()]; // Returns top/bottom texture. } else { - return texCoordToIndex(this.side[0], this.side[1]); + return this.atlasIndices[Side.EAST.getId()]; // Returns side texture. } } } diff --git a/src/main/java/turniplabs/simpletech/mixin/RenderBlocksMixin.java b/src/main/java/turniplabs/simpletech/mixin/RenderBlocksMixin.java @@ -17,30 +17,25 @@ final class RenderBlocksMixin { private int changeBlockInventoryRender(Block block, Side side, int meta) { if (block instanceof BlockFan) { if (side == Side.SOUTH) { - return block.getBlockTextureFromSideAndMetadata(Side.BOTTOM, meta); + return block.atlasIndices[Side.SOUTH.getId()]; // Returns front texture. } if (side == Side.BOTTOM) { - return block.getBlockTextureFromSideAndMetadata(Side.TOP, meta); + return block.atlasIndices[Side.TOP.getId()]; // Returns top/bottom texture. } } if (block instanceof BlockAllocator) { - BlockAllocator allocator = ((BlockAllocator) block); - if (side == Side.TOP) { - return Block.texCoordToIndex(allocator.getTop()[0], allocator.getTop()[1]); - } - - if (side == Side.BOTTOM) { - return Block.texCoordToIndex(allocator.getTop()[0], allocator.getTop()[1]); + if (side == Side.TOP || side == Side.BOTTOM) { + return block.atlasIndices[Side.WEST.getId()]; // Returns top/bottom texture. } if (side == Side.SOUTH) { - return Block.texCoordToIndex(allocator.getFront()[0], allocator.getFront()[1]); + return block.atlasIndices[Side.SOUTH.getId()]; // Returns front texture. } if (side == Side.NORTH) { - return Block.texCoordToIndex(allocator.getBack()[0], allocator.getBack()[1]); + return block.atlasIndices[Side.NORTH.getId()]; // Returns back texture. } }