simple-tech

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

commit 2e90b1279e0e641b9ca661f1ba237cc8740a73d6
parent 6a193c7a008d003e85fbe2b48d3597f06de27a8a
Author: Amb0s <ambos@disroot.org>
Date:   Wed,  7 Feb 2024 05:38:58 +0100

Changed formatting

Diffstat:
Msrc/main/java/ambos/simpletech/SimpleTech.java | 7++++---
Msrc/main/java/ambos/simpletech/SimpleTechRecipes.java | 4+++-
Msrc/main/java/ambos/simpletech/block/BlockAllocator.java | 658++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/main/java/ambos/simpletech/block/BlockFan.java | 160++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/main/java/ambos/simpletech/block/BlockRedstoneNotGate.java | 8+++++---
Msrc/main/java/ambos/simpletech/block/BlockTrappedChest.java | 2+-
Msrc/main/java/ambos/simpletech/block/entity/TileEntityAllocator.java | 159++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/main/java/ambos/simpletech/block/entity/TileEntityFan.java | 3+--
Msrc/main/java/ambos/simpletech/gui/GuiAllocator.java | 38+++++++++++++++++++-------------------
Msrc/main/java/ambos/simpletech/mixin/EntityItemMixin.java | 3+--
Msrc/main/java/ambos/simpletech/mixin/EntityPlayerSPMixin.java | 5+++--
Msrc/main/java/ambos/simpletech/mixin/NetClientHandlerMixin.java | 7++++---
Msrc/main/java/ambos/simpletech/mixin/RenderBlocksMixin.java | 75++++++++++++++++++++++++++++++++++++++-------------------------------------
Msrc/main/java/ambos/simpletech/player/inventory/ContainerAllocator.java | 68++++++++++++++++++++++++++++++++++----------------------------------
14 files changed, 602 insertions(+), 595 deletions(-)

diff --git a/src/main/java/ambos/simpletech/SimpleTech.java b/src/main/java/ambos/simpletech/SimpleTech.java @@ -74,7 +74,6 @@ public class SimpleTech implements GameStartEntrypoint { NOT_GATE_ID = config.getInt("ItemIDs.NOT_GATE_ID"); } - // Builders public static final BlockBuilder stoneBlockBuilder = new BlockBuilder(MOD_ID) .setHardness(1.5f) @@ -98,7 +97,8 @@ public class SimpleTech implements GameStartEntrypoint { .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); + .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 @@ -146,7 +146,8 @@ public class SimpleTech implements GameStartEntrypoint { .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"); + 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() { diff --git a/src/main/java/ambos/simpletech/SimpleTechRecipes.java b/src/main/java/ambos/simpletech/SimpleTechRecipes.java @@ -12,7 +12,9 @@ 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))); + public static final RecipeGroup<RecipeEntryCrafting<?, ?>> WORKBENCH = new RecipeGroup<>( + new RecipeSymbol(new ItemStack(Block.workbench))); + @Override public void onRecipesReady() { SIMPLE_TECH.register("workbench", WORKBENCH); diff --git a/src/main/java/ambos/simpletech/block/BlockAllocator.java b/src/main/java/ambos/simpletech/block/BlockAllocator.java @@ -28,333 +28,333 @@ 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; - } - } - } + 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 @@ -16,95 +16,95 @@ import ambos.simpletech.SimpleTech; import ambos.simpletech.block.entity.TileEntityFan; public class BlockFan extends BlockTileEntity { - private final boolean isPowered; + private final boolean isPowered; - public BlockFan(String key, int id, Material material, boolean isPowered) { - super(key, id, material); - this.isPowered = 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 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 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 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); + @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 - ); - } - } - } + 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; + @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); - } + // 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); - } - } + 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 + 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(); - } + @Override + protected TileEntity getNewBlockEntity() { + return new TileEntityFan(); + } } diff --git a/src/main/java/ambos/simpletech/block/BlockRedstoneNotGate.java b/src/main/java/ambos/simpletech/block/BlockRedstoneNotGate.java @@ -51,8 +51,9 @@ public class BlockRedstoneNotGate extends Block { } @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)}; + 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 @@ -84,7 +85,8 @@ public class BlockRedstoneNotGate extends Block { @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. + // Don't render bottom and top textures to avoid z-fighting with modified + // renderer. return side != Side.BOTTOM.getId() && side != Side.TOP.getId(); } diff --git a/src/main/java/ambos/simpletech/block/BlockTrappedChest.java b/src/main/java/ambos/simpletech/block/BlockTrappedChest.java @@ -59,7 +59,7 @@ public class BlockTrappedChest extends BlockChest { 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, + 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); diff --git a/src/main/java/ambos/simpletech/block/entity/TileEntityAllocator.java b/src/main/java/ambos/simpletech/block/entity/TileEntityAllocator.java @@ -8,95 +8,96 @@ import net.minecraft.core.item.ItemStack; import net.minecraft.core.player.inventory.IInventory; public class TileEntityAllocator extends TileEntity implements IInventory { - private ItemStack allocatorFilterItem; + private ItemStack allocatorFilterItem; - @Override - public int getSizeInventory() { - return 1; - } + @Override + public int getSizeInventory() { + return 1; + } - @Override - public ItemStack getStackInSlot(int i) { - return i == 0 ? this.allocatorFilterItem : null; - } + @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; - } + @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; - } - } + 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 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 String getInvName() { + return "Allocator"; + } - @Override - public int getInventoryStackLimit() { - return 1; - } + @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 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 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 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); - } + @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); - } + 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 @@ -49,8 +49,7 @@ public class TileEntityFan extends TileEntity { } List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, AABB.getBoundingBoxFromPool( - px, py, pz, px + 1, py + 1, pz + 1) - ); + px, py, pz, px + 1, py + 1, pz + 1)); for (Entity entity : entities) { if (entity instanceof EntityItem) { diff --git a/src/main/java/ambos/simpletech/gui/GuiAllocator.java b/src/main/java/ambos/simpletech/gui/GuiAllocator.java @@ -8,30 +8,30 @@ import ambos.simpletech.block.entity.TileEntityAllocator; import ambos.simpletech.player.inventory.ContainerAllocator; public class GuiAllocator extends GuiContainer { - private final TileEntityAllocator allocatorInv; + private final TileEntityAllocator allocatorInv; - public GuiAllocator(InventoryPlayer playerInventory, TileEntityAllocator allocator) { - super(new ContainerAllocator(playerInventory, allocator)); - this.allocatorInv = allocator; - } + 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 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"); + @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); + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - this.mc.renderEngine.bindTexture(i); + this.mc.renderEngine.bindTexture(i); - int j = (this.width - this.xSize) / 2; - int k = (this.height - this.ySize) / 2; + int j = (this.width - this.xSize) / 2; + int k = (this.height - this.ySize) / 2; - this.drawTexturedModalRect(j, k, 0, 0, this.xSize, this.ySize); - } + 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 @@ -8,8 +8,7 @@ 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) + @Inject(method = "clumpToNearbyStack", at = @At("HEAD"), require = 0, cancellable = true) private void removeItemEntityStacking(CallbackInfo ci) { EntityItem currentEntityItem = (EntityItem) ((Object) this); diff --git a/src/main/java/ambos/simpletech/mixin/EntityPlayerSPMixin.java b/src/main/java/ambos/simpletech/mixin/EntityPlayerSPMixin.java @@ -13,7 +13,8 @@ import ambos.simpletech.gui.GuiAllocator; @Mixin(value = EntityPlayerSP.class, remap = false) public abstract class EntityPlayerSPMixin extends EntityPlayer implements IPlayerDisplayer { - @Shadow protected Minecraft mc; + @Shadow + protected Minecraft mc; public EntityPlayerSPMixin(World world) { super(world); @@ -21,7 +22,7 @@ public abstract class EntityPlayerSPMixin extends EntityPlayer implements IPlaye @Override public void simple_tech$displayGUIAllocator(TileEntityAllocator allocator) { - if (allocator != null){ + 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 @@ -17,13 +17,14 @@ import ambos.simpletech.block.entity.TileEntityAllocator; @Mixin(value = NetClientHandler.class, remap = false) public class NetClientHandlerMixin { @Final - @Shadow private Minecraft mc; + @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){ + 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); + ((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 @@ -20,9 +20,7 @@ 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) + @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) { @@ -60,54 +58,57 @@ final class RenderBlocksMixin { 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) + @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) { + 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). */ + /* + * 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)); + 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; + 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); + 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); + 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); + 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); + 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 @@ -11,38 +11,38 @@ 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; - } + 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; + } }