SimpleTech.java (10084B)
1 package ambos.simpletech; 2 3 import net.minecraft.client.sound.block.BlockSounds; 4 import net.minecraft.core.block.Block; 5 import net.minecraft.core.block.material.Material; 6 import net.minecraft.core.block.tag.BlockTags; 7 import net.minecraft.core.item.Item; 8 import net.minecraft.core.item.ItemPlaceable; 9 import net.minecraft.core.util.helper.Direction; 10 import net.minecraft.core.world.World; 11 import org.slf4j.Logger; 12 import org.slf4j.LoggerFactory; 13 14 import ambos.simpletech.block.BlockAllocator; 15 import ambos.simpletech.block.BlockFan; 16 import ambos.simpletech.block.BlockJumpPad; 17 import ambos.simpletech.block.BlockLightSensor; 18 import ambos.simpletech.block.BlockRedstoneNotGate; 19 import ambos.simpletech.block.BlockTrappedChest; 20 import ambos.simpletech.block.entity.TileEntityAllocator; 21 import ambos.simpletech.block.entity.TileEntityFan; 22 import ambos.simpletech.block.entity.TileEntityLightSensor; 23 import turniplabs.halplibe.helper.BlockBuilder; 24 import turniplabs.halplibe.helper.EntityHelper; 25 import turniplabs.halplibe.helper.ItemHelper; 26 import turniplabs.halplibe.util.GameStartEntrypoint; 27 import turniplabs.halplibe.util.TomlConfigHandler; 28 import turniplabs.halplibe.util.toml.Toml; 29 30 public class SimpleTech implements GameStartEntrypoint { 31 public static final String MOD_ID = "simpletech"; 32 public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); 33 public static final TomlConfigHandler config; 34 public static final int FAN_RANGE; 35 public static final int UNPOWERED_FAN_ID; 36 public static final int POWERED_FAN_ID; 37 public static final int JUMP_PAD_ID; 38 public static final int TRAPPED_CHEST_ID; 39 public static final int LIGHT_SENSOR_ID; 40 public static final int ALLOCATOR_ID; 41 public static final int ALLOCATOR_GUI_ID; 42 public static final int NOT_GATE_IDLE_ID; 43 public static final int NOT_GATE_ACTIVE_ID; 44 public static final int NOT_GATE_ID; 45 static { 46 Toml configToml = new Toml(); 47 configToml.addCategory("BlockIDs"); 48 configToml.addEntry("BlockIDs.UNPOWERED_FAN_ID", 3789); 49 configToml.addEntry("BlockIDs.POWERED_FAN_ID", 3790); 50 configToml.addEntry("BlockIDs.JUMP_PAD_ID", 3791); 51 configToml.addEntry("BlockIDs.TRAPPED_CHEST_ID", 3792); 52 configToml.addEntry("BlockIDs.LIGHT_SENSOR_ID", 3793); 53 configToml.addEntry("BlockIDs.ALLOCATOR_ID", 3794); 54 configToml.addEntry("BlockIDs.NOT_GATE_IDLE_ID", 3795); 55 configToml.addEntry("BlockIDs.NOT_GATE_ACTIVE_ID", 3796); 56 configToml.addCategory("ItemIDs"); 57 configToml.addEntry("ItemIDs.NOT_GATE_ID", 28890); 58 configToml.addCategory("Settings"); 59 configToml.addEntry("Settings.FAN_RANGE", 4); 60 configToml.addCategory("GUI"); 61 configToml.addEntry("GUI.ALLOCATOR_GUI_ID", 13); 62 63 config = new TomlConfigHandler(MOD_ID, configToml); 64 FAN_RANGE = config.getInt("Settings.FAN_RANGE"); 65 UNPOWERED_FAN_ID = config.getInt("BlockIDs.UNPOWERED_FAN_ID"); 66 POWERED_FAN_ID = config.getInt("BlockIDs.POWERED_FAN_ID"); 67 JUMP_PAD_ID = config.getInt("BlockIDs.JUMP_PAD_ID"); 68 TRAPPED_CHEST_ID = config.getInt("BlockIDs.TRAPPED_CHEST_ID"); 69 LIGHT_SENSOR_ID = config.getInt("BlockIDs.LIGHT_SENSOR_ID"); 70 ALLOCATOR_ID = config.getInt("BlockIDs.ALLOCATOR_ID"); 71 ALLOCATOR_GUI_ID = config.getInt("GUI.ALLOCATOR_GUI_ID"); 72 NOT_GATE_IDLE_ID = config.getInt("BlockIDs.NOT_GATE_IDLE_ID"); 73 NOT_GATE_ACTIVE_ID = config.getInt("BlockIDs.NOT_GATE_ACTIVE_ID"); 74 NOT_GATE_ID = config.getInt("ItemIDs.NOT_GATE_ID"); 75 } 76 77 // Builders 78 public static final BlockBuilder stoneBlockBuilder = new BlockBuilder(MOD_ID) 79 .setHardness(1.5f) 80 .setResistance(10.0f) 81 .setLuminance(0) 82 .setBlockSound(BlockSounds.STONE) 83 .setTags(BlockTags.MINEABLE_BY_PICKAXE); 84 public static final BlockBuilder fanBuilder = stoneBlockBuilder 85 .setTopBottomTexture("misc_top_bottom.png") 86 .setEastTexture("misc_side.png") 87 .setWestTexture("misc_side.png") 88 .setNorthTexture("misc_side.png"); 89 public static final BlockBuilder woodenBlockBuilder = new BlockBuilder(MOD_ID) 90 .setHardness(1.0f) 91 .setResistance(2.5f) 92 .setLuminance(0) 93 .setBlockSound(BlockSounds.WOOD) 94 .setTags(BlockTags.MINEABLE_BY_AXE); 95 public static final BlockBuilder gateBlockBuilder = new BlockBuilder(MOD_ID) 96 .setHardness(0.0f) 97 .setResistance(0.0f) 98 .setLuminance(0) 99 .setBlockSound(BlockSounds.STONE) 100 .setTags(BlockTags.MINEABLE_BY_AXE, BlockTags.BROKEN_BY_FLUIDS, BlockTags.NOT_IN_CREATIVE_MENU, 101 BlockTags.PREVENT_MOB_SPAWNS); 102 103 // Blocks 104 public static final Block unpoweredFan = fanBuilder 105 .setSouthTexture("fan_front.png") 106 .build(new BlockFan("fan.unpowered", UNPOWERED_FAN_ID, Material.stone, false)); 107 public static final Block poweredFan = fanBuilder 108 .setSouthTexture("fan_front_powered.png") 109 .setTags(BlockTags.NOT_IN_CREATIVE_MENU) 110 .build(new BlockFan("fan.powered", POWERED_FAN_ID, Material.stone, true)); 111 public static final Block jumpPad = woodenBlockBuilder 112 .setTextures("jump_pad.png") 113 .build(new BlockJumpPad("jumppad", JUMP_PAD_ID, Material.wood)); 114 public static final Block trappedChest = woodenBlockBuilder 115 .setHardness(2.5f) 116 .setResistance(5.0f) 117 .setTags(BlockTags.MINEABLE_BY_AXE, BlockTags.FENCES_CONNECT) 118 .setTickOnLoad() 119 .build(new BlockTrappedChest("chest.trapped", TRAPPED_CHEST_ID, Material.wood)); 120 public static final Block lightSensor = woodenBlockBuilder 121 .setTextures("light_sensor.png") 122 .build(new BlockLightSensor("lightsensor", LIGHT_SENSOR_ID, Material.wood)); 123 public static final Block allocator = stoneBlockBuilder 124 .setTopTexture("allocator_back_top_bottom.png") 125 .setBottomTexture("allocator_front_top_bottom.png") 126 .setEastTexture("misc_side.png") 127 .setWestTexture("misc_top_bottom.png") 128 .setNorthTexture("allocator_back.png") 129 .setSouthTexture("allocator_front.png") 130 .build(new BlockAllocator("allocator", ALLOCATOR_ID, Material.stone, true, true)); 131 public static final Block notGateIdle = gateBlockBuilder 132 .setTopTexture("gate_top.png") 133 .setNorthTexture("gate_top.png") 134 .setEastTexture("gate_top.png") 135 .setWestTexture("gate_top.png") 136 .setSouthTexture("gate_top.png") 137 .setBottomTexture("gate_top.png") 138 .build(new BlockRedstoneNotGate("not.gate.idle", NOT_GATE_IDLE_ID, Material.decoration, false)); 139 public static final Block notGateActive = gateBlockBuilder 140 .setTopTexture("gate_top_powered.png") 141 .setNorthTexture("gate_top_powered.png") 142 .setEastTexture("gate_top_powered.png") 143 .setWestTexture("gate_top_powered.png") 144 .setSouthTexture("gate_top_powered.png") 145 .setBottomTexture("gate_top_powered.png") 146 .build(new BlockRedstoneNotGate("not.gate.active", NOT_GATE_ACTIVE_ID, Material.decoration, true)); 147 148 // Items 149 public static final Item notGate = ItemHelper.createItem(MOD_ID, 150 new ItemPlaceable("not.gate", NOT_GATE_ID, notGateIdle), "not.gate", "not_logicate.png"); 151 152 @Override 153 public void beforeGameStart() { 154 // Entities. 155 EntityHelper.Core.createTileEntity(TileEntityFan.class, "Fan"); 156 EntityHelper.Core.createTileEntity(TileEntityLightSensor.class, "Light Sensor"); 157 EntityHelper.Core.createTileEntity(TileEntityAllocator.class, "Allocator"); 158 LOGGER.info("Simple Tech initialized"); 159 } 160 161 @Override 162 public void afterGameStart() { 163 164 } 165 166 public static int setBit(int number, int position, int bit) { 167 int mask = 1 << position; 168 return (number & ~mask) | ((bit << position) & mask); 169 } 170 171 public static int getBit(int number, int offset) { 172 return (number >> offset) & 1; 173 } 174 175 public static int getRedstoneFromMetadata(int metadata, int redstoneOffset) { 176 return getBit(metadata, redstoneOffset); 177 } 178 179 public static int getInvertedFromMetadata(int metadata, int invertedOffset) { 180 return getBit(metadata, invertedOffset); 181 } 182 183 public static int getMetaWithRedstone(int metadata, int redstone, int redstoneOffset) { 184 return setBit(metadata, redstoneOffset, redstone); 185 } 186 187 public static int getMetaWithInverted(int metadata, int inverted, int invertedOffset) { 188 return setBit(metadata, invertedOffset, inverted); 189 } 190 191 public static int get3DDirectionFromMeta(int metadata) { 192 return metadata & 7; 193 } 194 195 public static int getOppositeDirectionById(int i) { 196 return Direction.getDirectionById(i).getOpposite().getId(); 197 } 198 199 public static int getDirectionX(World world, int x, int y, int z) { 200 int direction = world.getBlockMetadata(x, y, z); 201 int dx = 0; 202 203 if (direction == Direction.WEST.getId()) { 204 dx = 1; 205 } 206 207 if (direction == Direction.EAST.getId()) { 208 dx = -1; 209 } 210 211 return dx; 212 } 213 214 public static int getDirectionY(World world, int x, int y, int z) { 215 int direction = world.getBlockMetadata(x, y, z); 216 int dy = 0; 217 218 if (direction == Direction.DOWN.getId()) { 219 dy = 1; 220 } 221 222 if (direction == Direction.UP.getId()) { 223 dy = -1; 224 } 225 226 return dy; 227 } 228 229 public static int getDirectionZ(World world, int x, int y, int z) { 230 int direction = world.getBlockMetadata(x, y, z); 231 int dz = 0; 232 233 if (direction == Direction.NORTH.getId()) { 234 dz = 1; 235 } 236 237 if (direction == Direction.SOUTH.getId()) { 238 dz = -1; 239 } 240 241 return dz; 242 } 243 }