diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index d285dea1..986d58b7 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -22,6 +22,7 @@ New - Blast resistent Dark Steel Bars - Powered Magnet - Powered Spawner +- Vacuum Chest Changes - Removed advanced item conduits and added upgrades to the basic conduits diff --git a/resources/assets/enderio/lang/en_US.lang b/resources/assets/enderio/lang/en_US.lang index bd0df49d..0257dee8 100644 --- a/resources/assets/enderio/lang/en_US.lang +++ b/resources/assets/enderio/lang/en_US.lang @@ -232,6 +232,8 @@ enderio.tank.tank=Tank tile.blockCrafter.name=Crafter +tile.blockVacuumChest.name=Vacuum Chest + tile.blockPoweredSpawner.name=Powered Spawner tile.blockPoweredSpawner.tooltip.empty=Empty tile.blockPoweredSpawner.empty.tooltip.detailed.line1=Combine with a broken diff --git a/resources/assets/enderio/textures/blocks/blockVacuumChest.png b/resources/assets/enderio/textures/blocks/blockVacuumChest.png new file mode 100644 index 00000000..c84b2568 Binary files /dev/null and b/resources/assets/enderio/textures/blocks/blockVacuumChest.png differ diff --git a/resources/assets/enderio/textures/gui/vacumChest.png b/resources/assets/enderio/textures/gui/vacumChest.png new file mode 100644 index 00000000..4b203b2b Binary files /dev/null and b/resources/assets/enderio/textures/gui/vacumChest.png differ diff --git a/src/main/java/crazypants/enderio/ClientProxy.java b/src/main/java/crazypants/enderio/ClientProxy.java index 55fc281e..003dc275 100644 --- a/src/main/java/crazypants/enderio/ClientProxy.java +++ b/src/main/java/crazypants/enderio/ClientProxy.java @@ -71,6 +71,8 @@ import crazypants.enderio.machine.still.VatRenderer; import crazypants.enderio.machine.tank.TankFluidRenderer; import crazypants.enderio.machine.tank.TankItemRenderer; import crazypants.enderio.machine.tank.TileTank; +import crazypants.enderio.machine.vacuum.BlockVacuumChest; +import crazypants.enderio.machine.vacuum.VacuumChestRenderer; import crazypants.enderio.material.BlockFusedQuartz; import crazypants.enderio.material.FusedQuartzFrameRenderer; import crazypants.enderio.material.FusedQuartzRenderer; @@ -189,6 +191,11 @@ public class ClientProxy extends CommonProxy { BlockCapacitorBank.renderId = RenderingRegistry.getNextAvailableRenderId(); CapBankRenderer2 cbr2 = new CapBankRenderer2(); RenderingRegistry.registerBlockHandler(cbr2); + + BlockVacuumChest.renderId = RenderingRegistry.getNextAvailableRenderId(); + VacuumChestRenderer vcr = new VacuumChestRenderer(); + RenderingRegistry.registerBlockHandler(vcr); + MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockVacuumChest), vcr); ItemConduitRenderer itemConRenderer = new ItemConduitRenderer(); MinecraftForgeClient.registerItemRenderer(EnderIO.itemLiquidConduit, itemConRenderer); diff --git a/src/main/java/crazypants/enderio/Config.java b/src/main/java/crazypants/enderio/Config.java index 0858c213..004b0dd5 100644 --- a/src/main/java/crazypants/enderio/Config.java +++ b/src/main/java/crazypants/enderio/Config.java @@ -136,12 +136,11 @@ public final class Config { public static int darkSteelUpgradePowerOneCost = 10; public static int darkSteelUpgradePowerTwoCost = 20; public static int darkSteelUpgradePowerThreeCost = 30; - + public static int darkSteelGliderCost = 15; public static double darkSteelGliderHorizontalSpeed = 0.03; public static double darkSteelGliderVerticalSpeed = -0.05; public static double darkSteelGliderVerticalSpeedSprinting = -0.15; - public static float farmContinuousEnergyUse = 4; public static float farmActionEnergyUse = 50; @@ -169,8 +168,8 @@ public final class Config { public static boolean poweredSpawnerUseVanillaSpawChecks = false; public static double brokenSpawnerDropChance = 1; public static int powerSpawnerAddSpawnerCost = 30; - - + + public static double vacuumChestRange = 6; public static void load(FMLPreInitializationEvent event) { configDirectory = new File(event.getModConfigurationDirectory(), "enderio"); @@ -281,6 +280,8 @@ public final class Config { "'line of sight' distance rather than conduit path distance is used to calculate priorities.") .getBoolean(itemConduitUsePhyscialDistance); + vacuumChestRange = config.get("Efficiency Settings", "vacumChestRange", vacuumChestRange, "The range of the vacuum chest").getDouble(vacuumChestRange); + if(!useSneakMouseWheelYetaWrench && !useSneakRightClickYetaWrench) { Log.warn("Both useSneakMouseWheelYetaWrench and useSneakRightClickYetaWrench are set to false. Enabling mouse wheel."); useSneakMouseWheelYetaWrench = true; @@ -375,10 +376,10 @@ public final class Config { darkSteelBootsJumpPowerCost = config.get("Dark Steel", "darkSteelBootsJumpPowerCost", darkSteelBootsJumpPowerCost, "Base amount of power used per jump (RF) dark steel boots. The second jump in a 'double jump' uses 2x this etc").getInt(darkSteelBootsJumpPowerCost); - + darkSteelFallDistanceCost = config.get("Dark Steel", "darkSteelFallDistanceCost", darkSteelFallDistanceCost, "Amount of power used (RF) per block height of fall distance damage negated.").getInt(darkSteelFallDistanceCost); - + darkSteelGliderCost = config.get("Dark Steel", "darkSteelGliderCost", darkSteelGliderCost, "Number of levels required for the 'Glider' upgrade.").getInt(darkSteelGliderCost); darkSteelGliderHorizontalSpeed = config.get("Dark Steel", "darkSteelGliderHorizontalSpeed", darkSteelGliderHorizontalSpeed, @@ -386,7 +387,7 @@ public final class Config { darkSteelGliderVerticalSpeed = config.get("Dark Steel", "darkSteelGliderVerticalSpeed", darkSteelGliderVerticalSpeed, "Rate of altitude loss when gliding.").getDouble(darkSteelGliderVerticalSpeed); darkSteelGliderVerticalSpeedSprinting = config.get("Dark Steel", "darkSteelGliderVerticalSpeedSprinting", darkSteelGliderVerticalSpeedSprinting, - "Rate of altitude loss when sprinting and gliding.").getDouble(darkSteelGliderVerticalSpeedSprinting); + "Rate of altitude loss when sprinting and gliding.").getDouble(darkSteelGliderVerticalSpeedSprinting); darkSteelSwordSkullChance = (float) config.get("Dark Steel", "darkSteelSwordSkullChance", darkSteelSwordSkullChance, "The base chance that a skull will be dropped when using a powered dark steel sword (0 = no chance, 1 = 100% chance)").getDouble( @@ -469,10 +470,10 @@ public final class Config { "The amount of power used by a farm per action (eg plant, till, harvest) ").getDouble(farmActionEnergyUse); farmDefaultSize = config.get("Farm Settings", "farmDefaultSize", farmDefaultSize, "The number of blocks a farm will extend from its center").getInt(farmDefaultSize); - farmAxeDamageOnLeafBreak = config.get("Farm Settings", "farmAxeDamageOnLeafBreak", farmAxeDamageOnLeafBreak, - "Should axes in a farm take damage when breaking leaves?").getBoolean(farmAxeDamageOnLeafBreak); - farmToolTakeDamageChance = (float) config.get("Farm Settings", "farmToolTakeDamageChance", farmToolTakeDamageChance, - "The chance that a tool in the farm will take damage.").getDouble(farmToolTakeDamageChance); + farmAxeDamageOnLeafBreak = config.get("Farm Settings", "farmAxeDamageOnLeafBreak", farmAxeDamageOnLeafBreak, + "Should axes in a farm take damage when breaking leaves?").getBoolean(farmAxeDamageOnLeafBreak); + farmToolTakeDamageChance = (float) config.get("Farm Settings", "farmToolTakeDamageChance", farmToolTakeDamageChance, + "The chance that a tool in the farm will take damage.").getDouble(farmToolTakeDamageChance); combustionGeneratorUseOpaqueModel = config.get("Aesthetic Settings", "combustionGeneratorUseOpaqueModel", combustionGeneratorUseOpaqueModel, "If set to true: fluid will not be shown in combustion generator tanks. Improves FPS. ").getBoolean(combustionGeneratorUseOpaqueModel); @@ -491,24 +492,27 @@ public final class Config { "MJ used per autocrafted recipe").getInt(crafterMjPerCraft); poweredSpawnerMinDelayTicks = config.get("PoweredSpawner Settings", "poweredSpawnerMinDelayTicks", poweredSpawnerMinDelayTicks, - "Min tick delay between spawns for a non-upgraded spawner").getInt(poweredSpawnerMinDelayTicks); + "Min tick delay between spawns for a non-upgraded spawner").getInt(poweredSpawnerMinDelayTicks); poweredSpawnerMaxDelayTicks = config.get("PoweredSpawner Settings", "poweredSpawnerMaxDelayTicks", poweredSpawnerMaxDelayTicks, - "Min tick delay between spawns for a non-upgraded spawner").getInt(poweredSpawnerMaxDelayTicks); - poweredSpawnerLevelOnePowerPerTick = (float)config.get("PoweredSpawner Settings", "poweredSpawnerLevelOnePowerPerTick", poweredSpawnerLevelOnePowerPerTick, + "Min tick delay between spawns for a non-upgraded spawner").getInt(poweredSpawnerMaxDelayTicks); + poweredSpawnerLevelOnePowerPerTick = (float) config.get("PoweredSpawner Settings", "poweredSpawnerLevelOnePowerPerTick", + poweredSpawnerLevelOnePowerPerTick, "MJ per tick for a level 1 (non-upgraded) spawner").getDouble(poweredSpawnerLevelOnePowerPerTick); - poweredSpawnerLevelTwoPowerPerTick = (float)config.get("PoweredSpawner Settings", "poweredSpawnerLevelTwoPowerPerTick", poweredSpawnerLevelTwoPowerPerTick, + poweredSpawnerLevelTwoPowerPerTick = (float) config.get("PoweredSpawner Settings", "poweredSpawnerLevelTwoPowerPerTick", + poweredSpawnerLevelTwoPowerPerTick, "MJ per tick for a level 2 spawner").getDouble(poweredSpawnerLevelTwoPowerPerTick); - poweredSpawnerLevelThreePowerPerTick = (float)config.get("PoweredSpawner Settings", "poweredSpawnerLevelThreePowerPerTick", poweredSpawnerLevelThreePowerPerTick, + poweredSpawnerLevelThreePowerPerTick = (float) config.get("PoweredSpawner Settings", "poweredSpawnerLevelThreePowerPerTick", + poweredSpawnerLevelThreePowerPerTick, "MJ per tick for a level 3 spawner").getDouble(poweredSpawnerLevelThreePowerPerTick); poweredSpawnerMaxPlayerDistance = config.get("PoweredSpawner Settings", "poweredSpawnerMaxPlayerDistance", poweredSpawnerMaxPlayerDistance, "Max distance of the closest player for the spawner to be active. A zero value will remove the player check").getInt(poweredSpawnerMaxPlayerDistance); poweredSpawnerUseVanillaSpawChecks = config.get("PoweredSpawner Settings", "poweredSpawnerUseVanillaSpawChecks", poweredSpawnerUseVanillaSpawChecks, "If true, regular spawn checks such as lighting level and dimension will be made before spawning mobs").getBoolean(poweredSpawnerUseVanillaSpawChecks); - brokenSpawnerDropChance = (float)config.get("PoweredSpawner Settings", "brokenSpawnerDropChance", brokenSpawnerDropChance, + brokenSpawnerDropChance = (float) config.get("PoweredSpawner Settings", "brokenSpawnerDropChance", brokenSpawnerDropChance, "The chance a brokne spawner will be dropped when a spawner is broken. 1 = 100% chance, 0 = 0% chance").getDouble(brokenSpawnerDropChance); powerSpawnerAddSpawnerCost = config.get("PoweredSpawner Settings", "powerSpawnerAddSpawnerCost", powerSpawnerAddSpawnerCost, "The number of levels it costs to add a broken spawner").getInt(powerSpawnerAddSpawnerCost); - + } private Config() { diff --git a/src/main/java/crazypants/enderio/EnderIO.java b/src/main/java/crazypants/enderio/EnderIO.java index fb9dc41c..0f5fa1ce 100644 --- a/src/main/java/crazypants/enderio/EnderIO.java +++ b/src/main/java/crazypants/enderio/EnderIO.java @@ -84,6 +84,7 @@ import crazypants.enderio.machine.spawner.ItemBrokenSpawner; import crazypants.enderio.machine.still.BlockVat; import crazypants.enderio.machine.still.VatRecipeManager; import crazypants.enderio.machine.tank.BlockTank; +import crazypants.enderio.machine.vacuum.BlockVacuumChest; import crazypants.enderio.material.Alloy; import crazypants.enderio.material.BlockDarkIronBars; import crazypants.enderio.material.BlockFusedQuartz; @@ -171,6 +172,7 @@ public class EnderIO { public static BlockCrafter blockCrafter; public static BlockPoweredSpawner blockPoweredSpawner; public static ItemBrokenSpawner itemBrokenSpawner; + public static BlockVacuumChest blockVacuumChest; public static BlockElectricLight blockElectricLight; public static BlockLightNode blockLightNode; @@ -258,6 +260,7 @@ public class EnderIO { blockLightNode = BlockLightNode.create(); blockTank = BlockTank.create(); blockReservoir = BlockReservoir.create(); + blockVacuumChest = BlockVacuumChest.create(); blockDarkSteelPressurePlate = BlockDarkSteelPressurePlate.create(); diff --git a/src/main/java/crazypants/enderio/GuiHandler.java b/src/main/java/crazypants/enderio/GuiHandler.java index a92bb186..35683dea 100644 --- a/src/main/java/crazypants/enderio/GuiHandler.java +++ b/src/main/java/crazypants/enderio/GuiHandler.java @@ -39,6 +39,7 @@ public class GuiHandler implements IGuiHandler { public static final int GUI_ID_CRAFTER = 87; public static final int GUI_ID_ZOMBIE_GEN = 71; public static final int GUI_ID_POWERED_SPAWNER = 88; + public static final int GUI_ID_VACUUM_CHEST = 89; protected final Map guiHandlers = new HashMap(); diff --git a/src/main/java/crazypants/enderio/ModObject.java b/src/main/java/crazypants/enderio/ModObject.java index 6f2fe50c..fa237d53 100644 --- a/src/main/java/crazypants/enderio/ModObject.java +++ b/src/main/java/crazypants/enderio/ModObject.java @@ -47,6 +47,7 @@ public enum ModObject { blockFarmStation, blockTank, blockCrafter, + blockVacuumChest, blockPoweredSpawner, itemBrokenSpawner, diff --git a/src/main/java/crazypants/enderio/machine/MachineRecipes.java b/src/main/java/crazypants/enderio/machine/MachineRecipes.java index 2850e921..3eb5e5ca 100644 --- a/src/main/java/crazypants/enderio/machine/MachineRecipes.java +++ b/src/main/java/crazypants/enderio/machine/MachineRecipes.java @@ -130,6 +130,10 @@ public class MachineRecipes { .addShapedRecipe(mJMonitor, "bmb", "bMb", "bcb", 'b', Blocks.stonebrick, 'e', Items.ender_eye, 'M', machineChassi, 'm', mJReader, 'p', powerConduit, 'r', redstoneConduit, 'c', capacitor); + //Vacuum Chest + ItemStack vacuumChest = new ItemStack(EnderIO.blockVacuumChest); + GameRegistry.addShapedRecipe(vacuumChest, "iii", "ici","ipi", 'i', Items.iron_ingot, 'c', Blocks.chest, 'p', pulCry); + } public static void addOreDictionaryRecipes() { diff --git a/src/main/java/crazypants/enderio/machine/vacuum/BlockVacuumChest.java b/src/main/java/crazypants/enderio/machine/vacuum/BlockVacuumChest.java new file mode 100644 index 00000000..f8125a6d --- /dev/null +++ b/src/main/java/crazypants/enderio/machine/vacuum/BlockVacuumChest.java @@ -0,0 +1,98 @@ +package crazypants.enderio.machine.vacuum; + +import buildcraft.api.tools.IToolWrench; +import cpw.mods.fml.common.network.IGuiHandler; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import crazypants.enderio.BlockEio; +import crazypants.enderio.EnderIO; +import crazypants.enderio.GuiHandler; +import crazypants.enderio.ModObject; +import crazypants.enderio.conduit.ConduitUtil; +import crazypants.enderio.machine.AbstractMachineEntity; +import crazypants.enderio.machine.power.ContainerCapacitorBank; +import crazypants.enderio.machine.power.GuiCapacitorBank; +import crazypants.enderio.machine.power.TileCapacitorBank; + +public class BlockVacuumChest extends BlockEio implements IGuiHandler { + + public static BlockVacuumChest create() { + BlockVacuumChest res = new BlockVacuumChest(); + res.init(); + return res; + } + + public static int renderId; + + protected BlockVacuumChest() { + super(ModObject.blockVacuumChest.unlocalisedName, TileVacuumChest.class); + setBlockTextureName("enderio:blockVacuumChest"); + } + + @Override + protected void init() { + super.init(); + EnderIO.guiHandler.registerGuiHandler(GuiHandler.GUI_ID_VACUUM_CHEST, this); + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9) { + + if(ConduitUtil.isToolEquipped(entityPlayer)) { + if(entityPlayer.isSneaking() && entityPlayer.getCurrentEquippedItem().getItem() instanceof IToolWrench) { + IToolWrench wrench = (IToolWrench) entityPlayer.getCurrentEquippedItem().getItem(); + if(wrench.canWrench(entityPlayer, x, y, z)) { + removedByPlayer(world, entityPlayer, x, y, z); + if(entityPlayer.getCurrentEquippedItem().getItem() instanceof IToolWrench) { + ((IToolWrench) entityPlayer.getCurrentEquippedItem().getItem()).wrenchUsed(entityPlayer, x, y, z); + } + return true; + } + } + } + if(entityPlayer.isSneaking()) { + return false; + } + entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_VACUUM_CHEST, world, x, y, z); + return true; + } + + @Override + public int getRenderType() { + return renderId; + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + TileEntity te = world.getTileEntity(x, y, z); + if(te instanceof TileVacuumChest) { + return new ContainerVacuumChest(player, player.inventory, (TileVacuumChest) te); + } + return null; + } + + @Override + public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + TileEntity te = world.getTileEntity(x, y, z); + if(te instanceof TileVacuumChest) { + return new GuiVacuumChest(player, player.inventory, (TileVacuumChest) te); + } + return null; + } + + public void breakBlock(World world, int x, int y, int z, Block block, int p_149749_6_) { + super.breakBlock(world, x, y, z, block, p_149749_6_); + world.removeTileEntity(x, y, z); + } + +} diff --git a/src/main/java/crazypants/enderio/machine/vacuum/ContainerVacuumChest.java b/src/main/java/crazypants/enderio/machine/vacuum/ContainerVacuumChest.java new file mode 100644 index 00000000..303a9799 --- /dev/null +++ b/src/main/java/crazypants/enderio/machine/vacuum/ContainerVacuumChest.java @@ -0,0 +1,66 @@ +package crazypants.enderio.machine.vacuum; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class ContainerVacuumChest extends Container { + + private int numRows = 3; + + public ContainerVacuumChest(EntityPlayer player, InventoryPlayer inventory, TileVacuumChest te) { + + int x = 8; + int y = 17; + int index = -1; + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 9; ++j) { + addSlotToContainer(new Slot(te, ++index, x + j * 18, y + i * 18)); + } + } + + y = 84; + // add players inventory + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 9; ++j) { + addSlotToContainer(new Slot(inventory, j + i * 9 + 9, x + j * 18, y + i * 18)); + } + } + for (int i = 0; i < 9; ++i) { + addSlotToContainer(new Slot(inventory, i, x + i * 18, y + 58)); + } + } + + @Override + public boolean canInteractWith(EntityPlayer var1) { + return true; + } + + public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { + ItemStack itemstack = null; + Slot slot = (Slot) this.inventorySlots.get(par2); + + if(slot != null && slot.getHasStack()) { + ItemStack itemstack1 = slot.getStack(); + itemstack = itemstack1.copy(); + + if(par2 < this.numRows * 9) { + if(!this.mergeItemStack(itemstack1, this.numRows * 9, this.inventorySlots.size(), true)) { + return null; + } + } else if(!this.mergeItemStack(itemstack1, 0, this.numRows * 9, false)) { + return null; + } + + if(itemstack1.stackSize == 0) { + slot.putStack((ItemStack) null); + } else { + slot.onSlotChanged(); + } + } + return itemstack; + } + +} diff --git a/src/main/java/crazypants/enderio/machine/vacuum/GuiVacuumChest.java b/src/main/java/crazypants/enderio/machine/vacuum/GuiVacuumChest.java new file mode 100644 index 00000000..5273ca4f --- /dev/null +++ b/src/main/java/crazypants/enderio/machine/vacuum/GuiVacuumChest.java @@ -0,0 +1,25 @@ +package crazypants.enderio.machine.vacuum; + +import org.lwjgl.opengl.GL11; + +import crazypants.render.RenderUtil; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; + +public class GuiVacuumChest extends GuiContainer { + + public GuiVacuumChest(EntityPlayer player, InventoryPlayer inventory, TileVacuumChest te) { + super(new ContainerVacuumChest(player, inventory, te)); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + RenderUtil.bindTexture("enderio:textures/gui/vacumChest.png"); + int sx = (width - xSize) / 2; + int sy = (height - ySize) / 2; + drawTexturedModalRect(sx, sy, 0, 0, this.xSize, this.ySize); + } + +} diff --git a/src/main/java/crazypants/enderio/machine/vacuum/TileVacuumChest.java b/src/main/java/crazypants/enderio/machine/vacuum/TileVacuumChest.java new file mode 100644 index 00000000..fdd22aaa --- /dev/null +++ b/src/main/java/crazypants/enderio/machine/vacuum/TileVacuumChest.java @@ -0,0 +1,227 @@ +package crazypants.enderio.machine.vacuum; + +import java.util.List; + +import net.minecraft.command.IEntitySelector; +import net.minecraft.entity.Entity; +import net.minecraft.entity.IProjectile; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import crazypants.enderio.Config; +import crazypants.enderio.ModObject; +import crazypants.enderio.conduit.TileConduitBundle; +import crazypants.render.BoundingBox; +import crazypants.util.BlockCoord; +import crazypants.util.ItemUtil; + +public class TileVacuumChest extends TileEntity implements IEntitySelector, IInventory { + + + private static final double RANGE = Config.vacuumChestRange; + private ItemStack[] inv = new ItemStack[27]; + + @Override + public void updateEntity() { + if(!isFull()) { + doHoover(); + } + } + + @Override + public boolean isEntityApplicable(Entity entity) { + if(entity.isDead) { + return false; + } + if(entity instanceof IProjectile) { + return entity.motionY < 0.01; + } + if(entity instanceof EntityItem) { + ItemStack stack = ((EntityItem) entity).getEntityItem(); + return true; + } + return false; + } + + + private void doHoover() { + + BoundingBox bb = new BoundingBox(getLocation()); + AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ); + aabb = aabb.expand(RANGE, RANGE, RANGE); + List interestingItems = worldObj.selectEntitiesWithinAABB(EntityItem.class, aabb, this); + + for (EntityItem entity : interestingItems) { + double x = (xCoord + 0.5D - entity.posX); + double y = (yCoord + 0.5D - entity.posY); + double z = (zCoord + 0.5D - entity.posZ); + + double distance = Math.sqrt(x * x + y * y + z * z); + if(distance < 1.25) { + hooverEntity(entity); + } else { + double speed = 0.035; + entity.motionX += x / distance * speed; + entity.motionY += y * speed; + if(y > 0) { + entity.motionY = 0.12; + } + entity.motionZ += z / distance * speed; + } + + } + } + + private void hooverEntity(Entity entity) { + if(!worldObj.isRemote) { + if(entity instanceof EntityItem && !entity.isDead) { + EntityItem item = (EntityItem) entity; + ItemStack stack = item.getEntityItem().copy(); + + int numInserted = ItemUtil.doInsertItem(this, stack); + stack.stackSize -= numInserted; + item.setEntityItemStack(stack); + if(stack.stackSize == 0) { + item.setDead(); + } + } + } + } + + private boolean isFull() { + for(ItemStack stack : inv) { + if(stack == null || stack.stackSize < stack.getMaxStackSize()) { + return false; + } + } + return true; + } + + private BlockCoord getLocation() { + return new BlockCoord(this); + } + + @Override + public int getSizeInventory() { + return inv.length; + } + + @Override + public int getInventoryStackLimit() { + return 64; + } + + @Override + public ItemStack getStackInSlot(int slot) { + if(slot < 0 || slot >= inv.length) { + return null; + } + return inv[slot]; + } + + @Override + public ItemStack decrStackSize(int fromSlot, int amount) { + ItemStack fromStack = inv[fromSlot]; + if(fromStack == null) { + return null; + } + if(fromStack.stackSize <= amount) { + inv[fromSlot] = null; + return fromStack; + } + ItemStack result = new ItemStack(fromStack.getItem(), amount, fromStack.getItemDamage()); + if(fromStack.stackTagCompound != null) { + result.stackTagCompound = (NBTTagCompound) fromStack.stackTagCompound.copy(); + } + fromStack.stackSize -= amount; + return result; + } + + @Override + public void setInventorySlotContents(int slot, ItemStack contents) { + + if(slot < 0 || slot >= inv.length) { + System.out.println("TileVacumChest.setInventorySlotContents: " + slot); + return; + } + + if(contents == null) { + inv[slot] = contents; + } else { + inv[slot] = contents.copy(); + } + + if(contents != null && contents.stackSize > getInventoryStackLimit()) { + contents.stackSize = getInventoryStackLimit(); + } + } + + @Override + public ItemStack getStackInSlotOnClosing(int var1) { + return null; + } + + @Override + public String getInventoryName() { + return ModObject.blockVacuumChest.unlocalisedName; + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer var1) { + return true; + } + + @Override + public void openInventory() { + } + + @Override + public void closeInventory() { + } + + @Override + public boolean isItemValidForSlot(int var1, ItemStack var2) { + return true; + } + + @Override + public void readFromNBT(NBTTagCompound nbtRoot) { + super.readFromNBT(nbtRoot); + NBTTagList itemList = (NBTTagList) nbtRoot.getTag("Items"); + if(itemList != null) { + for (int i = 0; i < itemList.tagCount(); i++) { + NBTTagCompound itemStack = itemList.getCompoundTagAt(i); + byte slot = itemStack.getByte("Slot"); + if(slot >= 0 && slot < inv.length) { + inv[slot] = ItemStack.loadItemStackFromNBT(itemStack); + } + } + } + } + + @Override + public void writeToNBT(NBTTagCompound nbtRoot) { + super.writeToNBT(nbtRoot); + NBTTagList itemList = new NBTTagList(); + for (int i = 0; i < inv.length; i++) { + if(inv[i] != null) { + NBTTagCompound itemStackNBT = new NBTTagCompound(); + itemStackNBT.setByte("Slot", (byte) i); + inv[i].writeToNBT(itemStackNBT); + itemList.appendTag(itemStackNBT); + } + } + nbtRoot.setTag("Items", itemList); + } + +} diff --git a/src/main/java/crazypants/enderio/machine/vacuum/VacuumChestRenderer.java b/src/main/java/crazypants/enderio/machine/vacuum/VacuumChestRenderer.java new file mode 100644 index 00000000..f3ac3fe1 --- /dev/null +++ b/src/main/java/crazypants/enderio/machine/vacuum/VacuumChestRenderer.java @@ -0,0 +1,89 @@ +package crazypants.enderio.machine.vacuum; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.IItemRenderer; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import net.minecraftforge.client.IItemRenderer.ItemRendererHelper; +import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; +import crazypants.enderio.EnderIO; +import crazypants.render.BoundingBox; +import crazypants.render.CubeRenderer; +import crazypants.render.RenderUtil; + +public class VacuumChestRenderer implements ISimpleBlockRenderingHandler, IItemRenderer { + + @Override + public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) { + Tessellator.instance.startDrawingQuads(); + CubeRenderer.render(BoundingBox.UNIT_CUBE.scale(0.6, 0.6, 0.6), EnderIO.blockHyperCube.getIcon(0, 0)); + CubeRenderer.render(BoundingBox.UNIT_CUBE.scale(0.90, 0.90,0.90), EnderIO.blockVacuumChest.getIcon(0, 0)); + Tessellator.instance.draw(); + } + + @Override + public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { + + double size = 0.4; + renderer.renderMinX = 0.5 - size; + renderer.renderMaxX = 0.5 + size; + renderer.renderMinY = 0.5 - size; + renderer.renderMaxY = 0.5 + size; + renderer.renderMinZ = 0.5 - size; + renderer.renderMaxZ = 0.5 + size; + renderer.lockBlockBounds = true; + + renderer.setOverrideBlockTexture(EnderIO.blockHyperCube.getIcon(0, 0)); + renderer.renderStandardBlock(Blocks.stone, x, y, z); + renderer.setOverrideBlockTexture(null); + + renderer.lockBlockBounds = false; + + renderer.renderMinX = 0; + renderer.renderMaxX = 1; + renderer.renderMinY = 0; + renderer.renderMaxY = 1; + renderer.renderMinZ = 0; + renderer.renderMaxZ = 1; + + renderer.setOverrideBlockTexture(EnderIO.blockVacuumChest.getIcon(0, 0)); + renderer.renderStandardBlock(Blocks.stone, x, y, z); + renderer.setOverrideBlockTexture(null); + + return true; + } + + @Override + public boolean shouldRender3DInInventory(int modelId) { + return true; + } + + @Override + public int getRenderId() { + return EnderIO.blockVacuumChest.renderId; + } + + @Override + public boolean handleRenderType(ItemStack item, ItemRenderType type) { + return true; + } + + @Override + public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { + return true; + } + + @Override + public void renderItem(ItemRenderType type, ItemStack item, Object... data) { + renderInventoryBlock(Block.getBlockFromItem(item.getItem()), item.getItemDamage(), 0, (RenderBlocks)data[0]); + } + +}