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 63b4c3de1cd1b9327438ecec52faf0f092a2f9f9
parent 99b8e280fbe496786c86ccf89c7771808234a852
Author: Amb0s <ambos@disroot.org>
Date:   Wed, 30 Aug 2023 21:29:38 +0200

Cleaned up fan block code

- Use new Block API methods
- Get textures using the default atlas field

Diffstat:
Msrc/main/java/turniplabs/simpletech/SimpleTech.java | 31+++++++++++++++++++++----------
Msrc/main/java/turniplabs/simpletech/block/BlockFan.java | 20++++++--------------
Msrc/main/resources/lang/simpletech/en_US.lang | 8++++----
Msrc/main/resources/lang/simpletech/fr_FR.lang | 8++++----
4 files changed, 35 insertions(+), 32 deletions(-)

diff --git a/src/main/java/turniplabs/simpletech/SimpleTech.java b/src/main/java/turniplabs/simpletech/SimpleTech.java @@ -10,6 +10,7 @@ import net.minecraft.core.util.helper.Direction; 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; @@ -29,17 +30,27 @@ 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") + .setEastTexture("misc_side.png") + .setWestTexture("misc_side.png") + .setNorthTexture("misc_side.png") + .setHardness(1.5f) + .setResistance(10.0f) + .setLuminance(0) + .setBlockSound(BlockSounds.STONE); + // Blocks - public static final Block unpoweredFan = BlockHelper.createBlock( - MOD_ID, new BlockFan("block.fan.unpowered", UNPOWERED_FAN_ID, Material.stone,false, - "misc_top_bottom.png","misc_side.png","fan_front.png"), - BlockSounds.STONE, 1.5f, 10.0f, 0.0f) - .withTags(BlockTags.MINEABLE_BY_PICKAXE); - public static final Block poweredFan = BlockHelper.createBlock( - MOD_ID, new BlockFan("block.fan.powered", POWERED_FAN_ID, Material.stone,true, - "misc_top_bottom.png","misc_side.png","fan_front_powered.png"), - BlockSounds.STONE, 1.5f, 10.0f, 0.0f) - .withTags(BlockTags.NOT_IN_CREATIVE_MENU, BlockTags.MINEABLE_BY_PICKAXE); + public static final Block unpoweredFan = miscBuilder + .setSouthTexture("fan_front.png") + .setTags(BlockTags.MINEABLE_BY_PICKAXE) + .build(new BlockFan("fan.unpowered", UNPOWERED_FAN_ID, Material.stone, false)); + public static final Block poweredFan = miscBuilder + .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) diff --git a/src/main/java/turniplabs/simpletech/block/BlockFan.java b/src/main/java/turniplabs/simpletech/block/BlockFan.java @@ -9,31 +9,24 @@ import net.minecraft.core.item.ItemStack; import net.minecraft.core.util.helper.Direction; import net.minecraft.core.util.helper.Side; import net.minecraft.core.world.World; -import turniplabs.halplibe.helper.TextureHelper; import turniplabs.simpletech.SimpleTech; import turniplabs.simpletech.block.entity.TileEntityFan; import java.util.Random; public class BlockFan extends BlockTileEntity { - private final int[] topBottom; - private final int[] side; - private final int[] front; private final boolean isPowered; - public BlockFan(String key, int id, Material material, boolean isPowered, String topBottom, - String side, String front) { + public BlockFan(String key, int id, Material material, boolean isPowered) { super(key, id, material); this.isPowered = isPowered; - this.topBottom = TextureHelper.registerBlockTexture(SimpleTech.MOD_ID, topBottom); - this.side = TextureHelper.registerBlockTexture(SimpleTech.MOD_ID, side); - this.front = TextureHelper.registerBlockTexture(SimpleTech.MOD_ID, front); } @Override public ItemStack[] getBreakResult(World world, EnumDropCause dropCause, int x, int y, int z, int meta, TileEntity tileEntity) { // Only drops unpowered fan when broken. + // Should use BlockBuilder.setBlockDrop instead? return dropCause != EnumDropCause.IMPROPER_TOOL ? new ItemStack[]{new ItemStack(SimpleTech.unpoweredFan)} : null; } @@ -46,15 +39,14 @@ public class BlockFan extends BlockTileEntity { public int getBlockTextureFromSideAndMetadata(Side side, int j) { int direction = SimpleTech.get3DDirectionFromMeta(j); if (direction > Direction.EAST.getId()) { - // Defaults to top/bottom texture. - return texCoordToIndex(this.topBottom[0], this.topBottom[1]); + return this.atlasIndices[Side.TOP.getId()]; // Defaults to top/bottom texture. } else if (side.getId() == direction) { - 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.topBottom[0], this.topBottom[1]); + return this.atlasIndices[Side.TOP.getId()]; // Returns top/bottom texture. } else { - return texCoordToIndex(this.side[0], this.side[1]); + return this.atlasIndices[Side.EAST.getId()]; // Returns one of the sides texture. } } } diff --git a/src/main/resources/lang/simpletech/en_US.lang b/src/main/resources/lang/simpletech/en_US.lang @@ -1,7 +1,7 @@ -tile.block.fan.unpowered.name=Fan -tile.block.fan.unpowered.desc=Fan goes whoosh! -tile.block.fan.powered.name=Powered Fan -tile.block.fan.powered.desc=Fan goes whoosh! +tile.simpletech.fan.unpowered.name=Fan +tile.simpletech.fan.unpowered.desc=Fan goes whoosh! +tile.simpletech.fan.powered.name=Powered Fan +tile.simpletech.fan.powered.desc=Fan goes whoosh! tile.block.jumppad.name=Jump Pad tile.block.jumppad.desc=Boing! Hop hop! tile.chest.trapped.name=Trapped Chest diff --git a/src/main/resources/lang/simpletech/fr_FR.lang b/src/main/resources/lang/simpletech/fr_FR.lang @@ -1,7 +1,7 @@ -tile.block.fan.unpowered.name=Ventilateur -tile.block.fan.unpowered.desc= -tile.block.fan.powered.name=Ventilateur en marche -tile.block.fan.powered.desc= +tile.simpletech.fan.unpowered.name=Ventilateur +tile.simpletech.fan.unpowered.desc= +tile.simpletech.fan.powered.name=Ventilateur en marche +tile.simpletech.fan.powered.desc= tile.block.jumppad.name=Trampoline tile.block.jumppad.desc=Boing ! tile.chest.trapped.name=Coffre piégé