commit 4c70e5eadb6cbc549ade63b63a1c9a8253ee935e parent 4629ddefed503b5cef00d368e3f06463ddcdd44a Author: Amb0s <ambos@disroot.org> Date: Wed, 7 Feb 2024 05:19:03 +0100 Rebranded mod Diffstat:
43 files changed, 1730 insertions(+), 1718 deletions(-)
diff --git a/gradle.properties b/gradle.properties @@ -11,5 +11,5 @@ halplibe_version=3.2.1 # Mod mod_version=0.3.0 -mod_group=turniplabs +mod_group=ambos mod_name=simple-tech diff --git a/src/main/java/ambos/simpletech/IPlayerDisplayer.java b/src/main/java/ambos/simpletech/IPlayerDisplayer.java @@ -0,0 +1,7 @@ +package ambos.simpletech; + +import ambos.simpletech.block.entity.TileEntityAllocator; + +public interface IPlayerDisplayer { + void simple_tech$displayGUIAllocator(TileEntityAllocator allocator); +} diff --git a/src/main/java/ambos/simpletech/SimpleTech.java b/src/main/java/ambos/simpletech/SimpleTech.java @@ -0,0 +1,242 @@ +package ambos.simpletech; + +import net.minecraft.client.sound.block.BlockSounds; +import net.minecraft.core.block.Block; +import net.minecraft.core.block.material.Material; +import net.minecraft.core.block.tag.BlockTags; +import net.minecraft.core.item.Item; +import net.minecraft.core.item.ItemPlaceable; +import net.minecraft.core.util.helper.Direction; +import net.minecraft.core.world.World; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import ambos.simpletech.block.BlockAllocator; +import ambos.simpletech.block.BlockFan; +import ambos.simpletech.block.BlockJumpPad; +import ambos.simpletech.block.BlockLightSensor; +import ambos.simpletech.block.BlockRedstoneNotGate; +import ambos.simpletech.block.BlockTrappedChest; +import ambos.simpletech.block.entity.TileEntityAllocator; +import ambos.simpletech.block.entity.TileEntityFan; +import ambos.simpletech.block.entity.TileEntityLightSensor; +import turniplabs.halplibe.helper.BlockBuilder; +import turniplabs.halplibe.helper.EntityHelper; +import turniplabs.halplibe.helper.ItemHelper; +import turniplabs.halplibe.util.GameStartEntrypoint; +import turniplabs.halplibe.util.TomlConfigHandler; +import turniplabs.halplibe.util.toml.Toml; + +public class SimpleTech implements GameStartEntrypoint { + public static final String MOD_ID = "simpletech"; + public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); + public static final TomlConfigHandler config; + public static final int FAN_RANGE; + public static final int UNPOWERED_FAN_ID; + public static final int POWERED_FAN_ID; + public static final int JUMP_PAD_ID; + public static final int TRAPPED_CHEST_ID; + public static final int LIGHT_SENSOR_ID; + public static final int ALLOCATOR_ID; + public static final int ALLOCATOR_GUI_ID; + public static final int NOT_GATE_IDLE_ID; + public static final int NOT_GATE_ACTIVE_ID; + public static final int NOT_GATE_ID; + static { + Toml configToml = new Toml(); + configToml.addCategory("BlockIDs"); + configToml.addEntry("BlockIDs.UNPOWERED_FAN_ID", 3789); + configToml.addEntry("BlockIDs.POWERED_FAN_ID", 3790); + configToml.addEntry("BlockIDs.JUMP_PAD_ID", 3791); + configToml.addEntry("BlockIDs.TRAPPED_CHEST_ID", 3792); + configToml.addEntry("BlockIDs.LIGHT_SENSOR_ID", 3793); + configToml.addEntry("BlockIDs.ALLOCATOR_ID", 3794); + configToml.addEntry("BlockIDs.NOT_GATE_IDLE_ID", 3795); + configToml.addEntry("BlockIDs.NOT_GATE_ACTIVE_ID", 3796); + configToml.addCategory("ItemIDs"); + configToml.addEntry("ItemIDs.NOT_GATE_ID", 28890); + configToml.addCategory("Settings"); + configToml.addEntry("Settings.FAN_RANGE", 4); + configToml.addCategory("GUI"); + configToml.addEntry("GUI.ALLOCATOR_GUI_ID", 13); + + config = new TomlConfigHandler(MOD_ID, configToml); + FAN_RANGE = config.getInt("Settings.FAN_RANGE"); + UNPOWERED_FAN_ID = config.getInt("BlockIDs.UNPOWERED_FAN_ID"); + POWERED_FAN_ID = config.getInt("BlockIDs.POWERED_FAN_ID"); + JUMP_PAD_ID = config.getInt("BlockIDs.JUMP_PAD_ID"); + TRAPPED_CHEST_ID = config.getInt("BlockIDs.TRAPPED_CHEST_ID"); + LIGHT_SENSOR_ID = config.getInt("BlockIDs.LIGHT_SENSOR_ID"); + ALLOCATOR_ID = config.getInt("BlockIDs.ALLOCATOR_ID"); + ALLOCATOR_GUI_ID = config.getInt("GUI.ALLOCATOR_GUI_ID"); + NOT_GATE_IDLE_ID = config.getInt("BlockIDs.NOT_GATE_IDLE_ID"); + NOT_GATE_ACTIVE_ID = config.getInt("BlockIDs.NOT_GATE_ACTIVE_ID"); + NOT_GATE_ID = config.getInt("ItemIDs.NOT_GATE_ID"); + } + + + // Builders + public static final BlockBuilder stoneBlockBuilder = new BlockBuilder(MOD_ID) + .setHardness(1.5f) + .setResistance(10.0f) + .setLuminance(0) + .setBlockSound(BlockSounds.STONE) + .setTags(BlockTags.MINEABLE_BY_PICKAXE); + public static final BlockBuilder fanBuilder = stoneBlockBuilder + .setTopBottomTexture("misc_top_bottom.png") + .setEastTexture("misc_side.png") + .setWestTexture("misc_side.png") + .setNorthTexture("misc_side.png"); + public static final BlockBuilder woodenBlockBuilder = new BlockBuilder(MOD_ID) + .setHardness(1.0f) + .setResistance(2.5f) + .setLuminance(0) + .setBlockSound(BlockSounds.WOOD) + .setTags(BlockTags.MINEABLE_BY_AXE); + public static final BlockBuilder gateBlockBuilder = new BlockBuilder(MOD_ID) + .setHardness(0.0f) + .setResistance(0.0f) + .setLuminance(0) + .setBlockSound(BlockSounds.STONE) + .setTags(BlockTags.MINEABLE_BY_AXE, BlockTags.BROKEN_BY_FLUIDS, BlockTags.NOT_IN_CREATIVE_MENU, BlockTags.PREVENT_MOB_SPAWNS); + + // Blocks + public static final Block unpoweredFan = fanBuilder + .setSouthTexture("fan_front.png") + .build(new BlockFan("fan.unpowered", UNPOWERED_FAN_ID, Material.stone, false)); + public static final Block poweredFan = fanBuilder + .setSouthTexture("fan_front_powered.png") + .setTags(BlockTags.NOT_IN_CREATIVE_MENU) + .build(new BlockFan("fan.powered", POWERED_FAN_ID, Material.stone, true)); + public static final Block jumpPad = woodenBlockBuilder + .setTextures("jump_pad.png") + .build(new BlockJumpPad("jumppad", JUMP_PAD_ID, Material.wood)); + public static final Block trappedChest = woodenBlockBuilder + .setHardness(2.5f) + .setResistance(5.0f) + .setTags(BlockTags.MINEABLE_BY_AXE, BlockTags.FENCES_CONNECT) + .setTickOnLoad() + .build(new BlockTrappedChest("chest.trapped", TRAPPED_CHEST_ID, Material.wood)); + public static final Block lightSensor = woodenBlockBuilder + .setTextures("light_sensor.png") + .build(new BlockLightSensor("lightsensor", LIGHT_SENSOR_ID, Material.wood)); + public static final Block allocator = stoneBlockBuilder + .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") + .build(new BlockAllocator("allocator", ALLOCATOR_ID, Material.stone, true, true)); + public static final Block notGateIdle = gateBlockBuilder + .setTopTexture("gate_top.png") + .setNorthTexture("gate_top.png") + .setEastTexture("gate_top.png") + .setWestTexture("gate_top.png") + .setSouthTexture("gate_top.png") + .setBottomTexture("gate_top.png") + .build(new BlockRedstoneNotGate("not.gate.idle", NOT_GATE_IDLE_ID, Material.decoration, false)); + public static final Block notGateActive = gateBlockBuilder + .setTopTexture("gate_top_powered.png") + .setNorthTexture("gate_top_powered.png") + .setEastTexture("gate_top_powered.png") + .setWestTexture("gate_top_powered.png") + .setSouthTexture("gate_top_powered.png") + .setBottomTexture("gate_top_powered.png") + .build(new BlockRedstoneNotGate("not.gate.active", NOT_GATE_ACTIVE_ID, Material.decoration, true)); + + // Items + public static final Item notGate = ItemHelper.createItem(MOD_ID, new ItemPlaceable("not.gate", NOT_GATE_ID, notGateIdle), "not.gate", "not_logicate.png"); + + @Override + public void beforeGameStart() { + // Entities. + EntityHelper.Core.createTileEntity(TileEntityFan.class, "Fan"); + EntityHelper.Core.createTileEntity(TileEntityLightSensor.class, "Light Sensor"); + EntityHelper.Core.createTileEntity(TileEntityAllocator.class, "Allocator"); + LOGGER.info("Simple Tech initialized"); + } + + @Override + public void afterGameStart() { + + } + + public static int setBit(int number, int position, int bit) { + int mask = 1 << position; + return (number & ~mask) | ((bit << position) & mask); + } + + public static int getBit(int number, int offset) { + return (number >> offset) & 1; + } + + public static int getRedstoneFromMetadata(int metadata, int redstoneOffset) { + return getBit(metadata, redstoneOffset); + } + + public static int getInvertedFromMetadata(int metadata, int invertedOffset) { + return getBit(metadata, invertedOffset); + } + + public static int getMetaWithRedstone(int metadata, int redstone, int redstoneOffset) { + return setBit(metadata, redstoneOffset, redstone); + } + + public static int getMetaWithInverted(int metadata, int inverted, int invertedOffset) { + return setBit(metadata, invertedOffset, inverted); + } + + public static int get3DDirectionFromMeta(int metadata) { + return metadata & 7; + } + + public static int getOppositeDirectionById(int i) { + return Direction.getDirectionById(i).getOpposite().getId(); + } + + public static int getDirectionX(World world, int x, int y, int z) { + int direction = world.getBlockMetadata(x, y, z); + int dx = 0; + + if (direction == Direction.WEST.getId()) { + dx = 1; + } + + if (direction == Direction.EAST.getId()) { + dx = -1; + } + + return dx; + } + + public static int getDirectionY(World world, int x, int y, int z) { + int direction = world.getBlockMetadata(x, y, z); + int dy = 0; + + if (direction == Direction.DOWN.getId()) { + dy = 1; + } + + if (direction == Direction.UP.getId()) { + dy = -1; + } + + return dy; + } + + public static int getDirectionZ(World world, int x, int y, int z) { + int direction = world.getBlockMetadata(x, y, z); + int dz = 0; + + if (direction == Direction.NORTH.getId()) { + dz = 1; + } + + if (direction == Direction.SOUTH.getId()) { + dz = -1; + } + + return dz; + } +} diff --git a/src/main/java/ambos/simpletech/SimpleTechRecipes.java b/src/main/java/ambos/simpletech/SimpleTechRecipes.java @@ -0,0 +1,22 @@ +package ambos.simpletech; + +import net.minecraft.core.block.Block; +import net.minecraft.core.data.DataLoader; +import net.minecraft.core.data.registry.Registries; +import net.minecraft.core.data.registry.recipe.RecipeGroup; +import net.minecraft.core.data.registry.recipe.RecipeNamespace; +import net.minecraft.core.data.registry.recipe.RecipeSymbol; +import net.minecraft.core.data.registry.recipe.entry.RecipeEntryCrafting; +import net.minecraft.core.item.ItemStack; +import turniplabs.halplibe.util.RecipeEntrypoint; + +public class SimpleTechRecipes implements RecipeEntrypoint { + public static final RecipeNamespace SIMPLE_TECH = new RecipeNamespace(); + public static final RecipeGroup<RecipeEntryCrafting<?, ?>> WORKBENCH = new RecipeGroup<>(new RecipeSymbol(new ItemStack(Block.workbench))); + @Override + public void onRecipesReady() { + SIMPLE_TECH.register("workbench", WORKBENCH); + Registries.RECIPES.register("simpletech", SIMPLE_TECH); + DataLoader.loadRecipes("/assets/simpletech/recipes/workbench.json"); + } +} diff --git a/src/main/java/ambos/simpletech/block/BlockAllocator.java b/src/main/java/ambos/simpletech/block/BlockAllocator.java @@ -0,0 +1,360 @@ +package ambos.simpletech.block; + +import net.minecraft.core.block.Block; +import net.minecraft.core.block.BlockTileEntity; +import net.minecraft.core.block.entity.TileEntity; +import net.minecraft.core.block.entity.TileEntityChest; +import net.minecraft.core.block.entity.TileEntityFurnace; +import net.minecraft.core.block.material.Material; +import net.minecraft.core.entity.Entity; +import net.minecraft.core.entity.EntityItem; +import net.minecraft.core.entity.EntityLiving; +import net.minecraft.core.entity.player.EntityPlayer; +import net.minecraft.core.entity.vehicle.EntityMinecart; +import net.minecraft.core.item.ItemStack; +import net.minecraft.core.player.inventory.IInventory; +import net.minecraft.core.player.inventory.InventoryLargeChest; +import net.minecraft.core.sound.SoundType; +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 java.util.List; +import java.util.Random; + +import ambos.simpletech.IPlayerDisplayer; +import ambos.simpletech.SimpleTech; +import ambos.simpletech.block.entity.TileEntityAllocator; + +public class BlockAllocator extends BlockTileEntity { + private final boolean allowFiltering; + private final boolean subItemFiltering; + + public BlockAllocator(String key, int id, Material material, boolean allowFiltering, boolean subItemFiltering) { + super(key, id, material); + this.allowFiltering = allowFiltering; + this.subItemFiltering = subItemFiltering; + } + + @Override + protected TileEntity getNewBlockEntity() { + return new TileEntityAllocator(); + } + + @Override + public boolean blockActivated(World world, int x, int y, int z, EntityPlayer player) { + if (!this.allowFiltering) { + return false; + } else if (world.isClientSide) { + return true; + } else { + TileEntityAllocator allocator = (TileEntityAllocator) world.getBlockTileEntity(x, y, z); + ((IPlayerDisplayer)player).simple_tech$displayGUIAllocator(allocator); + return true; + } + } + + @Override + public void updateTick(World world, int x, int y, int z, Random rand) { + if (world.isBlockIndirectlyGettingPowered(x, y, z) || world.isBlockIndirectlyGettingPowered(x, y + 1, z)) { + this.allocateItems(world, x, y, z, rand); + } + } + + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, int blockId) { + if (blockId > 0 && Block.blocksList[blockId].canProvidePower() && + (world.isBlockIndirectlyGettingPowered(x, y, z) || + world.isBlockIndirectlyGettingPowered(x, y + 1, z))) { + world.scheduleBlockUpdate(x, y, z, this.id, this.tickRate()); + } + } + + @Override + public int tickRate() { + return 1; + } + + @Override + public void onBlockAdded(World world, int x, int y, int z) { + super.onBlockAdded(world, x, y, z); + } + + @Override + public int getBlockTextureFromSideAndMetadata(Side side, int meta) { + int direction = SimpleTech.get3DDirectionFromMeta(meta); + + if (direction > 5) { + 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 this.atlasIndices[Side.TOP.getId()]; // Returns back top/bottom texture. + } + 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 this.atlasIndices[Side.BOTTOM.getId()]; // Returns front top/bottom texture. + } + return this.atlasIndices[Side.SOUTH.getId()]; // Returns front texture. + } else { + if (side.getId() == Side.TOP.getId() || side.getId() == Side.BOTTOM.getId()) { + return this.atlasIndices[Side.WEST.getId()]; // Returns top/bottom texture. + } else { + return this.atlasIndices[Side.EAST.getId()]; // Returns side texture. + } + } + } + + @Override + public void onBlockPlaced(World world, int x, int y, int z, Side side, EntityLiving entity, double sideHeight) { + Direction placementDirection = entity.getPlacementDirection(side).getOpposite(); + world.setBlockMetadataWithNotify(x, y, z, placementDirection.getId()); + } + + public int getRandomItemFromContainer(IInventory inventory, Random rand, World world, int x, int y, int z) { + if (inventory == null) { + return -1; + } else { + int i = -1; + int j = 1; + + byte startAt = 0; + + if (inventory instanceof TileEntityFurnace) { + startAt = 2; + } + + for (int k = startAt; k < inventory.getSizeInventory(); ++k) { + if (inventory.getStackInSlot(k) != null && this.passesFilter(world, x, y, z, + inventory.getStackInSlot(k)) && rand.nextInt(j) == 0) { + i = k; + ++j; + } + } + + return i; + } + } + + protected IInventory containerAtPos(World world, int x, int y, int z) { + TileEntity tile = world.getBlockTileEntity(x, y, z); + return !(tile instanceof IInventory) ? null : this.getDoubleChest(world, x, y, z); + } + + protected boolean blockingCubeAtPos(World world, int x, int y, int z) { + int blockID = world.getBlockId(x, y, z); + boolean isOpaque = Block.translucent[blockID]; + + return isOpaque || blockID == Block.glass.id || + blockID == Block.cactus.id || + blockID == Block.cake.id || + blockID == Block.blockSnow.id || + blockID == Block.mobspawner.id || + blockID == Block.fencePlanksOak.id; + } + + private void putItemInContainer(IInventory inventory, ItemStack item, int index) { + if (item != null) { + if (index >= 0) { + ItemStack stack = inventory.getStackInSlot(index); + + if (stack != null) { + stack.stackSize += item.stackSize; + inventory.setInventorySlotContents(index, stack); + } else { + inventory.setInventorySlotContents(index, item); + } + } + } + } + + private void dispenseItem(World world, int x, int y, int z, int dx, int dy, int dz, ItemStack item, Random rand) { + double d = (double) x + (double) dx * 0.5D + 0.5D; + double d1 = (double) y + (double) dy * 0.5D + 0.5D; + double d2 = (double) z + (double) dz * 0.5D + 0.5D; + double d3 = rand.nextDouble() * 0.1D + 0.2D; + + EntityItem entityItem = new EntityItem(world, d, d1, d2, item); + + // Item movement. + entityItem.xd = (double) dx * d3; + entityItem.yd = (double) dy * d3; + entityItem.zd = (double) dz * d3; + entityItem.xd += rand.nextGaussian() * (double) 0.0075F * 6.0D; + entityItem.yd += rand.nextGaussian() * (double) 0.0075F * 6.0D; + entityItem.xd += rand.nextGaussian() * (double) 0.0075F * 6.0D; + + world.entityJoinedWorld(entityItem); + world.playSoundEffect(SoundType.GUI_SOUNDS, x, y, z, "random.click", 1.0f, 1.0f); + + // Particle rendering. + for (int i = 0; i < 10; ++i) { + double d4 = rand.nextDouble() * 0.2D + 0.01D; + double d5 = d + (double) dx * 0.01D + (rand.nextDouble() - 0.5D) * (double) dz * 0.5D; + double d6 = d1 + (rand.nextDouble() - 0.5D) * 0.5D; + double d7 = d2 + (double) dz * 0.01D + (rand.nextDouble() - 0.5D) * (double) dx * 0.5D; + double d8 = (double) dx * d4 + rand.nextGaussian() * 0.01D; + double d9 = -0.03D + rand.nextGaussian() * 0.01D; + double d10 = (double) dz * d4 + rand.nextGaussian() * 0.01D; + + world.spawnParticle("smoke", d5, d6, d7, d8, d9, d10); + } + } + + private boolean outputItem(World world, int x, int y, int z, int dx, int dy, int dz, ItemStack item, Random rand) { + IInventory outputContainer = this.containerAtPos(world, x + dx, y + dy, z + dz); + + if (outputContainer == null) { + List<Entity> index = world.getEntitiesWithinAABB(IInventory.class, AABB.getBoundingBoxFromPool( + x + dx, y + dy, z + dz, x + dx + 1, y + dy + 1, z + dz + 1)); + + if (!index.isEmpty() && (!(index.get(0) instanceof EntityMinecart) || + ((EntityMinecart) index.get(0)).minecartType == 1)) { + outputContainer = (IInventory) index.get(0); + } + } + + if (outputContainer == null) { + if (!this.blockingCubeAtPos(world, x + dx, y + dy, z + dz)) { + this.dispenseItem(world, x, y, z, dx, dy, dz, item, rand); + + return true; + } + } else { + int index1 = this.getFirstFreeInventorySlotOfKind(outputContainer, item); + + if (index1 >= 0) { + this.putItemInContainer(outputContainer, item, index1); + return true; + } + } + + return false; + } + + private IInventory getDoubleChest(World world, int x, int y, int z) { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + if (!(tileEntity instanceof TileEntityChest)) { + return tileEntity instanceof IInventory ? (IInventory) tileEntity : null; + } else { + int blockId = world.getBlockId(x, y, z); + + IInventory chest1 = (IInventory) world.getBlockTileEntity(x, y, z); + IInventory chest2; + + if (world.getBlockId(x + 1, y, z) == blockId) { + chest2 = (IInventory) world.getBlockTileEntity(x + 1, y, z); + + return new InventoryLargeChest("", chest1, chest2); + } else if (world.getBlockId(x - 1, y, z) == blockId) { + chest2 = (IInventory) world.getBlockTileEntity(x - 1, y, z); + + return new InventoryLargeChest("", chest2, chest1); + } else if (world.getBlockId(x, y, z + 1) == blockId) { + chest2 = (IInventory) world.getBlockTileEntity(x, y, z + 1); + + return new InventoryLargeChest("", chest1, chest2); + } else if (world.getBlockId(x, y, z - 1) == blockId) { + chest2 = (IInventory) world.getBlockTileEntity(x, y, z - 1); + + return new InventoryLargeChest("", chest2, chest1); + } else { + return chest1; + } + } + } + + private void allocateItems(World world, int x, int y, int z, Random rand) { + int dx = SimpleTech.getDirectionX(world, x, y, z); + int dy = SimpleTech.getDirectionY(world, x, y, z); + int dz = SimpleTech.getDirectionZ(world, x, y, z); + + IInventory inputContainer = this.containerAtPos(world, x - dx, y - dy, z - dz); + + List<Entity> entities; + + if (inputContainer == null) { + entities = world.getEntitiesWithinAABB(IInventory.class, AABB.getBoundingBoxFromPool( + x - dx, y - dy, z - dz, x - dx + 1, y - dy + 1, z - dz + 1)); + + if (!entities.isEmpty() && (!(entities.get(0) instanceof EntityMinecart) || + ((EntityMinecart)entities.get(0)).minecartType == 1)) { + inputContainer = (IInventory) entities.get(0); + } + } + + int itemIndex; + if (inputContainer == null) { + entities = world.getEntitiesWithinAABB(EntityItem.class, AABB.getBoundingBoxFromPool( + x - dx, y - dy, z - dz, x - dx + 1, y - dy + 1, z - dz + 1)); + + for (itemIndex = 0; itemIndex < entities.size(); ++itemIndex) { + if (entities.get(itemIndex) instanceof EntityItem) { + EntityItem itemType = (EntityItem) entities.get(itemIndex); + + if (itemType.isAlive() && this.passesFilter(world, x, y, z, itemType.item) && + this.outputItem(world, x, y, z, dx, dy, dz, itemType.item, rand)) { + itemType.outOfWorld(); + } + } + } + } else { + itemIndex = this.getRandomItemFromContainer(inputContainer, rand, world, x, y, z); + + if (itemIndex >= 0) { + int itemDamage = inputContainer.getStackInSlot(itemIndex).getItemDamageForDisplay(); + + ItemStack item = new ItemStack(inputContainer.getStackInSlot(itemIndex) + .getItem(), 1, itemDamage); + + if (this.outputItem(world, x, y, z, dx, dy, dz, item, rand)) { + inputContainer.decrStackSize(itemIndex, 1); + } + } + } + } + + private int getFirstFreeInventorySlotOfKind(IInventory inventory, ItemStack item) { + int inventorySize = inventory.getSizeInventory(); + + if (inventory instanceof TileEntityFurnace) { + --inventorySize; + } + + for (int i = 0; i < inventorySize; ++i) { + boolean canStack = false; + + if (inventory.getStackInSlot(i) != null && inventory.getStackInSlot(i).itemID == item.itemID && + (!item.getItem().getHasSubtypes() || + inventory.getStackInSlot(i).getItemDamageForDisplay() == item.getItemDamageForDisplay())) { + canStack = inventory.getStackInSlot(i).stackSize <= item.getMaxStackSize() - item.stackSize; + } + + if (inventory.getStackInSlot(i) == null || canStack) { + return i; + } + } + + return -1; + } + + private boolean passesFilter(World world, int x, int y, int z, ItemStack item) { + if (!this.allowFiltering) { + return true; + } else { + TileEntityAllocator tileentityallocator = (TileEntityAllocator)world.getBlockTileEntity(x, y, z); + ItemStack filterItem = tileentityallocator.getStackInSlot(0); + if (filterItem == null) { + return true; + } else { + boolean filterSubItems = true; + if (this.subItemFiltering) { + filterSubItems = filterItem.getItemDamageForDisplay() == item.getItemDamageForDisplay(); + } + + return filterItem.itemID == item.getItem().id && filterSubItems; + } + } + } +} diff --git a/src/main/java/ambos/simpletech/block/BlockFan.java b/src/main/java/ambos/simpletech/block/BlockFan.java @@ -0,0 +1,110 @@ +package ambos.simpletech.block; + +import net.minecraft.core.block.BlockTileEntity; +import net.minecraft.core.block.entity.TileEntity; +import net.minecraft.core.block.material.Material; +import net.minecraft.core.entity.EntityLiving; +import net.minecraft.core.enums.EnumDropCause; +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 java.util.Random; + +import ambos.simpletech.SimpleTech; +import ambos.simpletech.block.entity.TileEntityFan; + +public class BlockFan extends BlockTileEntity { + private final boolean isPowered; + + public BlockFan(String key, int id, Material material, boolean isPowered) { + super(key, id, material); + this.isPowered = isPowered; + } + + @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; + } + + @Override + public int tickRate() { + return 2; + } + + @Override + public int getBlockTextureFromSideAndMetadata(Side side, int j) { + int direction = SimpleTech.get3DDirectionFromMeta(j); + if (direction > Direction.EAST.getId()) { + return this.atlasIndices[Side.TOP.getId()]; // Defaults to top/bottom texture. + } else if (side.getId() == direction) { + return this.atlasIndices[Side.SOUTH.getId()]; // Returns front texture. + } else { + if (side.getId() == Side.TOP.getId() || side.getId() == Side.BOTTOM.getId()) { + return this.atlasIndices[Side.TOP.getId()]; // Returns top/bottom texture. + } else { + return this.atlasIndices[Side.EAST.getId()]; // Returns one of the sides texture. + } + } + } + + @Override + public void randomDisplayTick(World world, int x, int y, int z, Random rand) { + // Particle rendering. + if (this.isPowered) { + int dx = -SimpleTech.getDirectionX(world, x, y, z); + int dy = -SimpleTech.getDirectionY(world, x, y, z); + int dz = -SimpleTech.getDirectionZ(world, x, y, z); + + for (int i = 1; i < 3; ++i) { + double rx = rand.nextDouble() - 0.5; + double ry = rand.nextDouble() - 0.5; + double rz = rand.nextDouble() - 0.5; + world.spawnParticle("smoke", + (double) (x + dx) + 0.5 + rx, + (double) (y + dy) + 0.5 + ry, + (double) (z + dz) + 0.5 + rz, + 0.2 * (double) dx, + 0.2 * (double) dy, + 0.2 * (double) dz + ); + } + } + } + + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, int l) { + int direction; + + // If it's currently powered by redstone... + if (world.isBlockIndirectlyGettingPowered(x, y, z) || world.isBlockIndirectlyGettingPowered(x, y + 1, z)) { + // If it wasn't already powered... + if (!this.isPowered) { + // Replaces the unpowered fan by its powered counterpart. + direction = world.getBlockMetadata(x, y, z); + world.setBlockAndMetadataWithNotify(x, y, z, SimpleTech.POWERED_FAN_ID, direction); + } + + world.scheduleBlockUpdate(x, y, z, this.id, this.tickRate()); + } else if (this.isPowered) { + // Replaces the powered fan by its unpowered counterpart. + direction = world.getBlockMetadata(x, y, z); + world.setBlockAndMetadataWithNotify(x, y, z, SimpleTech.UNPOWERED_FAN_ID, direction); + } + } + + @Override + public void onBlockPlaced(World world, int x, int y, int z, Side side, EntityLiving entity, double sideHeight) { + Direction placementDirection = entity.getPlacementDirection(side).getOpposite(); + world.setBlockMetadataWithNotify(x, y, z, placementDirection.getId()); + } + + @Override + protected TileEntity getNewBlockEntity() { + return new TileEntityFan(); + } +} diff --git a/src/main/java/ambos/simpletech/block/BlockJumpPad.java b/src/main/java/ambos/simpletech/block/BlockJumpPad.java @@ -0,0 +1,56 @@ +package ambos.simpletech.block; + +import net.minecraft.core.block.Block; +import net.minecraft.core.block.material.Material; +import net.minecraft.core.entity.Entity; +import net.minecraft.core.entity.EntityItem; +import net.minecraft.core.entity.EntityLiving; +import net.minecraft.core.world.World; + +public class BlockJumpPad extends Block { + public BlockJumpPad(String key, int id, Material material) { + super(key, id, material); + } + + @Override + public boolean isSolidRender() { + return false; + } + + @Override + public boolean canPlaceBlockAt(World world, int x, int y, int z) { + return world.isBlockOpaqueCube(x, y - 1, z); + } + + public void jump(Entity entity) { + if ((entity instanceof EntityLiving || entity instanceof EntityItem) && entity.yd < 1.0D) { + entity.yd = 0.0D; + entity.fallDistance = 0.0F; + entity.push(0.0D, 1.0D, 0.0D); + } + } + + @Override + public void onEntityWalking(World world, int x, int y, int z, Entity entity) { + this.jump(entity); + } + + @Override + public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) { + if (entity.y > (double) y) { + this.jump(entity); + } + } + + @Override + public void setBlockBoundsBasedOnState(World world, int x, int y, int z) { + // Sets block shape when placed. + this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.25f, 1.0f); + } + + @Override + public void setBlockBoundsForItemRender() { + // Sets block shape when rendered inside containers. + this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.25f, 1.0f); + } +} diff --git a/src/main/java/ambos/simpletech/block/BlockLightSensor.java b/src/main/java/ambos/simpletech/block/BlockLightSensor.java @@ -0,0 +1,85 @@ +package ambos.simpletech.block; + +import ambos.simpletech.SimpleTech; +import ambos.simpletech.block.entity.TileEntityLightSensor; +import net.minecraft.core.block.BlockTileEntity; +import net.minecraft.core.block.entity.TileEntity; +import net.minecraft.core.block.material.Material; +import net.minecraft.core.entity.player.EntityPlayer; +import net.minecraft.core.world.World; +import net.minecraft.core.world.WorldSource; + +public class BlockLightSensor extends BlockTileEntity { + public static final int invertedOffset = 0; + public static final int redstoneOffset = 4; + + public BlockLightSensor(String key, int id, Material material) { + super(key, id, material); + } + + public boolean isInverted(World world, int x, int y, int z) { + return SimpleTech.getInvertedFromMetadata(world.getBlockMetadata(x, y, z), invertedOffset) != 0; + } + + @Override + public boolean renderAsNormalBlock() { + return false; + } + + @Override + public boolean isSolidRender() { + return false; + } + + @Override + public boolean canProvidePower() { + return true; + } + + @Override + public TileEntity getNewBlockEntity() { + return new TileEntityLightSensor(); + } + + @Override + public boolean isPoweringTo(WorldSource blockAccess, int x, int y, int z, int side) { + return SimpleTech.getRedstoneFromMetadata(blockAccess.getBlockMetadata(x, y, z), redstoneOffset) > 0; + } + + @Override + public void setBlockBoundsBasedOnState(World world, int x, int y, int z) { + // Sets block shape when placed. + this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.25f, 1.0f); + } + + @Override + public void setBlockBoundsForItemRender() { + // Sets block shape when rendered inside containers. + this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.25f, 1.0f); + } + + @Override + public boolean blockActivated(World world, int x, int y, int z, EntityPlayer player) { + int metadata = world.getBlockMetadata(x, y, z); + int isInverted = !isInverted(world, x, y, z) ? 1 : 0; + + // Recreates metadata using the inverted state and the old metadata value. + world.setBlockMetadataWithNotify(x, y, z, SimpleTech.getMetaWithInverted(metadata, isInverted, invertedOffset)); + + return true; + } + + public void updateSensor(World world, int x, int y, int z, boolean powering) { + int metadata = world.getBlockMetadata(x, y, z); + int redstone = powering ? 1 : 0; + + // Recreates metadata using the redstone signal and the old metadata value. + world.setBlockMetadataWithNotify(x, y, z, SimpleTech.getMetaWithRedstone(metadata, redstone, redstoneOffset)); + + // Updates block's neighbors. + world.notifyBlocksOfNeighborChange(x, y, z, this.id); + world.notifyBlocksOfNeighborChange(x, y - 1, z, this.id); + + world.markBlocksDirty(x, y, z, x, y, z); + } +} diff --git a/src/main/java/ambos/simpletech/block/BlockRedstoneNotGate.java b/src/main/java/ambos/simpletech/block/BlockRedstoneNotGate.java @@ -0,0 +1,180 @@ +package ambos.simpletech.block; + +import net.minecraft.core.block.Block; +import net.minecraft.core.block.entity.TileEntity; +import net.minecraft.core.block.material.Material; +import net.minecraft.core.entity.EntityLiving; +import net.minecraft.core.enums.EnumDropCause; +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 net.minecraft.core.world.WorldSource; + +import java.util.Random; + +import ambos.simpletech.SimpleTech; + +public class BlockRedstoneNotGate extends Block { + private final boolean isPowered; + + public BlockRedstoneNotGate(String key, int id, Material material, boolean isPowered) { + super(key, id, material); + this.isPowered = isPowered; + } + + @Override + public void setBlockBoundsBasedOnState(World world, int x, int y, int z) { + // Sets block shape when placed. + this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.125f, 1.0f); + } + + @Override + public void setBlockBoundsForItemRender() { + // Sets block shape when rendered inside containers. + this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.125f, 1.0f); + } + + @Override + public boolean isSolidRender() { + return false; + } + + @Override + public boolean renderAsNormalBlock() { + return false; + } + + @Override + public boolean canPlaceBlockAt(World world, int x, int y, int z) { + return !world.canPlaceOnSurfaceOfBlock(x, y - 1, z) ? false : super.canPlaceBlockAt(world, x, y, z); + } + + @Override + public ItemStack[] getBreakResult(World world, EnumDropCause dropCause, int x, int y, int z, int meta, TileEntity tileEntity) { + return new ItemStack[]{new ItemStack(SimpleTech.notGate)}; + } + + @Override + public boolean canBlockStay(World world, int x, int y, int z) { + return !world.canPlaceOnSurfaceOfBlock(x, y - 1, z) ? false : super.canBlockStay(world, x, y, z); + } + + @Override + public void updateTick(World world, int x, int y, int z, Random rand) { + int metadata = world.getBlockMetadata(x, y, z); + boolean shouldPower = this.shouldPowerAdjacentBlocks(world, x, y, z, metadata); + if (this.isPowered && !shouldPower) { + world.setBlockAndMetadataWithNotify(x, y, z, SimpleTech.notGateIdle.id, metadata); + } else if (!this.isPowered) { + world.setBlockAndMetadataWithNotify(x, y, z, SimpleTech.notGateActive.id, metadata); + } + } + + @Override + public int getBlockTextureFromSideAndMetadata(Side side, int j) { + if (side == Side.BOTTOM) { + return !this.isPowered ? texCoordToIndex(3, 7) : texCoordToIndex(3, 6); + } else if (side == Side.TOP) { + return !this.isPowered ? texCoordToIndex(3, 8) : texCoordToIndex(3, 9); + } else { + return texCoordToIndex(5, 0); + } + } + + @Override + public boolean shouldSideBeRendered(WorldSource blockAccess, int x, int y, int z, int side) { + // Don't render bottom and top textures to avoid z-fighting with modified renderer. + return side != Side.BOTTOM.getId() && side != Side.TOP.getId(); + } + + @Override + public boolean isIndirectlyPoweringTo(World world, int x, int y, int z, int side) { + return this.isPoweringTo(world, x, y, z, side); + } + + @Override + public boolean isPoweringTo(WorldSource blockAccess, int x, int y, int z, int side) { + int direction = blockAccess.getBlockMetadata(x, y, z) & 3; + if (!this.isPowered) { + if (direction == Direction.EAST.getHorizontalIndex() && side == Side.EAST.getId()) { + return false; + } else if (direction == Direction.NORTH.getHorizontalIndex() && side == Side.NORTH.getId()) { + return false; + } else if (direction == Direction.SOUTH.getHorizontalIndex() && side == Side.SOUTH.getId()) { + return false; + } else if (direction == Direction.WEST.getHorizontalIndex() && side == Side.WEST.getId()) { + return false; + } else { + return true; + } + } else { + return false; + } + } + + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, int blockId) { + if (!this.canBlockStay(world, x, y, z)) { + this.dropBlockWithCause(world, EnumDropCause.WORLD, x, y, z, world.getBlockMetadata(x, y, z), null); + world.setBlockWithNotify(x, y, z, 0); + } else { + int metadata = world.getBlockMetadata(x, y, z); + boolean shouldPower = this.shouldPowerAdjacentBlocks(world, x, y, z, metadata); + if (this.isPowered && !shouldPower) { + world.scheduleBlockUpdate(x, y, z, this.id, 1); + } else if (!this.isPowered && shouldPower) { + world.scheduleBlockUpdate(x, y, z, this.id, 1); + } + } + } + + @Override + public boolean canProvidePower() { + return false; + } + + @Override + public void onBlockPlaced(World world, int x, int y, int z, Side side, EntityLiving entity, double sideHeight) { + int metadata = entity.getHorizontalPlacementDirection(side).getHorizontalIndex(); + world.setBlockMetadataWithNotify(x, y, z, metadata); + boolean shouldPower = this.shouldPowerAdjacentBlocks(world, x, y, z, metadata); + if (shouldPower) { + world.scheduleBlockUpdate(x, y, z, this.id, 1); + } + } + + @Override + public void onBlockAdded(World world, int i, int j, int k) { + world.notifyBlocksOfNeighborChange(i + 1, j, k, this.id); + world.notifyBlocksOfNeighborChange(i - 1, j, k, this.id); + world.notifyBlocksOfNeighborChange(i, j, k + 1, this.id); + world.notifyBlocksOfNeighborChange(i, j, k - 1, this.id); + world.notifyBlocksOfNeighborChange(i, j - 1, k, this.id); + world.notifyBlocksOfNeighborChange(i, j + 1, k, this.id); + } + + private boolean shouldPowerAdjacentBlocks(World world, int i, int j, int k, int metadata) { + int direction = metadata & 3; + switch (direction) { + case 0: + return world.isBlockIndirectlyProvidingPowerTo(i, j, k + 1, 3) || + world.getBlockId(i, j, k + 1) == Block.wireRedstone.id && + world.getBlockMetadata(i, j, k + 1) > 0; + case 1: + return world.isBlockIndirectlyProvidingPowerTo(i - 1, j, k, 4) || + world.getBlockId(i - 1, j, k) == Block.wireRedstone.id && + world.getBlockMetadata(i - 1, j, k) > 0; + case 2: + return world.isBlockIndirectlyProvidingPowerTo(i, j, k - 1, 2) || + world.getBlockId(i, j, k - 1) == Block.wireRedstone.id && + world.getBlockMetadata(i, j, k - 1) > 0; + case 3: + return world.isBlockIndirectlyProvidingPowerTo(i + 1, j, k, 5) || + world.getBlockId(i + 1, j, k) == Block.wireRedstone.id && + world.getBlockMetadata(i + 1, j, k) > 0; + default: + return false; + } + } +} diff --git a/src/main/java/ambos/simpletech/block/BlockTrappedChest.java b/src/main/java/ambos/simpletech/block/BlockTrappedChest.java @@ -0,0 +1,93 @@ +package ambos.simpletech.block; + +import net.minecraft.core.block.BlockChest; +import net.minecraft.core.block.material.Material; +import net.minecraft.core.entity.player.EntityPlayer; +import net.minecraft.core.sound.SoundType; +import net.minecraft.core.world.World; +import net.minecraft.core.world.WorldSource; + +import java.util.Random; + +import ambos.simpletech.SimpleTech; + +public class BlockTrappedChest extends BlockChest { + public static final int redstoneOffset = 4; + + public BlockTrappedChest(String key, int id, Material material) { + super(key, id, material); + this.withTexCoords(9, 1, 9, 1, 11, 1, 10, 1, 10, 1, 10, 1); + this.setTicking(true); + } + + @Override + public int tickRate() { + return 20; + } + + @Override + public boolean isSolidRender() { + return false; + } + + @Override + public boolean canProvidePower() { + return true; + } + + @Override + public boolean renderAsNormalBlock() { + return false; + } + + @Override + public boolean isPoweringTo(WorldSource blockAccess, int x, int y, int z, int side) { + return SimpleTech.getRedstoneFromMetadata(blockAccess.getBlockMetadata(x, y, z), redstoneOffset) > 0; + } + + @Override + public void onBlockRemoved(World world, int x, int y, int z, int data) { + if (SimpleTech.getRedstoneFromMetadata(world.getBlockMetadata(x, y, z), redstoneOffset) > 0) { + this.notifyNeighbors(world, x, y, z); + } + + super.onBlockRemoved(world, x, y, z, data); + } + + @Override + public boolean blockActivated(World world, int x, int y, int z, EntityPlayer player) { + this.setState(world, x, y, z, (byte) 1); + + world.scheduleBlockUpdate(x, y, z, this.id, this.tickRate()); + world.playSoundEffect(SoundType.GUI_SOUNDS,x + 0.5, y + 0.5, z + 0.5, + "random.click", 0.3f, 0.6f); + + return super.blockActivated(world, x, y, z, player); + } + + @Override + public void updateTick(World world, int x, int y, int z, Random rand) { + if (!world.isClientSide) { + if (SimpleTech.getRedstoneFromMetadata(world.getBlockMetadata(x, y, z), redstoneOffset) > 0) { + this.setState(world, x, y, z, (byte) 0); + } + } + } + + private void setState(World world, int x, int y, int z, byte redstone) { + int metadata = world.getBlockMetadata(x, y, z); + + // Recreates metadata using the redstone signal and the old metadata value. + world.setBlockMetadataWithNotify(x, y, z, SimpleTech.getMetaWithRedstone(metadata, redstone, redstoneOffset)); + + // Updates block's neighbors. + this.notifyNeighbors(world, x, y, z); + + world.markBlocksDirty(x, y, z, x, y, z); + } + + private void notifyNeighbors(World world, int x, int y, int z) { + world.notifyBlocksOfNeighborChange(x, y, z, this.id); + world.notifyBlocksOfNeighborChange(x, y - 1, z, this.id); + } +} diff --git a/src/main/java/ambos/simpletech/block/entity/TileEntityAllocator.java b/src/main/java/ambos/simpletech/block/entity/TileEntityAllocator.java @@ -0,0 +1,102 @@ +package ambos.simpletech.block.entity; + +import com.mojang.nbt.CompoundTag; +import com.mojang.nbt.ListTag; +import net.minecraft.core.block.entity.TileEntity; +import net.minecraft.core.entity.player.EntityPlayer; +import net.minecraft.core.item.ItemStack; +import net.minecraft.core.player.inventory.IInventory; + +public class TileEntityAllocator extends TileEntity implements IInventory { + private ItemStack allocatorFilterItem; + + @Override + public int getSizeInventory() { + return 1; + } + + @Override + public ItemStack getStackInSlot(int i) { + return i == 0 ? this.allocatorFilterItem : null; + } + + @Override + public ItemStack decrStackSize(int i, int j) { + if (i != 0) { + return null; + } else if (this.allocatorFilterItem != null) { + ItemStack itemstack; + if (this.allocatorFilterItem.stackSize <= j) { + itemstack = this.allocatorFilterItem; + this.allocatorFilterItem = null; + return itemstack; + } else { + itemstack = this.allocatorFilterItem.splitStack(j); + if (this.allocatorFilterItem.stackSize == 0) { + this.allocatorFilterItem = null; + } + + return itemstack; + } + } else { + return null; + } + } + + @Override + public void setInventorySlotContents(int i, ItemStack itemStack) { + if (i == 0) { + this.allocatorFilterItem = itemStack; + if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()) { + itemStack.stackSize = this.getInventoryStackLimit(); + } + } + } + + @Override + public String getInvName() { + return "Allocator"; + } + + @Override + public int getInventoryStackLimit() { + return 1; + } + + @Override + public boolean canInteractWith(EntityPlayer entityPlayer) { + return this.worldObj.getBlockTileEntity(this.x, this.y, this.z) == this && + entityPlayer.distanceToSqr((double) this.x + 0.5D, (double) this.y + 0.5D, + (double) this.z + 0.5D) <= 64.0D; + } + + @Override + public void sortInventory() {} + + @Override + public void readFromNBT(CompoundTag nbttagcompound) { + super.readFromNBT(nbttagcompound); + ListTag items = nbttagcompound.getList("Items"); + if (items.tagCount() != 0) { + CompoundTag item = (CompoundTag)items.tagAt(0); + int slot = item.getByte("Slot") & 255; + if(slot == 0) { + this.allocatorFilterItem = ItemStack.readItemStackFromNbt(item); + } + } + } + + @Override + public void writeToNBT(CompoundTag nbttagcompound) { + super.writeToNBT(nbttagcompound); + ListTag items = new ListTag(); + if (this.allocatorFilterItem != null) { + CompoundTag item = new CompoundTag(); + item.putByte("Slot", (byte)0); + this.allocatorFilterItem.writeToNBT(item); + items.addTag(item); + } + + nbttagcompound.put("Items", items); + } +} diff --git a/src/main/java/ambos/simpletech/block/entity/TileEntityFan.java b/src/main/java/ambos/simpletech/block/entity/TileEntityFan.java @@ -0,0 +1,97 @@ +package ambos.simpletech.block.entity; + +import net.minecraft.core.block.entity.TileEntity; +import net.minecraft.core.entity.Entity; +import net.minecraft.core.entity.EntityItem; +import net.minecraft.core.util.phys.AABB; +import net.minecraft.core.world.World; + +import java.util.List; + +import ambos.simpletech.SimpleTech; + +public class TileEntityFan extends TileEntity { + private final int range; + + public TileEntityFan(int range) { + this.range = range; + } + + public TileEntityFan() { + // Always define the default constructor when working with tile entities. + this(SimpleTech.FAN_RANGE); + } + + @Override + public void tick() { + if (worldObj.isBlockIndirectlyGettingPowered(x, y, z) || + worldObj.isBlockIndirectlyGettingPowered(x, y + 1, z)) { + this.blow(worldObj, x, y, z); + } + } + + private void blow(World world, int x, int y, int z) { + int dx = -SimpleTech.getDirectionX(world, x, y, z); + int dy = -SimpleTech.getDirectionY(world, x, y, z); + int dz = -SimpleTech.getDirectionZ(world, x, y, z); + + int px = x; + int py = y; + int pz = z; + + for (int i = 0; i < this.range; ++i) { + px += dx; + py += dy; + pz += dz; + + if (world.isBlockOpaqueCube(px, py, pz)) { + break; + } + + List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, AABB.getBoundingBoxFromPool( + px, py, pz, px + 1, py + 1, pz + 1) + ); + + for (Entity entity : entities) { + if (entity instanceof EntityItem) { + this.pushEntity(entity, dx, dy, dz); + } + } + } + } + + private void pushEntity(Entity entity, int dx, int dy, int dz) { + double maxspeed = 0.4; + double boost = 0.1; + + if (Math.abs(dx) != 0) { + if (entity.xd * (double) dx < 0.0) { + entity.xd = 0.0; + } + + if (entity.xd * (double) dx <= maxspeed) { + entity.xd += (double) dx * boost; + } + } else if (Math.abs(dy) != 0) { + if (entity.yd * (double) dy < 0.0) { + entity.yd = 0.0; + } + + if (dy > 0) { + boost *= 0.5; + } + + if (entity.yd * (double) dy <= maxspeed) { + entity.yd += (double) dy * boost; + } + } else if (Math.abs(dz) != 0) { + if (entity.zd * (double) dz < 0.0) { + entity.zd = 0.0; + } + + if (entity.zd * (double) dz <= maxspeed) { + entity.zd += (double) dz * boost; + } + } + } +} diff --git a/src/main/java/ambos/simpletech/block/entity/TileEntityLightSensor.java b/src/main/java/ambos/simpletech/block/entity/TileEntityLightSensor.java @@ -0,0 +1,39 @@ +package ambos.simpletech.block.entity; + +import ambos.simpletech.SimpleTech; +import ambos.simpletech.block.BlockLightSensor; +import net.minecraft.core.block.Block; +import net.minecraft.core.block.entity.TileEntity; + +public class TileEntityLightSensor extends TileEntity { + @Override + public void tick() { + // If the world object is valid... + if (worldObj != null && !worldObj.isClientSide) { + Block block = getBlockType(); + // If it's a light sensor... + if (block instanceof BlockLightSensor) { + BlockLightSensor lightSensor = ((BlockLightSensor) block); + boolean isDay = worldObj.isDaytime(); + boolean isPowered = SimpleTech.getRedstoneFromMetadata( + worldObj.getBlockMetadata(x, y, z), + BlockLightSensor.redstoneOffset) > 0; + boolean isInverted = lightSensor.isInverted(worldObj, x, y, z); + if (isInverted) { + // Daytime mode. + if (isDay && !isPowered) + // Sends redstone value. + lightSensor.updateSensor(worldObj, x, y, z, true); + if (!isDay && isPowered) + lightSensor.updateSensor(worldObj, x, y, z, false); + } else { + // Nighttime mode. + if (isDay && isPowered) + lightSensor.updateSensor(worldObj, x, y, z, false); + if (!isDay && !isPowered) + lightSensor.updateSensor(worldObj, x, y, z, true); + } + } + } + } +} diff --git a/src/main/java/ambos/simpletech/gui/GuiAllocator.java b/src/main/java/ambos/simpletech/gui/GuiAllocator.java @@ -0,0 +1,37 @@ +package ambos.simpletech.gui; + +import net.minecraft.client.gui.GuiContainer; +import net.minecraft.core.player.inventory.InventoryPlayer; +import org.lwjgl.opengl.GL11; + +import ambos.simpletech.block.entity.TileEntityAllocator; +import ambos.simpletech.player.inventory.ContainerAllocator; + +public class GuiAllocator extends GuiContainer { + private final TileEntityAllocator allocatorInv; + + public GuiAllocator(InventoryPlayer playerInventory, TileEntityAllocator allocator) { + super(new ContainerAllocator(playerInventory, allocator)); + this.allocatorInv = allocator; + } + + @Override + protected void drawGuiContainerForegroundLayer() { + this.fontRenderer.drawString("Allocator", 60, 6, 4210752); + this.fontRenderer.drawString("Inventory", 8, this.ySize - 96 + 2, 4210752); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float f) { + int i = this.mc.renderEngine.getTexture("/assets/simpletech/gui/allocator.png"); + + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + this.mc.renderEngine.bindTexture(i); + + int j = (this.width - this.xSize) / 2; + int k = (this.height - this.ySize) / 2; + + this.drawTexturedModalRect(j, k, 0, 0, this.xSize, this.ySize); + } +} diff --git a/src/main/java/ambos/simpletech/mixin/EntityItemMixin.java b/src/main/java/ambos/simpletech/mixin/EntityItemMixin.java @@ -0,0 +1,20 @@ +package ambos.simpletech.mixin; + +import net.minecraft.core.entity.EntityItem; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = EntityItem.class, remap = false) +final class EntityItemMixin { + @Inject(method = "clumpToNearbyStack", at = @At("HEAD"), + require = 0, cancellable = true) + private void removeItemEntityStacking(CallbackInfo ci) { + EntityItem currentEntityItem = (EntityItem) ((Object) this); + + if (!currentEntityItem.item.isStackable()) { + ci.cancel(); + } + } +} diff --git a/src/main/java/ambos/simpletech/mixin/EntityPlayerMPMixin.java b/src/main/java/ambos/simpletech/mixin/EntityPlayerMPMixin.java @@ -0,0 +1,36 @@ +package ambos.simpletech.mixin; + +import net.minecraft.core.entity.player.EntityPlayer; +import net.minecraft.core.net.packet.Packet100OpenWindow; +import net.minecraft.core.world.World; +import net.minecraft.server.entity.player.EntityPlayerMP; +import net.minecraft.server.net.handler.NetServerHandler; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import ambos.simpletech.IPlayerDisplayer; +import ambos.simpletech.SimpleTech; +import ambos.simpletech.block.entity.TileEntityAllocator; +import ambos.simpletech.player.inventory.ContainerAllocator; + +@Mixin(value = EntityPlayerMP.class, remap = false) +public abstract class EntityPlayerMPMixin extends EntityPlayer implements IPlayerDisplayer { + @Shadow protected abstract void getNextWindowId(); + + @Shadow public NetServerHandler playerNetServerHandler; + + @Shadow private int currentWindowId; + + public EntityPlayerMPMixin(World world) { + super(world); + } + + @Override + public void simple_tech$displayGUIAllocator(TileEntityAllocator allocator) { + this.getNextWindowId(); + this.playerNetServerHandler.sendPacket(new Packet100OpenWindow(this.currentWindowId, SimpleTech.ALLOCATOR_GUI_ID, allocator.getInvName(), allocator.getSizeInventory())); + this.craftingInventory = new ContainerAllocator(this.inventory, allocator); + this.craftingInventory.windowId = this.currentWindowId; + this.craftingInventory.onContainerInit((EntityPlayerMP)(Object)this); + } +} diff --git a/src/main/java/ambos/simpletech/mixin/EntityPlayerMixin.java b/src/main/java/ambos/simpletech/mixin/EntityPlayerMixin.java @@ -0,0 +1,15 @@ +package ambos.simpletech.mixin; + +import net.minecraft.core.entity.player.EntityPlayer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +import ambos.simpletech.IPlayerDisplayer; +import ambos.simpletech.block.entity.TileEntityAllocator; + +@Mixin(value = EntityPlayer.class, remap = false) +public class EntityPlayerMixin implements IPlayerDisplayer { + @Unique + public void simple_tech$displayGUIAllocator(TileEntityAllocator allocator) { + } +} diff --git a/src/main/java/ambos/simpletech/mixin/EntityPlayerSPMixin.java b/src/main/java/ambos/simpletech/mixin/EntityPlayerSPMixin.java @@ -0,0 +1,28 @@ +package ambos.simpletech.mixin; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.player.EntityPlayerSP; +import net.minecraft.core.entity.player.EntityPlayer; +import net.minecraft.core.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import ambos.simpletech.IPlayerDisplayer; +import ambos.simpletech.block.entity.TileEntityAllocator; +import ambos.simpletech.gui.GuiAllocator; + +@Mixin(value = EntityPlayerSP.class, remap = false) +public abstract class EntityPlayerSPMixin extends EntityPlayer implements IPlayerDisplayer { + @Shadow protected Minecraft mc; + + public EntityPlayerSPMixin(World world) { + super(world); + } + + @Override + public void simple_tech$displayGUIAllocator(TileEntityAllocator allocator) { + if (allocator != null){ + this.mc.displayGuiScreen(new GuiAllocator(inventory, allocator)); + } + } +} diff --git a/src/main/java/ambos/simpletech/mixin/NetClientHandlerMixin.java b/src/main/java/ambos/simpletech/mixin/NetClientHandlerMixin.java @@ -0,0 +1,31 @@ +package ambos.simpletech.mixin; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.net.handler.NetClientHandler; +import net.minecraft.core.net.packet.Packet100OpenWindow; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import ambos.simpletech.IPlayerDisplayer; +import ambos.simpletech.SimpleTech; +import ambos.simpletech.block.entity.TileEntityAllocator; + +@Mixin(value = NetClientHandler.class, remap = false) +public class NetClientHandlerMixin { + @Final + @Shadow private Minecraft mc; + + @Inject(method = "handleOpenWindow(Lnet/minecraft/core/net/packet/Packet100OpenWindow;)V", at = @At("HEAD"), cancellable = true) + public void handleAllocator(Packet100OpenWindow packet100openwindow, CallbackInfo ci){ + if (packet100openwindow.inventoryType == SimpleTech.ALLOCATOR_GUI_ID) { + TileEntityAllocator tileEntityAllocator = new TileEntityAllocator(); + ((IPlayerDisplayer)this.mc.thePlayer).simple_tech$displayGUIAllocator(tileEntityAllocator); + this.mc.thePlayer.craftingInventory.windowId = packet100openwindow.windowId; + ci.cancel(); + } + } +} diff --git a/src/main/java/ambos/simpletech/mixin/RenderBlocksMixin.java b/src/main/java/ambos/simpletech/mixin/RenderBlocksMixin.java @@ -0,0 +1,115 @@ +package ambos.simpletech.mixin; + +import net.minecraft.client.render.RenderBlocks; +import net.minecraft.client.render.Tessellator; +import net.minecraft.client.render.TextureFX; +import net.minecraft.core.Global; +import net.minecraft.core.block.Block; +import net.minecraft.core.util.helper.Side; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import ambos.simpletech.block.BlockAllocator; +import ambos.simpletech.block.BlockFan; +import ambos.simpletech.block.BlockRedstoneNotGate; + +@Mixin(value = RenderBlocks.class, remap = false) +final class RenderBlocksMixin { + @Redirect(method = "renderBlockOnInventory(Lnet/minecraft/core/block/Block;IFF)V", at = @At(value = "INVOKE", + target = "Lnet/minecraft/core/block/Block;getBlockTextureFromSideAndMetadata(Lnet/minecraft/core/util/helper/Side;I)I"), + require = 0) + private int changeBlockInventoryRender(Block block, Side side, int meta) { + if (block instanceof BlockFan) { + if (side == Side.SOUTH) { + return block.atlasIndices[Side.SOUTH.getId()]; // Returns front texture. + } + + if (side == Side.BOTTOM) { + return block.atlasIndices[Side.TOP.getId()]; // Returns top/bottom texture. + } + } + + if (block instanceof BlockAllocator) { + if (side == Side.TOP || side == Side.BOTTOM) { + return block.atlasIndices[Side.WEST.getId()]; // Returns top/bottom texture. + } + + if (side == Side.SOUTH) { + return block.atlasIndices[Side.SOUTH.getId()]; // Returns front texture. + } + + if (side == Side.NORTH) { + return block.atlasIndices[Side.NORTH.getId()]; // Returns back texture. + } + } + + return block.getBlockTextureFromSideAndMetadata(side, meta); + } + + @ModifyVariable(method = "renderBlockByRenderType", at = @At("HEAD"), ordinal = 0, require = 0) + private int changeRenderType(int renderType, Block block) { + if (block instanceof BlockRedstoneNotGate) { + return 15; // Use the repeater renderer as a base. + } + + return renderType; + } + + @Inject(method = "renderBlockRepeater", at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/render/Tessellator;setColorOpaque_F(FFF)V", shift = At.Shift.AFTER), + locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true, require = 0) + private void renderBlockRedstoneGate(Block block, int i, int j, int k, CallbackInfoReturnable<Boolean> cir, + int l, int i1, int j1, Tessellator tessellator) { + if (block instanceof BlockRedstoneNotGate) { + /* Gets metadata, tesselator and block brightness (captures locals). */ + + /* Skips torch rendering instructions (injects just after 'setColorOpaque_F' method call). */ + + int k1 = block.getBlockTextureFromSideAndMetadata(Side.TOP, l); + int l1 = k1 % Global.TEXTURE_ATLAS_WIDTH_TILES * TextureFX.tileWidthTerrain; + int i2 = k1 / Global.TEXTURE_ATLAS_WIDTH_TILES * TextureFX.tileWidthTerrain; + double d5 = (double)((float)l1 / (float)(TextureFX.tileWidthTerrain * Global.TEXTURE_ATLAS_WIDTH_TILES)); + double d6 = (double)(((float)l1 + ((float)TextureFX.tileWidthTerrain - 0.01F)) / (float)(TextureFX.tileWidthTerrain * Global.TEXTURE_ATLAS_WIDTH_TILES)); + double d7 = (double)((float)i2 / (float)(TextureFX.tileWidthTerrain * Global.TEXTURE_ATLAS_WIDTH_TILES)); + double d8 = (double)(((float)i2 + ((float)TextureFX.tileWidthTerrain - 0.01F)) / (float)(TextureFX.tileWidthTerrain * Global.TEXTURE_ATLAS_WIDTH_TILES)); + float f1 = 0.125F; + float f2 = (float)(i + 1); + float f3 = (float)(i + 1); + float f4 = (float)(i + 0); + float f5 = (float)(i + 0); + float f6 = (float)(k + 0); + float f7 = (float)(k + 1); + float f8 = (float)(k + 1); + float f9 = (float)(k + 0); + float f10 = (float)j + f1; + if (i1 == 2) { + f2 = f3 = (float)(i + 0); + f4 = f5 = (float)(i + 1); + f6 = f9 = (float)(k + 1); + f7 = f8 = (float)(k + 0); + } else if (i1 == 3) { + f2 = f5 = (float)(i + 0); + f3 = f4 = (float)(i + 1); + f6 = f7 = (float)(k + 0); + f8 = f9 = (float)(k + 1); + } else if (i1 == 1) { + f2 = f5 = (float)(i + 1); + f3 = f4 = (float)(i + 0); + f6 = f7 = (float)(k + 1); + f8 = f9 = (float)(k + 0); + } + + tessellator.addVertexWithUV((double)f5, (double)f10, (double)f9, d5, d7); + tessellator.addVertexWithUV((double)f4, (double)f10, (double)f8, d5, d8); + tessellator.addVertexWithUV((double)f3, (double)f10, (double)f7, d6, d8); + tessellator.addVertexWithUV((double)f2, (double)f10, (double)f6, d6, d7); + + cir.setReturnValue(true); + } + } +} diff --git a/src/main/java/ambos/simpletech/player/inventory/ContainerAllocator.java b/src/main/java/ambos/simpletech/player/inventory/ContainerAllocator.java @@ -0,0 +1,48 @@ +package ambos.simpletech.player.inventory; + +import net.minecraft.core.InventoryAction; +import net.minecraft.core.entity.player.EntityPlayer; +import net.minecraft.core.player.inventory.Container; +import net.minecraft.core.player.inventory.IInventory; +import net.minecraft.core.player.inventory.slot.Slot; + +import java.util.List; + +import ambos.simpletech.block.entity.TileEntityAllocator; + +public class ContainerAllocator extends Container { + private final TileEntityAllocator allocator; + + public ContainerAllocator(IInventory playerInventory, TileEntityAllocator allocator) { + this.allocator = allocator; + + // Adding allocator slot. + this.addSlot(new Slot(allocator, 0, 80, 36)); + + // Adding player inventory slots. + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 9; ++j) { + this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + } + } + + for(int i = 0; i < 9; ++i) { + this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 142)); + } + } + + @Override + public boolean isUsableByPlayer(EntityPlayer entityPlayer) { + return this.allocator.canInteractWith(entityPlayer); + } + + @Override + public List<Integer> getMoveSlots(InventoryAction inventoryAction, Slot slot, int i, EntityPlayer entityPlayer) { + return null; + } + + @Override + public List<Integer> getTargetSlots(InventoryAction inventoryAction, Slot slot, int i, EntityPlayer entityPlayer) { + return null; + } +} diff --git a/src/main/java/turniplabs/simpletech/IPlayerDisplayer.java b/src/main/java/turniplabs/simpletech/IPlayerDisplayer.java @@ -1,7 +0,0 @@ -package turniplabs.simpletech; - -import turniplabs.simpletech.block.entity.TileEntityAllocator; - -public interface IPlayerDisplayer { - void simple_tech$displayGUIAllocator(TileEntityAllocator allocator); -} diff --git a/src/main/java/turniplabs/simpletech/SimpleTech.java b/src/main/java/turniplabs/simpletech/SimpleTech.java @@ -1,241 +0,0 @@ -package turniplabs.simpletech; - -import net.minecraft.client.sound.block.BlockSounds; -import net.minecraft.core.block.Block; -import net.minecraft.core.block.material.Material; -import net.minecraft.core.block.tag.BlockTags; -import net.minecraft.core.item.Item; -import net.minecraft.core.item.ItemPlaceable; -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.EntityHelper; -import turniplabs.halplibe.helper.ItemHelper; -import turniplabs.halplibe.util.GameStartEntrypoint; -import turniplabs.halplibe.util.TomlConfigHandler; -import turniplabs.halplibe.util.toml.Toml; -import turniplabs.simpletech.block.BlockAllocator; -import turniplabs.simpletech.block.BlockFan; -import turniplabs.simpletech.block.BlockJumpPad; -import turniplabs.simpletech.block.BlockLightSensor; -import turniplabs.simpletech.block.BlockRedstoneNotGate; -import turniplabs.simpletech.block.BlockTrappedChest; -import turniplabs.simpletech.block.entity.TileEntityAllocator; -import turniplabs.simpletech.block.entity.TileEntityFan; -import turniplabs.simpletech.block.entity.TileEntityLightSensor; - -public class SimpleTech implements GameStartEntrypoint { - public static final String MOD_ID = "simpletech"; - public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); - public static final TomlConfigHandler config; - public static final int FAN_RANGE; - public static final int UNPOWERED_FAN_ID; - public static final int POWERED_FAN_ID; - public static final int JUMP_PAD_ID; - public static final int TRAPPED_CHEST_ID; - public static final int LIGHT_SENSOR_ID; - public static final int ALLOCATOR_ID; - public static final int ALLOCATOR_GUI_ID; - public static final int NOT_GATE_IDLE_ID; - public static final int NOT_GATE_ACTIVE_ID; - public static final int NOT_GATE_ID; - static { - Toml configToml = new Toml(); - configToml.addCategory("BlockIDs"); - configToml.addEntry("BlockIDs.UNPOWERED_FAN_ID", 3789); - configToml.addEntry("BlockIDs.POWERED_FAN_ID", 3790); - configToml.addEntry("BlockIDs.JUMP_PAD_ID", 3791); - configToml.addEntry("BlockIDs.TRAPPED_CHEST_ID", 3792); - configToml.addEntry("BlockIDs.LIGHT_SENSOR_ID", 3793); - configToml.addEntry("BlockIDs.ALLOCATOR_ID", 3794); - configToml.addEntry("BlockIDs.NOT_GATE_IDLE_ID", 3795); - configToml.addEntry("BlockIDs.NOT_GATE_ACTIVE_ID", 3796); - configToml.addCategory("ItemIDs"); - configToml.addEntry("ItemIDs.NOT_GATE_ID", 28890); - configToml.addCategory("Settings"); - configToml.addEntry("Settings.FAN_RANGE", 4); - configToml.addCategory("GUI"); - configToml.addEntry("GUI.ALLOCATOR_GUI_ID", 13); - - config = new TomlConfigHandler(MOD_ID, configToml); - FAN_RANGE = config.getInt("Settings.FAN_RANGE"); - UNPOWERED_FAN_ID = config.getInt("BlockIDs.UNPOWERED_FAN_ID"); - POWERED_FAN_ID = config.getInt("BlockIDs.POWERED_FAN_ID"); - JUMP_PAD_ID = config.getInt("BlockIDs.JUMP_PAD_ID"); - TRAPPED_CHEST_ID = config.getInt("BlockIDs.TRAPPED_CHEST_ID"); - LIGHT_SENSOR_ID = config.getInt("BlockIDs.LIGHT_SENSOR_ID"); - ALLOCATOR_ID = config.getInt("BlockIDs.ALLOCATOR_ID"); - ALLOCATOR_GUI_ID = config.getInt("GUI.ALLOCATOR_GUI_ID"); - NOT_GATE_IDLE_ID = config.getInt("BlockIDs.NOT_GATE_IDLE_ID"); - NOT_GATE_ACTIVE_ID = config.getInt("BlockIDs.NOT_GATE_ACTIVE_ID"); - NOT_GATE_ID = config.getInt("ItemIDs.NOT_GATE_ID"); - } - - - // Builders - public static final BlockBuilder stoneBlockBuilder = new BlockBuilder(MOD_ID) - .setHardness(1.5f) - .setResistance(10.0f) - .setLuminance(0) - .setBlockSound(BlockSounds.STONE) - .setTags(BlockTags.MINEABLE_BY_PICKAXE); - public static final BlockBuilder fanBuilder = stoneBlockBuilder - .setTopBottomTexture("misc_top_bottom.png") - .setEastTexture("misc_side.png") - .setWestTexture("misc_side.png") - .setNorthTexture("misc_side.png"); - public static final BlockBuilder woodenBlockBuilder = new BlockBuilder(MOD_ID) - .setHardness(1.0f) - .setResistance(2.5f) - .setLuminance(0) - .setBlockSound(BlockSounds.WOOD) - .setTags(BlockTags.MINEABLE_BY_AXE); - public static final BlockBuilder gateBlockBuilder = new BlockBuilder(MOD_ID) - .setHardness(0.0f) - .setResistance(0.0f) - .setLuminance(0) - .setBlockSound(BlockSounds.STONE) - .setTags(BlockTags.MINEABLE_BY_AXE, BlockTags.BROKEN_BY_FLUIDS, BlockTags.NOT_IN_CREATIVE_MENU, BlockTags.PREVENT_MOB_SPAWNS); - - // Blocks - public static final Block unpoweredFan = fanBuilder - .setSouthTexture("fan_front.png") - .build(new BlockFan("fan.unpowered", UNPOWERED_FAN_ID, Material.stone, false)); - public static final Block poweredFan = fanBuilder - .setSouthTexture("fan_front_powered.png") - .setTags(BlockTags.NOT_IN_CREATIVE_MENU) - .build(new BlockFan("fan.powered", POWERED_FAN_ID, Material.stone, true)); - public static final Block jumpPad = woodenBlockBuilder - .setTextures("jump_pad.png") - .build(new BlockJumpPad("jumppad", JUMP_PAD_ID, Material.wood)); - public static final Block trappedChest = woodenBlockBuilder - .setHardness(2.5f) - .setResistance(5.0f) - .setTags(BlockTags.MINEABLE_BY_AXE, BlockTags.FENCES_CONNECT) - .setTickOnLoad() - .build(new BlockTrappedChest("chest.trapped", TRAPPED_CHEST_ID, Material.wood)); - public static final Block lightSensor = woodenBlockBuilder - .setTextures("light_sensor.png") - .build(new BlockLightSensor("lightsensor", LIGHT_SENSOR_ID, Material.wood)); - public static final Block allocator = stoneBlockBuilder - .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") - .build(new BlockAllocator("allocator", ALLOCATOR_ID, Material.stone, true, true)); - public static final Block notGateIdle = gateBlockBuilder - .setTopTexture("gate_top.png") - .setNorthTexture("gate_top.png") - .setEastTexture("gate_top.png") - .setWestTexture("gate_top.png") - .setSouthTexture("gate_top.png") - .setBottomTexture("gate_top.png") - .build(new BlockRedstoneNotGate("not.gate.idle", NOT_GATE_IDLE_ID, Material.decoration, false)); - public static final Block notGateActive = gateBlockBuilder - .setTopTexture("gate_top_powered.png") - .setNorthTexture("gate_top_powered.png") - .setEastTexture("gate_top_powered.png") - .setWestTexture("gate_top_powered.png") - .setSouthTexture("gate_top_powered.png") - .setBottomTexture("gate_top_powered.png") - .build(new BlockRedstoneNotGate("not.gate.active", NOT_GATE_ACTIVE_ID, Material.decoration, true)); - - // Items - public static final Item notGate = ItemHelper.createItem(MOD_ID, new ItemPlaceable("not.gate", NOT_GATE_ID, notGateIdle), "not.gate", "not_logicate.png"); - - @Override - public void beforeGameStart() { - // Entities. - EntityHelper.Core.createTileEntity(TileEntityFan.class, "Fan"); - EntityHelper.Core.createTileEntity(TileEntityLightSensor.class, "Light Sensor"); - EntityHelper.Core.createTileEntity(TileEntityAllocator.class, "Allocator"); - LOGGER.info("Simple Tech initialized"); - } - - @Override - public void afterGameStart() { - - } - - public static int setBit(int number, int position, int bit) { - int mask = 1 << position; - return (number & ~mask) | ((bit << position) & mask); - } - - public static int getBit(int number, int offset) { - return (number >> offset) & 1; - } - - public static int getRedstoneFromMetadata(int metadata, int redstoneOffset) { - return getBit(metadata, redstoneOffset); - } - - public static int getInvertedFromMetadata(int metadata, int invertedOffset) { - return getBit(metadata, invertedOffset); - } - - public static int getMetaWithRedstone(int metadata, int redstone, int redstoneOffset) { - return setBit(metadata, redstoneOffset, redstone); - } - - public static int getMetaWithInverted(int metadata, int inverted, int invertedOffset) { - return setBit(metadata, invertedOffset, inverted); - } - - public static int get3DDirectionFromMeta(int metadata) { - return metadata & 7; - } - - public static int getOppositeDirectionById(int i) { - return Direction.getDirectionById(i).getOpposite().getId(); - } - - public static int getDirectionX(World world, int x, int y, int z) { - int direction = world.getBlockMetadata(x, y, z); - int dx = 0; - - if (direction == Direction.WEST.getId()) { - dx = 1; - } - - if (direction == Direction.EAST.getId()) { - dx = -1; - } - - return dx; - } - - public static int getDirectionY(World world, int x, int y, int z) { - int direction = world.getBlockMetadata(x, y, z); - int dy = 0; - - if (direction == Direction.DOWN.getId()) { - dy = 1; - } - - if (direction == Direction.UP.getId()) { - dy = -1; - } - - return dy; - } - - public static int getDirectionZ(World world, int x, int y, int z) { - int direction = world.getBlockMetadata(x, y, z); - int dz = 0; - - if (direction == Direction.NORTH.getId()) { - dz = 1; - } - - if (direction == Direction.SOUTH.getId()) { - dz = -1; - } - - return dz; - } -} diff --git a/src/main/java/turniplabs/simpletech/SimpleTechRecipes.java b/src/main/java/turniplabs/simpletech/SimpleTechRecipes.java @@ -1,22 +0,0 @@ -package turniplabs.simpletech; - -import net.minecraft.core.block.Block; -import net.minecraft.core.data.DataLoader; -import net.minecraft.core.data.registry.Registries; -import net.minecraft.core.data.registry.recipe.RecipeGroup; -import net.minecraft.core.data.registry.recipe.RecipeNamespace; -import net.minecraft.core.data.registry.recipe.RecipeSymbol; -import net.minecraft.core.data.registry.recipe.entry.RecipeEntryCrafting; -import net.minecraft.core.item.ItemStack; -import turniplabs.halplibe.util.RecipeEntrypoint; - -public class SimpleTechRecipes implements RecipeEntrypoint { - public static final RecipeNamespace SIMPLE_TECH = new RecipeNamespace(); - public static final RecipeGroup<RecipeEntryCrafting<?, ?>> WORKBENCH = new RecipeGroup<>(new RecipeSymbol(new ItemStack(Block.workbench))); - @Override - public void onRecipesReady() { - SIMPLE_TECH.register("workbench", WORKBENCH); - Registries.RECIPES.register("simpletech", SIMPLE_TECH); - DataLoader.loadRecipes("/assets/simpletech/recipes/workbench.json"); - } -} diff --git a/src/main/java/turniplabs/simpletech/block/BlockAllocator.java b/src/main/java/turniplabs/simpletech/block/BlockAllocator.java @@ -1,359 +0,0 @@ -package turniplabs.simpletech.block; - -import net.minecraft.core.block.Block; -import net.minecraft.core.block.BlockTileEntity; -import net.minecraft.core.block.entity.TileEntity; -import net.minecraft.core.block.entity.TileEntityChest; -import net.minecraft.core.block.entity.TileEntityFurnace; -import net.minecraft.core.block.material.Material; -import net.minecraft.core.entity.Entity; -import net.minecraft.core.entity.EntityItem; -import net.minecraft.core.entity.EntityLiving; -import net.minecraft.core.entity.player.EntityPlayer; -import net.minecraft.core.entity.vehicle.EntityMinecart; -import net.minecraft.core.item.ItemStack; -import net.minecraft.core.player.inventory.IInventory; -import net.minecraft.core.player.inventory.InventoryLargeChest; -import net.minecraft.core.sound.SoundType; -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.simpletech.IPlayerDisplayer; -import turniplabs.simpletech.SimpleTech; -import turniplabs.simpletech.block.entity.TileEntityAllocator; - -import java.util.List; -import java.util.Random; - -public class BlockAllocator extends BlockTileEntity { - private final boolean allowFiltering; - private final boolean subItemFiltering; - - public BlockAllocator(String key, int id, Material material, boolean allowFiltering, boolean subItemFiltering) { - super(key, id, material); - this.allowFiltering = allowFiltering; - this.subItemFiltering = subItemFiltering; - } - - @Override - protected TileEntity getNewBlockEntity() { - return new TileEntityAllocator(); - } - - @Override - public boolean blockActivated(World world, int x, int y, int z, EntityPlayer player) { - if (!this.allowFiltering) { - return false; - } else if (world.isClientSide) { - return true; - } else { - TileEntityAllocator allocator = (TileEntityAllocator) world.getBlockTileEntity(x, y, z); - ((IPlayerDisplayer)player).simple_tech$displayGUIAllocator(allocator); - return true; - } - } - - @Override - public void updateTick(World world, int x, int y, int z, Random rand) { - if (world.isBlockIndirectlyGettingPowered(x, y, z) || world.isBlockIndirectlyGettingPowered(x, y + 1, z)) { - this.allocateItems(world, x, y, z, rand); - } - } - - @Override - public void onNeighborBlockChange(World world, int x, int y, int z, int blockId) { - if (blockId > 0 && Block.blocksList[blockId].canProvidePower() && - (world.isBlockIndirectlyGettingPowered(x, y, z) || - world.isBlockIndirectlyGettingPowered(x, y + 1, z))) { - world.scheduleBlockUpdate(x, y, z, this.id, this.tickRate()); - } - } - - @Override - public int tickRate() { - return 1; - } - - @Override - public void onBlockAdded(World world, int x, int y, int z) { - super.onBlockAdded(world, x, y, z); - } - - @Override - public int getBlockTextureFromSideAndMetadata(Side side, int meta) { - int direction = SimpleTech.get3DDirectionFromMeta(meta); - - if (direction > 5) { - 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 this.atlasIndices[Side.TOP.getId()]; // Returns back top/bottom texture. - } - 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 this.atlasIndices[Side.BOTTOM.getId()]; // Returns front top/bottom texture. - } - return this.atlasIndices[Side.SOUTH.getId()]; // Returns front texture. - } else { - if (side.getId() == Side.TOP.getId() || side.getId() == Side.BOTTOM.getId()) { - return this.atlasIndices[Side.WEST.getId()]; // Returns top/bottom texture. - } else { - return this.atlasIndices[Side.EAST.getId()]; // Returns side texture. - } - } - } - - @Override - public void onBlockPlaced(World world, int x, int y, int z, Side side, EntityLiving entity, double sideHeight) { - Direction placementDirection = entity.getPlacementDirection(side).getOpposite(); - world.setBlockMetadataWithNotify(x, y, z, placementDirection.getId()); - } - - public int getRandomItemFromContainer(IInventory inventory, Random rand, World world, int x, int y, int z) { - if (inventory == null) { - return -1; - } else { - int i = -1; - int j = 1; - - byte startAt = 0; - - if (inventory instanceof TileEntityFurnace) { - startAt = 2; - } - - for (int k = startAt; k < inventory.getSizeInventory(); ++k) { - if (inventory.getStackInSlot(k) != null && this.passesFilter(world, x, y, z, - inventory.getStackInSlot(k)) && rand.nextInt(j) == 0) { - i = k; - ++j; - } - } - - return i; - } - } - - protected IInventory containerAtPos(World world, int x, int y, int z) { - TileEntity tile = world.getBlockTileEntity(x, y, z); - return !(tile instanceof IInventory) ? null : this.getDoubleChest(world, x, y, z); - } - - protected boolean blockingCubeAtPos(World world, int x, int y, int z) { - int blockID = world.getBlockId(x, y, z); - boolean isOpaque = Block.translucent[blockID]; - - return isOpaque || blockID == Block.glass.id || - blockID == Block.cactus.id || - blockID == Block.cake.id || - blockID == Block.blockSnow.id || - blockID == Block.mobspawner.id || - blockID == Block.fencePlanksOak.id; - } - - private void putItemInContainer(IInventory inventory, ItemStack item, int index) { - if (item != null) { - if (index >= 0) { - ItemStack stack = inventory.getStackInSlot(index); - - if (stack != null) { - stack.stackSize += item.stackSize; - inventory.setInventorySlotContents(index, stack); - } else { - inventory.setInventorySlotContents(index, item); - } - } - } - } - - private void dispenseItem(World world, int x, int y, int z, int dx, int dy, int dz, ItemStack item, Random rand) { - double d = (double) x + (double) dx * 0.5D + 0.5D; - double d1 = (double) y + (double) dy * 0.5D + 0.5D; - double d2 = (double) z + (double) dz * 0.5D + 0.5D; - double d3 = rand.nextDouble() * 0.1D + 0.2D; - - EntityItem entityItem = new EntityItem(world, d, d1, d2, item); - - // Item movement. - entityItem.xd = (double) dx * d3; - entityItem.yd = (double) dy * d3; - entityItem.zd = (double) dz * d3; - entityItem.xd += rand.nextGaussian() * (double) 0.0075F * 6.0D; - entityItem.yd += rand.nextGaussian() * (double) 0.0075F * 6.0D; - entityItem.xd += rand.nextGaussian() * (double) 0.0075F * 6.0D; - - world.entityJoinedWorld(entityItem); - world.playSoundEffect(SoundType.GUI_SOUNDS, x, y, z, "random.click", 1.0f, 1.0f); - - // Particle rendering. - for (int i = 0; i < 10; ++i) { - double d4 = rand.nextDouble() * 0.2D + 0.01D; - double d5 = d + (double) dx * 0.01D + (rand.nextDouble() - 0.5D) * (double) dz * 0.5D; - double d6 = d1 + (rand.nextDouble() - 0.5D) * 0.5D; - double d7 = d2 + (double) dz * 0.01D + (rand.nextDouble() - 0.5D) * (double) dx * 0.5D; - double d8 = (double) dx * d4 + rand.nextGaussian() * 0.01D; - double d9 = -0.03D + rand.nextGaussian() * 0.01D; - double d10 = (double) dz * d4 + rand.nextGaussian() * 0.01D; - - world.spawnParticle("smoke", d5, d6, d7, d8, d9, d10); - } - } - - private boolean outputItem(World world, int x, int y, int z, int dx, int dy, int dz, ItemStack item, Random rand) { - IInventory outputContainer = this.containerAtPos(world, x + dx, y + dy, z + dz); - - if (outputContainer == null) { - List<Entity> index = world.getEntitiesWithinAABB(IInventory.class, AABB.getBoundingBoxFromPool( - x + dx, y + dy, z + dz, x + dx + 1, y + dy + 1, z + dz + 1)); - - if (!index.isEmpty() && (!(index.get(0) instanceof EntityMinecart) || - ((EntityMinecart) index.get(0)).minecartType == 1)) { - outputContainer = (IInventory) index.get(0); - } - } - - if (outputContainer == null) { - if (!this.blockingCubeAtPos(world, x + dx, y + dy, z + dz)) { - this.dispenseItem(world, x, y, z, dx, dy, dz, item, rand); - - return true; - } - } else { - int index1 = this.getFirstFreeInventorySlotOfKind(outputContainer, item); - - if (index1 >= 0) { - this.putItemInContainer(outputContainer, item, index1); - return true; - } - } - - return false; - } - - private IInventory getDoubleChest(World world, int x, int y, int z) { - TileEntity tileEntity = world.getBlockTileEntity(x, y, z); - if (!(tileEntity instanceof TileEntityChest)) { - return tileEntity instanceof IInventory ? (IInventory) tileEntity : null; - } else { - int blockId = world.getBlockId(x, y, z); - - IInventory chest1 = (IInventory) world.getBlockTileEntity(x, y, z); - IInventory chest2; - - if (world.getBlockId(x + 1, y, z) == blockId) { - chest2 = (IInventory) world.getBlockTileEntity(x + 1, y, z); - - return new InventoryLargeChest("", chest1, chest2); - } else if (world.getBlockId(x - 1, y, z) == blockId) { - chest2 = (IInventory) world.getBlockTileEntity(x - 1, y, z); - - return new InventoryLargeChest("", chest2, chest1); - } else if (world.getBlockId(x, y, z + 1) == blockId) { - chest2 = (IInventory) world.getBlockTileEntity(x, y, z + 1); - - return new InventoryLargeChest("", chest1, chest2); - } else if (world.getBlockId(x, y, z - 1) == blockId) { - chest2 = (IInventory) world.getBlockTileEntity(x, y, z - 1); - - return new InventoryLargeChest("", chest2, chest1); - } else { - return chest1; - } - } - } - - private void allocateItems(World world, int x, int y, int z, Random rand) { - int dx = SimpleTech.getDirectionX(world, x, y, z); - int dy = SimpleTech.getDirectionY(world, x, y, z); - int dz = SimpleTech.getDirectionZ(world, x, y, z); - - IInventory inputContainer = this.containerAtPos(world, x - dx, y - dy, z - dz); - - List<Entity> entities; - - if (inputContainer == null) { - entities = world.getEntitiesWithinAABB(IInventory.class, AABB.getBoundingBoxFromPool( - x - dx, y - dy, z - dz, x - dx + 1, y - dy + 1, z - dz + 1)); - - if (!entities.isEmpty() && (!(entities.get(0) instanceof EntityMinecart) || - ((EntityMinecart)entities.get(0)).minecartType == 1)) { - inputContainer = (IInventory) entities.get(0); - } - } - - int itemIndex; - if (inputContainer == null) { - entities = world.getEntitiesWithinAABB(EntityItem.class, AABB.getBoundingBoxFromPool( - x - dx, y - dy, z - dz, x - dx + 1, y - dy + 1, z - dz + 1)); - - for (itemIndex = 0; itemIndex < entities.size(); ++itemIndex) { - if (entities.get(itemIndex) instanceof EntityItem) { - EntityItem itemType = (EntityItem) entities.get(itemIndex); - - if (itemType.isAlive() && this.passesFilter(world, x, y, z, itemType.item) && - this.outputItem(world, x, y, z, dx, dy, dz, itemType.item, rand)) { - itemType.outOfWorld(); - } - } - } - } else { - itemIndex = this.getRandomItemFromContainer(inputContainer, rand, world, x, y, z); - - if (itemIndex >= 0) { - int itemDamage = inputContainer.getStackInSlot(itemIndex).getItemDamageForDisplay(); - - ItemStack item = new ItemStack(inputContainer.getStackInSlot(itemIndex) - .getItem(), 1, itemDamage); - - if (this.outputItem(world, x, y, z, dx, dy, dz, item, rand)) { - inputContainer.decrStackSize(itemIndex, 1); - } - } - } - } - - private int getFirstFreeInventorySlotOfKind(IInventory inventory, ItemStack item) { - int inventorySize = inventory.getSizeInventory(); - - if (inventory instanceof TileEntityFurnace) { - --inventorySize; - } - - for (int i = 0; i < inventorySize; ++i) { - boolean canStack = false; - - if (inventory.getStackInSlot(i) != null && inventory.getStackInSlot(i).itemID == item.itemID && - (!item.getItem().getHasSubtypes() || - inventory.getStackInSlot(i).getItemDamageForDisplay() == item.getItemDamageForDisplay())) { - canStack = inventory.getStackInSlot(i).stackSize <= item.getMaxStackSize() - item.stackSize; - } - - if (inventory.getStackInSlot(i) == null || canStack) { - return i; - } - } - - return -1; - } - - private boolean passesFilter(World world, int x, int y, int z, ItemStack item) { - if (!this.allowFiltering) { - return true; - } else { - TileEntityAllocator tileentityallocator = (TileEntityAllocator)world.getBlockTileEntity(x, y, z); - ItemStack filterItem = tileentityallocator.getStackInSlot(0); - if (filterItem == null) { - return true; - } else { - boolean filterSubItems = true; - if (this.subItemFiltering) { - filterSubItems = filterItem.getItemDamageForDisplay() == item.getItemDamageForDisplay(); - } - - return filterItem.itemID == item.getItem().id && filterSubItems; - } - } - } -} diff --git a/src/main/java/turniplabs/simpletech/block/BlockFan.java b/src/main/java/turniplabs/simpletech/block/BlockFan.java @@ -1,109 +0,0 @@ -package turniplabs.simpletech.block; - -import net.minecraft.core.block.BlockTileEntity; -import net.minecraft.core.block.entity.TileEntity; -import net.minecraft.core.block.material.Material; -import net.minecraft.core.entity.EntityLiving; -import net.minecraft.core.enums.EnumDropCause; -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.simpletech.SimpleTech; -import turniplabs.simpletech.block.entity.TileEntityFan; - -import java.util.Random; - -public class BlockFan extends BlockTileEntity { - private final boolean isPowered; - - public BlockFan(String key, int id, Material material, boolean isPowered) { - super(key, id, material); - this.isPowered = isPowered; - } - - @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; - } - - @Override - public int tickRate() { - return 2; - } - - @Override - public int getBlockTextureFromSideAndMetadata(Side side, int j) { - int direction = SimpleTech.get3DDirectionFromMeta(j); - if (direction > Direction.EAST.getId()) { - return this.atlasIndices[Side.TOP.getId()]; // Defaults to top/bottom texture. - } else if (side.getId() == direction) { - return this.atlasIndices[Side.SOUTH.getId()]; // Returns front texture. - } else { - if (side.getId() == Side.TOP.getId() || side.getId() == Side.BOTTOM.getId()) { - return this.atlasIndices[Side.TOP.getId()]; // Returns top/bottom texture. - } else { - return this.atlasIndices[Side.EAST.getId()]; // Returns one of the sides texture. - } - } - } - - @Override - public void randomDisplayTick(World world, int x, int y, int z, Random rand) { - // Particle rendering. - if (this.isPowered) { - int dx = -SimpleTech.getDirectionX(world, x, y, z); - int dy = -SimpleTech.getDirectionY(world, x, y, z); - int dz = -SimpleTech.getDirectionZ(world, x, y, z); - - for (int i = 1; i < 3; ++i) { - double rx = rand.nextDouble() - 0.5; - double ry = rand.nextDouble() - 0.5; - double rz = rand.nextDouble() - 0.5; - world.spawnParticle("smoke", - (double) (x + dx) + 0.5 + rx, - (double) (y + dy) + 0.5 + ry, - (double) (z + dz) + 0.5 + rz, - 0.2 * (double) dx, - 0.2 * (double) dy, - 0.2 * (double) dz - ); - } - } - } - - @Override - public void onNeighborBlockChange(World world, int x, int y, int z, int l) { - int direction; - - // If it's currently powered by redstone... - if (world.isBlockIndirectlyGettingPowered(x, y, z) || world.isBlockIndirectlyGettingPowered(x, y + 1, z)) { - // If it wasn't already powered... - if (!this.isPowered) { - // Replaces the unpowered fan by its powered counterpart. - direction = world.getBlockMetadata(x, y, z); - world.setBlockAndMetadataWithNotify(x, y, z, SimpleTech.POWERED_FAN_ID, direction); - } - - world.scheduleBlockUpdate(x, y, z, this.id, this.tickRate()); - } else if (this.isPowered) { - // Replaces the powered fan by its unpowered counterpart. - direction = world.getBlockMetadata(x, y, z); - world.setBlockAndMetadataWithNotify(x, y, z, SimpleTech.UNPOWERED_FAN_ID, direction); - } - } - - @Override - public void onBlockPlaced(World world, int x, int y, int z, Side side, EntityLiving entity, double sideHeight) { - Direction placementDirection = entity.getPlacementDirection(side).getOpposite(); - world.setBlockMetadataWithNotify(x, y, z, placementDirection.getId()); - } - - @Override - protected TileEntity getNewBlockEntity() { - return new TileEntityFan(); - } -} diff --git a/src/main/java/turniplabs/simpletech/block/BlockJumpPad.java b/src/main/java/turniplabs/simpletech/block/BlockJumpPad.java @@ -1,56 +0,0 @@ -package turniplabs.simpletech.block; - -import net.minecraft.core.block.Block; -import net.minecraft.core.block.material.Material; -import net.minecraft.core.entity.Entity; -import net.minecraft.core.entity.EntityItem; -import net.minecraft.core.entity.EntityLiving; -import net.minecraft.core.world.World; - -public class BlockJumpPad extends Block { - public BlockJumpPad(String key, int id, Material material) { - super(key, id, material); - } - - @Override - public boolean isSolidRender() { - return false; - } - - @Override - public boolean canPlaceBlockAt(World world, int x, int y, int z) { - return world.isBlockOpaqueCube(x, y - 1, z); - } - - public void jump(Entity entity) { - if ((entity instanceof EntityLiving || entity instanceof EntityItem) && entity.yd < 1.0D) { - entity.yd = 0.0D; - entity.fallDistance = 0.0F; - entity.push(0.0D, 1.0D, 0.0D); - } - } - - @Override - public void onEntityWalking(World world, int x, int y, int z, Entity entity) { - this.jump(entity); - } - - @Override - public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) { - if (entity.y > (double) y) { - this.jump(entity); - } - } - - @Override - public void setBlockBoundsBasedOnState(World world, int x, int y, int z) { - // Sets block shape when placed. - this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.25f, 1.0f); - } - - @Override - public void setBlockBoundsForItemRender() { - // Sets block shape when rendered inside containers. - this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.25f, 1.0f); - } -} diff --git a/src/main/java/turniplabs/simpletech/block/BlockLightSensor.java b/src/main/java/turniplabs/simpletech/block/BlockLightSensor.java @@ -1,85 +0,0 @@ -package turniplabs.simpletech.block; - -import net.minecraft.core.block.BlockTileEntity; -import net.minecraft.core.block.entity.TileEntity; -import net.minecraft.core.block.material.Material; -import net.minecraft.core.entity.player.EntityPlayer; -import net.minecraft.core.world.World; -import net.minecraft.core.world.WorldSource; -import turniplabs.simpletech.SimpleTech; -import turniplabs.simpletech.block.entity.TileEntityLightSensor; - -public class BlockLightSensor extends BlockTileEntity { - public static final int invertedOffset = 0; - public static final int redstoneOffset = 4; - - public BlockLightSensor(String key, int id, Material material) { - super(key, id, material); - } - - public boolean isInverted(World world, int x, int y, int z) { - return SimpleTech.getInvertedFromMetadata(world.getBlockMetadata(x, y, z), invertedOffset) != 0; - } - - @Override - public boolean renderAsNormalBlock() { - return false; - } - - @Override - public boolean isSolidRender() { - return false; - } - - @Override - public boolean canProvidePower() { - return true; - } - - @Override - public TileEntity getNewBlockEntity() { - return new TileEntityLightSensor(); - } - - @Override - public boolean isPoweringTo(WorldSource blockAccess, int x, int y, int z, int side) { - return SimpleTech.getRedstoneFromMetadata(blockAccess.getBlockMetadata(x, y, z), redstoneOffset) > 0; - } - - @Override - public void setBlockBoundsBasedOnState(World world, int x, int y, int z) { - // Sets block shape when placed. - this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.25f, 1.0f); - } - - @Override - public void setBlockBoundsForItemRender() { - // Sets block shape when rendered inside containers. - this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.25f, 1.0f); - } - - @Override - public boolean blockActivated(World world, int x, int y, int z, EntityPlayer player) { - int metadata = world.getBlockMetadata(x, y, z); - int isInverted = !isInverted(world, x, y, z) ? 1 : 0; - - // Recreates metadata using the inverted state and the old metadata value. - world.setBlockMetadataWithNotify(x, y, z, SimpleTech.getMetaWithInverted(metadata, isInverted, invertedOffset)); - - return true; - } - - public void updateSensor(World world, int x, int y, int z, boolean powering) { - int metadata = world.getBlockMetadata(x, y, z); - int redstone = powering ? 1 : 0; - - // Recreates metadata using the redstone signal and the old metadata value. - world.setBlockMetadataWithNotify(x, y, z, SimpleTech.getMetaWithRedstone(metadata, redstone, redstoneOffset)); - - // Updates block's neighbors. - world.notifyBlocksOfNeighborChange(x, y, z, this.id); - world.notifyBlocksOfNeighborChange(x, y - 1, z, this.id); - - world.markBlocksDirty(x, y, z, x, y, z); - } -} diff --git a/src/main/java/turniplabs/simpletech/block/BlockRedstoneNotGate.java b/src/main/java/turniplabs/simpletech/block/BlockRedstoneNotGate.java @@ -1,179 +0,0 @@ -package turniplabs.simpletech.block; - -import net.minecraft.core.block.Block; -import net.minecraft.core.block.entity.TileEntity; -import net.minecraft.core.block.material.Material; -import net.minecraft.core.entity.EntityLiving; -import net.minecraft.core.enums.EnumDropCause; -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 net.minecraft.core.world.WorldSource; -import turniplabs.simpletech.SimpleTech; - -import java.util.Random; - -public class BlockRedstoneNotGate extends Block { - private final boolean isPowered; - - public BlockRedstoneNotGate(String key, int id, Material material, boolean isPowered) { - super(key, id, material); - this.isPowered = isPowered; - } - - @Override - public void setBlockBoundsBasedOnState(World world, int x, int y, int z) { - // Sets block shape when placed. - this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.125f, 1.0f); - } - - @Override - public void setBlockBoundsForItemRender() { - // Sets block shape when rendered inside containers. - this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.125f, 1.0f); - } - - @Override - public boolean isSolidRender() { - return false; - } - - @Override - public boolean renderAsNormalBlock() { - return false; - } - - @Override - public boolean canPlaceBlockAt(World world, int x, int y, int z) { - return !world.canPlaceOnSurfaceOfBlock(x, y - 1, z) ? false : super.canPlaceBlockAt(world, x, y, z); - } - - @Override - public ItemStack[] getBreakResult(World world, EnumDropCause dropCause, int x, int y, int z, int meta, TileEntity tileEntity) { - return new ItemStack[]{new ItemStack(SimpleTech.notGate)}; - } - - @Override - public boolean canBlockStay(World world, int x, int y, int z) { - return !world.canPlaceOnSurfaceOfBlock(x, y - 1, z) ? false : super.canBlockStay(world, x, y, z); - } - - @Override - public void updateTick(World world, int x, int y, int z, Random rand) { - int metadata = world.getBlockMetadata(x, y, z); - boolean shouldPower = this.shouldPowerAdjacentBlocks(world, x, y, z, metadata); - if (this.isPowered && !shouldPower) { - world.setBlockAndMetadataWithNotify(x, y, z, SimpleTech.notGateIdle.id, metadata); - } else if (!this.isPowered) { - world.setBlockAndMetadataWithNotify(x, y, z, SimpleTech.notGateActive.id, metadata); - } - } - - @Override - public int getBlockTextureFromSideAndMetadata(Side side, int j) { - if (side == Side.BOTTOM) { - return !this.isPowered ? texCoordToIndex(3, 7) : texCoordToIndex(3, 6); - } else if (side == Side.TOP) { - return !this.isPowered ? texCoordToIndex(3, 8) : texCoordToIndex(3, 9); - } else { - return texCoordToIndex(5, 0); - } - } - - @Override - public boolean shouldSideBeRendered(WorldSource blockAccess, int x, int y, int z, int side) { - // Don't render bottom and top textures to avoid z-fighting with modified renderer. - return side != Side.BOTTOM.getId() && side != Side.TOP.getId(); - } - - @Override - public boolean isIndirectlyPoweringTo(World world, int x, int y, int z, int side) { - return this.isPoweringTo(world, x, y, z, side); - } - - @Override - public boolean isPoweringTo(WorldSource blockAccess, int x, int y, int z, int side) { - int direction = blockAccess.getBlockMetadata(x, y, z) & 3; - if (!this.isPowered) { - if (direction == Direction.EAST.getHorizontalIndex() && side == Side.EAST.getId()) { - return false; - } else if (direction == Direction.NORTH.getHorizontalIndex() && side == Side.NORTH.getId()) { - return false; - } else if (direction == Direction.SOUTH.getHorizontalIndex() && side == Side.SOUTH.getId()) { - return false; - } else if (direction == Direction.WEST.getHorizontalIndex() && side == Side.WEST.getId()) { - return false; - } else { - return true; - } - } else { - return false; - } - } - - @Override - public void onNeighborBlockChange(World world, int x, int y, int z, int blockId) { - if (!this.canBlockStay(world, x, y, z)) { - this.dropBlockWithCause(world, EnumDropCause.WORLD, x, y, z, world.getBlockMetadata(x, y, z), null); - world.setBlockWithNotify(x, y, z, 0); - } else { - int metadata = world.getBlockMetadata(x, y, z); - boolean shouldPower = this.shouldPowerAdjacentBlocks(world, x, y, z, metadata); - if (this.isPowered && !shouldPower) { - world.scheduleBlockUpdate(x, y, z, this.id, 1); - } else if (!this.isPowered && shouldPower) { - world.scheduleBlockUpdate(x, y, z, this.id, 1); - } - } - } - - @Override - public boolean canProvidePower() { - return false; - } - - @Override - public void onBlockPlaced(World world, int x, int y, int z, Side side, EntityLiving entity, double sideHeight) { - int metadata = entity.getHorizontalPlacementDirection(side).getHorizontalIndex(); - world.setBlockMetadataWithNotify(x, y, z, metadata); - boolean shouldPower = this.shouldPowerAdjacentBlocks(world, x, y, z, metadata); - if (shouldPower) { - world.scheduleBlockUpdate(x, y, z, this.id, 1); - } - } - - @Override - public void onBlockAdded(World world, int i, int j, int k) { - world.notifyBlocksOfNeighborChange(i + 1, j, k, this.id); - world.notifyBlocksOfNeighborChange(i - 1, j, k, this.id); - world.notifyBlocksOfNeighborChange(i, j, k + 1, this.id); - world.notifyBlocksOfNeighborChange(i, j, k - 1, this.id); - world.notifyBlocksOfNeighborChange(i, j - 1, k, this.id); - world.notifyBlocksOfNeighborChange(i, j + 1, k, this.id); - } - - private boolean shouldPowerAdjacentBlocks(World world, int i, int j, int k, int metadata) { - int direction = metadata & 3; - switch (direction) { - case 0: - return world.isBlockIndirectlyProvidingPowerTo(i, j, k + 1, 3) || - world.getBlockId(i, j, k + 1) == Block.wireRedstone.id && - world.getBlockMetadata(i, j, k + 1) > 0; - case 1: - return world.isBlockIndirectlyProvidingPowerTo(i - 1, j, k, 4) || - world.getBlockId(i - 1, j, k) == Block.wireRedstone.id && - world.getBlockMetadata(i - 1, j, k) > 0; - case 2: - return world.isBlockIndirectlyProvidingPowerTo(i, j, k - 1, 2) || - world.getBlockId(i, j, k - 1) == Block.wireRedstone.id && - world.getBlockMetadata(i, j, k - 1) > 0; - case 3: - return world.isBlockIndirectlyProvidingPowerTo(i + 1, j, k, 5) || - world.getBlockId(i + 1, j, k) == Block.wireRedstone.id && - world.getBlockMetadata(i + 1, j, k) > 0; - default: - return false; - } - } -} diff --git a/src/main/java/turniplabs/simpletech/block/BlockTrappedChest.java b/src/main/java/turniplabs/simpletech/block/BlockTrappedChest.java @@ -1,92 +0,0 @@ -package turniplabs.simpletech.block; - -import net.minecraft.core.block.BlockChest; -import net.minecraft.core.block.material.Material; -import net.minecraft.core.entity.player.EntityPlayer; -import net.minecraft.core.sound.SoundType; -import net.minecraft.core.world.World; -import net.minecraft.core.world.WorldSource; -import turniplabs.simpletech.SimpleTech; - -import java.util.Random; - -public class BlockTrappedChest extends BlockChest { - public static final int redstoneOffset = 4; - - public BlockTrappedChest(String key, int id, Material material) { - super(key, id, material); - this.withTexCoords(9, 1, 9, 1, 11, 1, 10, 1, 10, 1, 10, 1); - this.setTicking(true); - } - - @Override - public int tickRate() { - return 20; - } - - @Override - public boolean isSolidRender() { - return false; - } - - @Override - public boolean canProvidePower() { - return true; - } - - @Override - public boolean renderAsNormalBlock() { - return false; - } - - @Override - public boolean isPoweringTo(WorldSource blockAccess, int x, int y, int z, int side) { - return SimpleTech.getRedstoneFromMetadata(blockAccess.getBlockMetadata(x, y, z), redstoneOffset) > 0; - } - - @Override - public void onBlockRemoved(World world, int x, int y, int z, int data) { - if (SimpleTech.getRedstoneFromMetadata(world.getBlockMetadata(x, y, z), redstoneOffset) > 0) { - this.notifyNeighbors(world, x, y, z); - } - - super.onBlockRemoved(world, x, y, z, data); - } - - @Override - public boolean blockActivated(World world, int x, int y, int z, EntityPlayer player) { - this.setState(world, x, y, z, (byte) 1); - - world.scheduleBlockUpdate(x, y, z, this.id, this.tickRate()); - world.playSoundEffect(SoundType.GUI_SOUNDS,x + 0.5, y + 0.5, z + 0.5, - "random.click", 0.3f, 0.6f); - - return super.blockActivated(world, x, y, z, player); - } - - @Override - public void updateTick(World world, int x, int y, int z, Random rand) { - if (!world.isClientSide) { - if (SimpleTech.getRedstoneFromMetadata(world.getBlockMetadata(x, y, z), redstoneOffset) > 0) { - this.setState(world, x, y, z, (byte) 0); - } - } - } - - private void setState(World world, int x, int y, int z, byte redstone) { - int metadata = world.getBlockMetadata(x, y, z); - - // Recreates metadata using the redstone signal and the old metadata value. - world.setBlockMetadataWithNotify(x, y, z, SimpleTech.getMetaWithRedstone(metadata, redstone, redstoneOffset)); - - // Updates block's neighbors. - this.notifyNeighbors(world, x, y, z); - - world.markBlocksDirty(x, y, z, x, y, z); - } - - private void notifyNeighbors(World world, int x, int y, int z) { - world.notifyBlocksOfNeighborChange(x, y, z, this.id); - world.notifyBlocksOfNeighborChange(x, y - 1, z, this.id); - } -} diff --git a/src/main/java/turniplabs/simpletech/block/entity/TileEntityAllocator.java b/src/main/java/turniplabs/simpletech/block/entity/TileEntityAllocator.java @@ -1,102 +0,0 @@ -package turniplabs.simpletech.block.entity; - -import com.mojang.nbt.CompoundTag; -import com.mojang.nbt.ListTag; -import net.minecraft.core.block.entity.TileEntity; -import net.minecraft.core.entity.player.EntityPlayer; -import net.minecraft.core.item.ItemStack; -import net.minecraft.core.player.inventory.IInventory; - -public class TileEntityAllocator extends TileEntity implements IInventory { - private ItemStack allocatorFilterItem; - - @Override - public int getSizeInventory() { - return 1; - } - - @Override - public ItemStack getStackInSlot(int i) { - return i == 0 ? this.allocatorFilterItem : null; - } - - @Override - public ItemStack decrStackSize(int i, int j) { - if (i != 0) { - return null; - } else if (this.allocatorFilterItem != null) { - ItemStack itemstack; - if (this.allocatorFilterItem.stackSize <= j) { - itemstack = this.allocatorFilterItem; - this.allocatorFilterItem = null; - return itemstack; - } else { - itemstack = this.allocatorFilterItem.splitStack(j); - if (this.allocatorFilterItem.stackSize == 0) { - this.allocatorFilterItem = null; - } - - return itemstack; - } - } else { - return null; - } - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemStack) { - if (i == 0) { - this.allocatorFilterItem = itemStack; - if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()) { - itemStack.stackSize = this.getInventoryStackLimit(); - } - } - } - - @Override - public String getInvName() { - return "Allocator"; - } - - @Override - public int getInventoryStackLimit() { - return 1; - } - - @Override - public boolean canInteractWith(EntityPlayer entityPlayer) { - return this.worldObj.getBlockTileEntity(this.x, this.y, this.z) == this && - entityPlayer.distanceToSqr((double) this.x + 0.5D, (double) this.y + 0.5D, - (double) this.z + 0.5D) <= 64.0D; - } - - @Override - public void sortInventory() {} - - @Override - public void readFromNBT(CompoundTag nbttagcompound) { - super.readFromNBT(nbttagcompound); - ListTag items = nbttagcompound.getList("Items"); - if (items.tagCount() != 0) { - CompoundTag item = (CompoundTag)items.tagAt(0); - int slot = item.getByte("Slot") & 255; - if(slot == 0) { - this.allocatorFilterItem = ItemStack.readItemStackFromNbt(item); - } - } - } - - @Override - public void writeToNBT(CompoundTag nbttagcompound) { - super.writeToNBT(nbttagcompound); - ListTag items = new ListTag(); - if (this.allocatorFilterItem != null) { - CompoundTag item = new CompoundTag(); - item.putByte("Slot", (byte)0); - this.allocatorFilterItem.writeToNBT(item); - items.addTag(item); - } - - nbttagcompound.put("Items", items); - } -} diff --git a/src/main/java/turniplabs/simpletech/block/entity/TileEntityFan.java b/src/main/java/turniplabs/simpletech/block/entity/TileEntityFan.java @@ -1,96 +0,0 @@ -package turniplabs.simpletech.block.entity; - -import net.minecraft.core.block.entity.TileEntity; -import net.minecraft.core.entity.Entity; -import net.minecraft.core.entity.EntityItem; -import net.minecraft.core.util.phys.AABB; -import net.minecraft.core.world.World; -import turniplabs.simpletech.SimpleTech; - -import java.util.List; - -public class TileEntityFan extends TileEntity { - private final int range; - - public TileEntityFan(int range) { - this.range = range; - } - - public TileEntityFan() { - // Always define the default constructor when working with tile entities. - this(SimpleTech.FAN_RANGE); - } - - @Override - public void tick() { - if (worldObj.isBlockIndirectlyGettingPowered(x, y, z) || - worldObj.isBlockIndirectlyGettingPowered(x, y + 1, z)) { - this.blow(worldObj, x, y, z); - } - } - - private void blow(World world, int x, int y, int z) { - int dx = -SimpleTech.getDirectionX(world, x, y, z); - int dy = -SimpleTech.getDirectionY(world, x, y, z); - int dz = -SimpleTech.getDirectionZ(world, x, y, z); - - int px = x; - int py = y; - int pz = z; - - for (int i = 0; i < this.range; ++i) { - px += dx; - py += dy; - pz += dz; - - if (world.isBlockOpaqueCube(px, py, pz)) { - break; - } - - List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, AABB.getBoundingBoxFromPool( - px, py, pz, px + 1, py + 1, pz + 1) - ); - - for (Entity entity : entities) { - if (entity instanceof EntityItem) { - this.pushEntity(entity, dx, dy, dz); - } - } - } - } - - private void pushEntity(Entity entity, int dx, int dy, int dz) { - double maxspeed = 0.4; - double boost = 0.1; - - if (Math.abs(dx) != 0) { - if (entity.xd * (double) dx < 0.0) { - entity.xd = 0.0; - } - - if (entity.xd * (double) dx <= maxspeed) { - entity.xd += (double) dx * boost; - } - } else if (Math.abs(dy) != 0) { - if (entity.yd * (double) dy < 0.0) { - entity.yd = 0.0; - } - - if (dy > 0) { - boost *= 0.5; - } - - if (entity.yd * (double) dy <= maxspeed) { - entity.yd += (double) dy * boost; - } - } else if (Math.abs(dz) != 0) { - if (entity.zd * (double) dz < 0.0) { - entity.zd = 0.0; - } - - if (entity.zd * (double) dz <= maxspeed) { - entity.zd += (double) dz * boost; - } - } - } -} diff --git a/src/main/java/turniplabs/simpletech/block/entity/TileEntityLightSensor.java b/src/main/java/turniplabs/simpletech/block/entity/TileEntityLightSensor.java @@ -1,39 +0,0 @@ -package turniplabs.simpletech.block.entity; - -import net.minecraft.core.block.Block; -import net.minecraft.core.block.entity.TileEntity; -import turniplabs.simpletech.SimpleTech; -import turniplabs.simpletech.block.BlockLightSensor; - -public class TileEntityLightSensor extends TileEntity { - @Override - public void tick() { - // If the world object is valid... - if (worldObj != null && !worldObj.isClientSide) { - Block block = getBlockType(); - // If it's a light sensor... - if (block instanceof BlockLightSensor) { - BlockLightSensor lightSensor = ((BlockLightSensor) block); - boolean isDay = worldObj.isDaytime(); - boolean isPowered = SimpleTech.getRedstoneFromMetadata( - worldObj.getBlockMetadata(x, y, z), - BlockLightSensor.redstoneOffset) > 0; - boolean isInverted = lightSensor.isInverted(worldObj, x, y, z); - if (isInverted) { - // Daytime mode. - if (isDay && !isPowered) - // Sends redstone value. - lightSensor.updateSensor(worldObj, x, y, z, true); - if (!isDay && isPowered) - lightSensor.updateSensor(worldObj, x, y, z, false); - } else { - // Nighttime mode. - if (isDay && isPowered) - lightSensor.updateSensor(worldObj, x, y, z, false); - if (!isDay && !isPowered) - lightSensor.updateSensor(worldObj, x, y, z, true); - } - } - } - } -} diff --git a/src/main/java/turniplabs/simpletech/gui/GuiAllocator.java b/src/main/java/turniplabs/simpletech/gui/GuiAllocator.java @@ -1,36 +0,0 @@ -package turniplabs.simpletech.gui; - -import net.minecraft.client.gui.GuiContainer; -import net.minecraft.core.player.inventory.InventoryPlayer; -import org.lwjgl.opengl.GL11; -import turniplabs.simpletech.block.entity.TileEntityAllocator; -import turniplabs.simpletech.player.inventory.ContainerAllocator; - -public class GuiAllocator extends GuiContainer { - private final TileEntityAllocator allocatorInv; - - public GuiAllocator(InventoryPlayer playerInventory, TileEntityAllocator allocator) { - super(new ContainerAllocator(playerInventory, allocator)); - this.allocatorInv = allocator; - } - - @Override - protected void drawGuiContainerForegroundLayer() { - this.fontRenderer.drawString("Allocator", 60, 6, 4210752); - this.fontRenderer.drawString("Inventory", 8, this.ySize - 96 + 2, 4210752); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float f) { - int i = this.mc.renderEngine.getTexture("/assets/simpletech/gui/allocator.png"); - - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - - this.mc.renderEngine.bindTexture(i); - - int j = (this.width - this.xSize) / 2; - int k = (this.height - this.ySize) / 2; - - this.drawTexturedModalRect(j, k, 0, 0, this.xSize, this.ySize); - } -} diff --git a/src/main/java/turniplabs/simpletech/mixin/EntityItemMixin.java b/src/main/java/turniplabs/simpletech/mixin/EntityItemMixin.java @@ -1,20 +0,0 @@ -package turniplabs.simpletech.mixin; - -import net.minecraft.core.entity.EntityItem; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(value = EntityItem.class, remap = false) -final class EntityItemMixin { - @Inject(method = "clumpToNearbyStack", at = @At("HEAD"), - require = 0, cancellable = true) - private void removeItemEntityStacking(CallbackInfo ci) { - EntityItem currentEntityItem = (EntityItem) ((Object) this); - - if (!currentEntityItem.item.isStackable()) { - ci.cancel(); - } - } -} diff --git a/src/main/java/turniplabs/simpletech/mixin/EntityPlayerMPMixin.java b/src/main/java/turniplabs/simpletech/mixin/EntityPlayerMPMixin.java @@ -1,35 +0,0 @@ -package turniplabs.simpletech.mixin; - -import net.minecraft.core.entity.player.EntityPlayer; -import net.minecraft.core.net.packet.Packet100OpenWindow; -import net.minecraft.core.world.World; -import net.minecraft.server.entity.player.EntityPlayerMP; -import net.minecraft.server.net.handler.NetServerHandler; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import turniplabs.simpletech.IPlayerDisplayer; -import turniplabs.simpletech.SimpleTech; -import turniplabs.simpletech.block.entity.TileEntityAllocator; -import turniplabs.simpletech.player.inventory.ContainerAllocator; - -@Mixin(value = EntityPlayerMP.class, remap = false) -public abstract class EntityPlayerMPMixin extends EntityPlayer implements IPlayerDisplayer { - @Shadow protected abstract void getNextWindowId(); - - @Shadow public NetServerHandler playerNetServerHandler; - - @Shadow private int currentWindowId; - - public EntityPlayerMPMixin(World world) { - super(world); - } - - @Override - public void simple_tech$displayGUIAllocator(TileEntityAllocator allocator) { - this.getNextWindowId(); - this.playerNetServerHandler.sendPacket(new Packet100OpenWindow(this.currentWindowId, SimpleTech.ALLOCATOR_GUI_ID, allocator.getInvName(), allocator.getSizeInventory())); - this.craftingInventory = new ContainerAllocator(this.inventory, allocator); - this.craftingInventory.windowId = this.currentWindowId; - this.craftingInventory.onContainerInit((EntityPlayerMP)(Object)this); - } -} diff --git a/src/main/java/turniplabs/simpletech/mixin/EntityPlayerMixin.java b/src/main/java/turniplabs/simpletech/mixin/EntityPlayerMixin.java @@ -1,14 +0,0 @@ -package turniplabs.simpletech.mixin; - -import net.minecraft.core.entity.player.EntityPlayer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import turniplabs.simpletech.IPlayerDisplayer; -import turniplabs.simpletech.block.entity.TileEntityAllocator; - -@Mixin(value = EntityPlayer.class, remap = false) -public class EntityPlayerMixin implements IPlayerDisplayer { - @Unique - public void simple_tech$displayGUIAllocator(TileEntityAllocator allocator) { - } -} diff --git a/src/main/java/turniplabs/simpletech/mixin/EntityPlayerSPMixin.java b/src/main/java/turniplabs/simpletech/mixin/EntityPlayerSPMixin.java @@ -1,27 +0,0 @@ -package turniplabs.simpletech.mixin; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.player.EntityPlayerSP; -import net.minecraft.core.entity.player.EntityPlayer; -import net.minecraft.core.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import turniplabs.simpletech.IPlayerDisplayer; -import turniplabs.simpletech.block.entity.TileEntityAllocator; -import turniplabs.simpletech.gui.GuiAllocator; - -@Mixin(value = EntityPlayerSP.class, remap = false) -public abstract class EntityPlayerSPMixin extends EntityPlayer implements IPlayerDisplayer { - @Shadow protected Minecraft mc; - - public EntityPlayerSPMixin(World world) { - super(world); - } - - @Override - public void simple_tech$displayGUIAllocator(TileEntityAllocator allocator) { - if (allocator != null){ - this.mc.displayGuiScreen(new GuiAllocator(inventory, allocator)); - } - } -} diff --git a/src/main/java/turniplabs/simpletech/mixin/NetClientHandlerMixin.java b/src/main/java/turniplabs/simpletech/mixin/NetClientHandlerMixin.java @@ -1,30 +0,0 @@ -package turniplabs.simpletech.mixin; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.net.handler.NetClientHandler; -import net.minecraft.core.net.packet.Packet100OpenWindow; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import turniplabs.simpletech.IPlayerDisplayer; -import turniplabs.simpletech.SimpleTech; -import turniplabs.simpletech.block.entity.TileEntityAllocator; - -@Mixin(value = NetClientHandler.class, remap = false) -public class NetClientHandlerMixin { - @Final - @Shadow private Minecraft mc; - - @Inject(method = "handleOpenWindow(Lnet/minecraft/core/net/packet/Packet100OpenWindow;)V", at = @At("HEAD"), cancellable = true) - public void handleAllocator(Packet100OpenWindow packet100openwindow, CallbackInfo ci){ - if (packet100openwindow.inventoryType == SimpleTech.ALLOCATOR_GUI_ID) { - TileEntityAllocator tileEntityAllocator = new TileEntityAllocator(); - ((IPlayerDisplayer)this.mc.thePlayer).simple_tech$displayGUIAllocator(tileEntityAllocator); - this.mc.thePlayer.craftingInventory.windowId = packet100openwindow.windowId; - ci.cancel(); - } - } -} diff --git a/src/main/java/turniplabs/simpletech/mixin/RenderBlocksMixin.java b/src/main/java/turniplabs/simpletech/mixin/RenderBlocksMixin.java @@ -1,115 +0,0 @@ -package turniplabs.simpletech.mixin; - -import net.minecraft.client.render.RenderBlocks; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.TextureFX; -import net.minecraft.core.Global; -import net.minecraft.core.block.Block; -import net.minecraft.core.util.helper.Side; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyVariable; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -import turniplabs.simpletech.block.BlockAllocator; -import turniplabs.simpletech.block.BlockFan; -import turniplabs.simpletech.block.BlockRedstoneNotGate; - -@Mixin(value = RenderBlocks.class, remap = false) -final class RenderBlocksMixin { - @Redirect(method = "renderBlockOnInventory(Lnet/minecraft/core/block/Block;IFF)V", at = @At(value = "INVOKE", - target = "Lnet/minecraft/core/block/Block;getBlockTextureFromSideAndMetadata(Lnet/minecraft/core/util/helper/Side;I)I"), - require = 0) - private int changeBlockInventoryRender(Block block, Side side, int meta) { - if (block instanceof BlockFan) { - if (side == Side.SOUTH) { - return block.atlasIndices[Side.SOUTH.getId()]; // Returns front texture. - } - - if (side == Side.BOTTOM) { - return block.atlasIndices[Side.TOP.getId()]; // Returns top/bottom texture. - } - } - - if (block instanceof BlockAllocator) { - if (side == Side.TOP || side == Side.BOTTOM) { - return block.atlasIndices[Side.WEST.getId()]; // Returns top/bottom texture. - } - - if (side == Side.SOUTH) { - return block.atlasIndices[Side.SOUTH.getId()]; // Returns front texture. - } - - if (side == Side.NORTH) { - return block.atlasIndices[Side.NORTH.getId()]; // Returns back texture. - } - } - - return block.getBlockTextureFromSideAndMetadata(side, meta); - } - - @ModifyVariable(method = "renderBlockByRenderType", at = @At("HEAD"), ordinal = 0, require = 0) - private int changeRenderType(int renderType, Block block) { - if (block instanceof BlockRedstoneNotGate) { - return 15; // Use the repeater renderer as a base. - } - - return renderType; - } - - @Inject(method = "renderBlockRepeater", at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/render/Tessellator;setColorOpaque_F(FFF)V", shift = At.Shift.AFTER), - locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true, require = 0) - private void renderBlockRedstoneGate(Block block, int i, int j, int k, CallbackInfoReturnable<Boolean> cir, - int l, int i1, int j1, Tessellator tessellator) { - if (block instanceof BlockRedstoneNotGate) { - /* Gets metadata, tesselator and block brightness (captures locals). */ - - /* Skips torch rendering instructions (injects just after 'setColorOpaque_F' method call). */ - - int k1 = block.getBlockTextureFromSideAndMetadata(Side.TOP, l); - int l1 = k1 % Global.TEXTURE_ATLAS_WIDTH_TILES * TextureFX.tileWidthTerrain; - int i2 = k1 / Global.TEXTURE_ATLAS_WIDTH_TILES * TextureFX.tileWidthTerrain; - double d5 = (double)((float)l1 / (float)(TextureFX.tileWidthTerrain * Global.TEXTURE_ATLAS_WIDTH_TILES)); - double d6 = (double)(((float)l1 + ((float)TextureFX.tileWidthTerrain - 0.01F)) / (float)(TextureFX.tileWidthTerrain * Global.TEXTURE_ATLAS_WIDTH_TILES)); - double d7 = (double)((float)i2 / (float)(TextureFX.tileWidthTerrain * Global.TEXTURE_ATLAS_WIDTH_TILES)); - double d8 = (double)(((float)i2 + ((float)TextureFX.tileWidthTerrain - 0.01F)) / (float)(TextureFX.tileWidthTerrain * Global.TEXTURE_ATLAS_WIDTH_TILES)); - float f1 = 0.125F; - float f2 = (float)(i + 1); - float f3 = (float)(i + 1); - float f4 = (float)(i + 0); - float f5 = (float)(i + 0); - float f6 = (float)(k + 0); - float f7 = (float)(k + 1); - float f8 = (float)(k + 1); - float f9 = (float)(k + 0); - float f10 = (float)j + f1; - if (i1 == 2) { - f2 = f3 = (float)(i + 0); - f4 = f5 = (float)(i + 1); - f6 = f9 = (float)(k + 1); - f7 = f8 = (float)(k + 0); - } else if (i1 == 3) { - f2 = f5 = (float)(i + 0); - f3 = f4 = (float)(i + 1); - f6 = f7 = (float)(k + 0); - f8 = f9 = (float)(k + 1); - } else if (i1 == 1) { - f2 = f5 = (float)(i + 1); - f3 = f4 = (float)(i + 0); - f6 = f7 = (float)(k + 1); - f8 = f9 = (float)(k + 0); - } - - tessellator.addVertexWithUV((double)f5, (double)f10, (double)f9, d5, d7); - tessellator.addVertexWithUV((double)f4, (double)f10, (double)f8, d5, d8); - tessellator.addVertexWithUV((double)f3, (double)f10, (double)f7, d6, d8); - tessellator.addVertexWithUV((double)f2, (double)f10, (double)f6, d6, d7); - - cir.setReturnValue(true); - } - } -} diff --git a/src/main/java/turniplabs/simpletech/player/inventory/ContainerAllocator.java b/src/main/java/turniplabs/simpletech/player/inventory/ContainerAllocator.java @@ -1,47 +0,0 @@ -package turniplabs.simpletech.player.inventory; - -import net.minecraft.core.InventoryAction; -import net.minecraft.core.entity.player.EntityPlayer; -import net.minecraft.core.player.inventory.Container; -import net.minecraft.core.player.inventory.IInventory; -import net.minecraft.core.player.inventory.slot.Slot; -import turniplabs.simpletech.block.entity.TileEntityAllocator; - -import java.util.List; - -public class ContainerAllocator extends Container { - private final TileEntityAllocator allocator; - - public ContainerAllocator(IInventory playerInventory, TileEntityAllocator allocator) { - this.allocator = allocator; - - // Adding allocator slot. - this.addSlot(new Slot(allocator, 0, 80, 36)); - - // Adding player inventory slots. - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 9; ++j) { - this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); - } - } - - for(int i = 0; i < 9; ++i) { - this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 142)); - } - } - - @Override - public boolean isUsableByPlayer(EntityPlayer entityPlayer) { - return this.allocator.canInteractWith(entityPlayer); - } - - @Override - public List<Integer> getMoveSlots(InventoryAction inventoryAction, Slot slot, int i, EntityPlayer entityPlayer) { - return null; - } - - @Override - public List<Integer> getTargetSlots(InventoryAction inventoryAction, Slot slot, int i, EntityPlayer entityPlayer) { - return null; - } -} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json @@ -8,19 +8,19 @@ "Ambos" ], "contact": { - "homepage": "https://github.com/Turnip-Labs", - "sources": "https://github.com/Turnip-Labs/simple-tech", - "issues": "https://github.com/Turnip-Labs/simple-tech/issues" + "homepage": "https://memoryshards.xyz", + "sources": "https://github.com/ambos/simple-tech", + "issues": "https://github.com/ambos/simple-tech/issues" }, "license": "CC-BY-NC-SA-3.0", "icon": "icon.png", "environment": "*", "entrypoints": { "beforeGameStart": [ - "turniplabs.simpletech.SimpleTech" + "ambos.simpletech.SimpleTech" ], "recipesReady": [ - "turniplabs.simpletech.SimpleTechRecipes" + "ambos.simpletech.SimpleTechRecipes" ] }, "mixins": [ diff --git a/src/main/resources/simpletech.mixins.json b/src/main/resources/simpletech.mixins.json @@ -1,7 +1,7 @@ { "required": true, "minVersion": "0.8", - "package": "turniplabs.simpletech.mixin", + "package": "ambos.simpletech.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ "EntityItemMixin",