diff --git a/src/main/java/com/hbm/blocks/network/CraneInserter.java b/src/main/java/com/hbm/blocks/network/CraneInserter.java index bf214709c..a617aaa10 100644 --- a/src/main/java/com/hbm/blocks/network/CraneInserter.java +++ b/src/main/java/com/hbm/blocks/network/CraneInserter.java @@ -11,6 +11,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; @@ -76,7 +77,10 @@ public class CraneInserter extends BlockCraneBase implements IEnterableBlock { if(te instanceof IInventory) { IInventory inv = (IInventory) te; - int limit = inv.getInventoryStackLimit(); + + addToInventory(inv, access, toAdd, dir.ordinal()); + + /*int limit = inv.getInventoryStackLimit(); int size = access == null ? inv.getSizeInventory() : access.length; @@ -115,7 +119,62 @@ public class CraneInserter extends BlockCraneBase implements IEnterableBlock { return; } } - } + }*/ + } + + if(toAdd != null && toAdd.stackSize > 0) { + addToInventory((TileEntityCraneInserter) world.getTileEntity(x, y, z), null, toAdd, dir.ordinal()); + } + if(toAdd != null && toAdd.stackSize > 0) { + EntityItem drop = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, toAdd.copy()); + world.spawnEntityInWorld(drop); } } + + public static ItemStack addToInventory(IInventory inv, int[] access, ItemStack toAdd, int side) { + + ISidedInventory sided = inv instanceof ISidedInventory ? (ISidedInventory) inv : null; + int limit = inv.getInventoryStackLimit(); + + int size = access == null ? inv.getSizeInventory() : access.length; + + for(int i = 0; i < size; i++) { + int index = access == null ? i : access[i]; + ItemStack stack = inv.getStackInSlot(index); + + if(stack != null && toAdd.isItemEqual(stack) && ItemStack.areItemStackTagsEqual(toAdd, stack) && stack.stackSize < Math.min(stack.getMaxStackSize(), limit)) { + + int stackLimit = Math.min(stack.getMaxStackSize(), limit); + int amount = Math.min(toAdd.stackSize, stackLimit - stack.stackSize); + + stack.stackSize += amount; + toAdd.stackSize -= amount; + + if(toAdd.stackSize == 0) { + return null; + } + } + } + + for(int i = 0; i < size; i++) { + int index = access == null ? i : access[i]; + ItemStack stack = inv.getStackInSlot(index); + + if(stack == null && (sided != null ? sided.canInsertItem(index, toAdd, side) : inv.isItemValidForSlot(index, toAdd))) { + + int amount = Math.min(toAdd.stackSize, limit); + + ItemStack newStack = toAdd.copy(); + newStack.stackSize = amount; + inv.setInventorySlotContents(index, newStack); + toAdd.stackSize -= amount; + + if(toAdd.stackSize == 0) { + return null; + } + } + } + + return toAdd; + } } diff --git a/src/main/java/com/hbm/entity/item/EntityMovingItem.java b/src/main/java/com/hbm/entity/item/EntityMovingItem.java index 7f3bba107..38cbb86c7 100644 --- a/src/main/java/com/hbm/entity/item/EntityMovingItem.java +++ b/src/main/java/com/hbm/entity/item/EntityMovingItem.java @@ -184,6 +184,21 @@ public class EntityMovingItem extends Entity implements IConveyorItem { enterable.onEnter(worldObj, newPos.getX(), newPos.getY(), newPos.getZ(), dir, this); this.setDead(); } + } else { + + if(!newBlock.getMaterial().isSolid()) { + + newBlock = worldObj.getBlock(newPos.getX(), newPos.getY() - 1, newPos.getZ()); + + if(newBlock instanceof IEnterableBlock) { + + IEnterableBlock enterable = (IEnterableBlock) newBlock; + if(enterable.canEnter(worldObj, newPos.getX(), newPos.getY() - 1, newPos.getZ(), ForgeDirection.UP, this)) { + enterable.onEnter(worldObj, newPos.getX(), newPos.getY() - 1, newPos.getZ(), ForgeDirection.UP, this); + this.setDead(); + } + } + } } } } diff --git a/src/main/java/com/hbm/inventory/container/ContainerCraneInserter.java b/src/main/java/com/hbm/inventory/container/ContainerCraneInserter.java index ff9848108..ad08c4a45 100644 --- a/src/main/java/com/hbm/inventory/container/ContainerCraneInserter.java +++ b/src/main/java/com/hbm/inventory/container/ContainerCraneInserter.java @@ -23,12 +23,12 @@ public class ContainerCraneInserter extends Container { for(int i = 0; i < 3; i++) { for(int j = 0; j < 9; j++) { - this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18 + 20)); + this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 103 + i * 18)); } } for(int i = 0; i < 9; i++) { - this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 142 + 20)); + this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 161)); } } diff --git a/src/main/java/com/hbm/items/ItemEnumMulti.java b/src/main/java/com/hbm/items/ItemEnumMulti.java index 2419ae0c6..762634440 100644 --- a/src/main/java/com/hbm/items/ItemEnumMulti.java +++ b/src/main/java/com/hbm/items/ItemEnumMulti.java @@ -17,8 +17,8 @@ public class ItemEnumMulti extends Item { //hell yes, now we're thinking with enums! protected Class theEnum; - private boolean multiName; - private boolean multiTexture; + protected boolean multiName; + protected boolean multiTexture; public ItemEnumMulti(Class theEnum, boolean multiName, boolean multiTexture) { this.setHasSubtypes(true); @@ -42,7 +42,7 @@ public class ItemEnumMulti extends Item { return this; } - private IIcon[] icons; + protected IIcon[] icons; @SideOnly(Side.CLIENT) public void registerIcons(IIconRegister reg) { diff --git a/src/main/java/com/hbm/items/ItemGenericPart.java b/src/main/java/com/hbm/items/ItemGenericPart.java new file mode 100644 index 000000000..3e87bb0ca --- /dev/null +++ b/src/main/java/com/hbm/items/ItemGenericPart.java @@ -0,0 +1,39 @@ +package com.hbm.items; + +import com.hbm.lib.RefStrings; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.util.IIcon; + +public class ItemGenericPart extends ItemEnumMulti { + + public static enum EnumPartTpe { + PISTON_PNEUMATIC("piston_pneumatic"), + PISTON_HYDRAULIC("piston_hydraulic"), + PISTON_ELECTRIC("piston_electric"); + + private String texName; + + private EnumPartTpe(String texName) { + this.texName = texName; + } + } + + public ItemGenericPart() { + super(EnumPartTpe.class, true, true); + } + + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister reg) { + + Enum[] enums = theEnum.getEnumConstants(); + this.icons = new IIcon[enums.length]; + + for(int i = 0; i < icons.length; i++) { + EnumPartTpe num = (EnumPartTpe)enums[i]; + this.icons[i] = reg.registerIcon(RefStrings.MODID + ":" + num.texName); + } + } +} diff --git a/src/main/java/com/hbm/items/ModItems.java b/src/main/java/com/hbm/items/ModItems.java index 1318911e2..434a9270c 100644 --- a/src/main/java/com/hbm/items/ModItems.java +++ b/src/main/java/com/hbm/items/ModItems.java @@ -314,6 +314,7 @@ public class ModItems { public static Item sat_base; public static Item thruster_nuclear; public static Item safety_fuse; + public static Item part_generic; public static Item undefined; @@ -2681,6 +2682,7 @@ public class ModItems { sat_base = new Item().setUnlocalizedName("sat_base").setCreativeTab(MainRegistry.partsTab).setTextureName(RefStrings.MODID + ":sat_base"); thruster_nuclear = new Item().setUnlocalizedName("thruster_nuclear").setCreativeTab(MainRegistry.partsTab).setTextureName(RefStrings.MODID + ":thruster_nuclear"); safety_fuse = new Item().setUnlocalizedName("safety_fuse").setCreativeTab(MainRegistry.partsTab).setTextureName(RefStrings.MODID + ":safety_fuse"); + part_generic = new ItemGenericPart().setUnlocalizedName("part_generic").setCreativeTab(MainRegistry.partsTab).setTextureName(RefStrings.MODID + ":part_generic"); undefined = new ItemCustomLore().setUnlocalizedName("undefined").setCreativeTab(MainRegistry.partsTab).setTextureName(RefStrings.MODID + ":undefined"); @@ -6190,6 +6192,7 @@ public class ModItems { GameRegistry.registerItem(chlorine_pinwheel, chlorine_pinwheel.getUnlocalizedName()); GameRegistry.registerItem(ring_starmetal, ring_starmetal.getUnlocalizedName()); GameRegistry.registerItem(deuterium_filter, deuterium_filter.getUnlocalizedName()); + GameRegistry.registerItem(part_generic, part_generic.getUnlocalizedName()); GameRegistry.registerItem(parts_legendary, parts_legendary.getUnlocalizedName()); //Plant Products diff --git a/src/main/java/com/hbm/main/CraftingManager.java b/src/main/java/com/hbm/main/CraftingManager.java index 66f82c33b..c35eae0b3 100644 --- a/src/main/java/com/hbm/main/CraftingManager.java +++ b/src/main/java/com/hbm/main/CraftingManager.java @@ -16,6 +16,7 @@ import static com.hbm.inventory.OreDictManager.*; import com.hbm.items.ModItems; import com.hbm.items.ItemEnums.EnumLegendaryType; import com.hbm.items.ItemEnums.EnumPlantType; +import com.hbm.items.ItemGenericPart.EnumPartTpe; import com.hbm.items.machine.ItemBattery; import com.hbm.items.special.ItemCircuitStarComponent.CircuitComponentType; import com.hbm.items.special.ItemHolotapeImage.EnumHoloImage; @@ -915,6 +916,11 @@ public class CraftingManager { addShapelessAuto(new ItemStack(ModItems.canister_full, 1, Fluids.BIOFUEL.getID()), new Object[] { ModItems.canister_biofuel }); addShapelessAuto(new ItemStack(ModItems.canister_full, 1, Fluids.ETHANOL.getID()), new Object[] { ModItems.canister_ethanol }); + addRecipeAuto(DictFrame.fromOne(ModItems.part_generic, EnumPartTpe.PISTON_PNEUMATIC, 4), new Object[] { " I ", "CPC", " I ", 'I', IRON.ingot(), 'C', CU.ingot(), 'P', IRON.plate() }); + addRecipeAuto(DictFrame.fromOne(ModItems.part_generic, EnumPartTpe.PISTON_HYDRAULIC, 4), new Object[] { " I ", "CPC", " I ", 'I', STEEL.ingot(), 'C', TI.ingot(), 'P', Fluids.LUBRICANT.getDict(1000) }); + addRecipeAuto(DictFrame.fromOne(ModItems.part_generic, EnumPartTpe.PISTON_ELECTRIC, 4), new Object[] { " I ", "CPC", " I ", 'I', TCALLOY.ingot(), 'C', ANY_PLASTIC.ingot(), 'P', ModItems.motor }); + + addShapelessAuto(DictFrame.fromOne(ModItems.parts_legendary, EnumLegendaryType.TIER1), new Object[] { ModItems.ingot_chainsteel, ASBESTOS.ingot(), ModItems.gem_alexandrite }); addShapelessAuto(DictFrame.fromOne(ModItems.parts_legendary, EnumLegendaryType.TIER1, 3), new Object[] { DictFrame.fromOne(ModItems.parts_legendary, EnumLegendaryType.TIER2) }); addShapelessAuto(DictFrame.fromOne(ModItems.parts_legendary, EnumLegendaryType.TIER2), new Object[] { ModItems.ingot_chainsteel, ModItems.ingot_bismuth, ModItems.gem_alexandrite, ModItems.gem_alexandrite }); diff --git a/src/main/java/com/hbm/render/entity/item/RenderMovingItem.java b/src/main/java/com/hbm/render/entity/item/RenderMovingItem.java index 1115a27bf..92747da0f 100644 --- a/src/main/java/com/hbm/render/entity/item/RenderMovingItem.java +++ b/src/main/java/com/hbm/render/entity/item/RenderMovingItem.java @@ -1,5 +1,7 @@ package com.hbm.render.entity.item; +import java.util.Random; + import org.lwjgl.opengl.GL11; import com.hbm.entity.item.EntityMovingItem; @@ -20,6 +22,9 @@ public class RenderMovingItem extends Render { GL11.glPushMatrix(); GL11.glTranslated(x, y, z); + + Random rand = new Random(entity.getEntityId()); + GL11.glTranslated(0, rand.nextDouble() * 0.0625, 0); EntityMovingItem item = (EntityMovingItem) entity; ItemStack stack = item.getItemStack().copy(); diff --git a/src/main/java/com/hbm/tileentity/TileMappings.java b/src/main/java/com/hbm/tileentity/TileMappings.java index 73d9c279a..3101835ac 100644 --- a/src/main/java/com/hbm/tileentity/TileMappings.java +++ b/src/main/java/com/hbm/tileentity/TileMappings.java @@ -315,6 +315,9 @@ public class TileMappings { put(TileEntityPylon.class, "tileentity_pylon_redwire"); put(TileEntityPylonLarge.class, "tileentity_pylon_large"); put(TileEntitySubstation.class, "tileentity_substation"); + + put(TileEntityCraneInserter.class, "tileentity_inserter"); + put(TileEntityCraneExtractor.class, "tileentity_extractor"); } private static void put(Class clazz, String... names) { diff --git a/src/main/java/com/hbm/tileentity/network/TileEntityCraneExtractor.java b/src/main/java/com/hbm/tileentity/network/TileEntityCraneExtractor.java index 95a3561a2..4d1d5f2f2 100644 --- a/src/main/java/com/hbm/tileentity/network/TileEntityCraneExtractor.java +++ b/src/main/java/com/hbm/tileentity/network/TileEntityCraneExtractor.java @@ -1,7 +1,17 @@ package com.hbm.tileentity.network; +import com.hbm.entity.item.EntityMovingItem; import com.hbm.tileentity.TileEntityMachineBase; +import api.hbm.conveyor.IConveyorBelt; +import net.minecraft.block.Block; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Vec3; +import net.minecraftforge.common.util.ForgeDirection; + public class TileEntityCraneExtractor extends TileEntityMachineBase { public TileEntityCraneExtractor() { @@ -16,5 +26,46 @@ public class TileEntityCraneExtractor extends TileEntityMachineBase { @Override public void updateEntity() { + if(!worldObj.isRemote && worldObj.getTotalWorldTime() % 20 == 0) { + + int amount = 16; + + ForgeDirection dir = ForgeDirection.getOrientation(this.blockMetadata); + TileEntity te = worldObj.getTileEntity(xCoord - dir.offsetX, yCoord - dir.offsetY, zCoord - dir.offsetZ); + Block b = worldObj.getBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ); + + int[] access = null; + ISidedInventory sided = null; + + if(te instanceof ISidedInventory) { + sided = (ISidedInventory) te; + access = sided.getAccessibleSlotsFromSide(dir.ordinal()); + } + + if(b instanceof IConveyorBelt && te instanceof IInventory) { + IInventory inv = (IInventory) te; + int size = access == null ? inv.getSizeInventory() : access.length; + + for(int i = 0; i < size; i++) { + int index = access == null ? i : access[i]; + ItemStack stack = inv.getStackInSlot(index); + + if(stack != null && (sided == null || sided.canExtractItem(index, stack, dir.ordinal()))){ + stack = stack.copy(); + int toSend = Math.min(amount, stack.stackSize); + inv.decrStackSize(index, toSend); + stack.stackSize = toSend; + + EntityMovingItem moving = new EntityMovingItem(worldObj); + Vec3 pos = Vec3.createVectorHelper(xCoord + 0.5 + dir.offsetX * 0.55, yCoord + 0.5 + dir.offsetY * 0.55, zCoord + 0.5 + dir.offsetZ * 0.55); + Vec3 snap = ((IConveyorBelt) b).getClosestSnappingPosition(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, pos); + moving.setPosition(snap.xCoord, snap.yCoord, snap.zCoord); + moving.setItemStack(stack); + worldObj.spawnEntityInWorld(moving); + break; + } + } + } + } } } diff --git a/src/main/java/com/hbm/tileentity/network/TileEntityCraneInserter.java b/src/main/java/com/hbm/tileentity/network/TileEntityCraneInserter.java index bcfca593c..e5e3e90ff 100644 --- a/src/main/java/com/hbm/tileentity/network/TileEntityCraneInserter.java +++ b/src/main/java/com/hbm/tileentity/network/TileEntityCraneInserter.java @@ -1,5 +1,6 @@ package com.hbm.tileentity.network; +import com.hbm.blocks.network.CraneInserter; import com.hbm.inventory.container.ContainerCraneInserter; import com.hbm.inventory.gui.GUICraneInserter; import com.hbm.tileentity.IGUIProvider; @@ -10,7 +11,12 @@ import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; public class TileEntityCraneInserter extends TileEntityMachineBase implements IGUIProvider { @@ -26,6 +32,39 @@ public class TileEntityCraneInserter extends TileEntityMachineBase implements IG @Override public void updateEntity() { + if(!worldObj.isRemote) { + + ForgeDirection dir = ForgeDirection.getOrientation(this.blockMetadata); + TileEntity te = worldObj.getTileEntity(xCoord - dir.offsetX, yCoord - dir.offsetY, zCoord - dir.offsetZ); + + int[] access = null; + + if(te instanceof ISidedInventory) { + ISidedInventory sided = (ISidedInventory) te; + access = sided.getAccessibleSlotsFromSide(dir.ordinal()); + } + + if(te instanceof IInventory) { + for(int i = 0; i < slots.length; i++) { + + ItemStack stack = slots[i]; + + if(stack != null) { + ItemStack ret = CraneInserter.addToInventory((ISidedInventory) te, access, stack.copy(), dir.ordinal()); + + if(ret == null || ret.stackSize != stack.stackSize) { + slots[i] = ret; + break; + } + } + } + } + } + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemStack) { + return true; } @Override diff --git a/src/main/resources/assets/hbm/lang/de_DE.lang b/src/main/resources/assets/hbm/lang/de_DE.lang index a633cadc1..28ff298e5 100644 --- a/src/main/resources/assets/hbm/lang/de_DE.lang +++ b/src/main/resources/assets/hbm/lang/de_DE.lang @@ -2111,6 +2111,9 @@ item.pancake.name=Pfannkuchen aus Altmetall, Nägeln und Edelsteinpulver item.part_beryllium.name=Berylliumstaubkiste item.part_carbon.name=Kohlenstoffstaubkiste item.part_copper.name=Kupferstaubkiste +item.part_generic.piston_electric.name=Electrischer Kolben +item.part_generic.piston_hydraulic.name=Hydraulischer Kolben +item.part_generic.piston_pneumatic.name=Pneumatischer Kolben item.part_lithium.name=Lithiumstaubkiste item.part_plutonium.name=Plutoniumstaubkiste item.particle_aelectron.name=Positronenkapsel diff --git a/src/main/resources/assets/hbm/lang/en_US.lang b/src/main/resources/assets/hbm/lang/en_US.lang index fe780307e..f0fb54273 100644 --- a/src/main/resources/assets/hbm/lang/en_US.lang +++ b/src/main/resources/assets/hbm/lang/en_US.lang @@ -2385,6 +2385,9 @@ item.pancake.name=Pancake made from Scrap Metal, Nails and Gem Dust item.part_beryllium.name=Box of Beryllium Dust item.part_carbon.name=Box of Carbon Dust item.part_copper.name=Box of Copper Dust +item.part_generic.piston_electric.name=Electric Piston +item.part_generic.piston_hydraulic.name=Hydraulic Piston +item.part_generic.piston_pneumatic.name=Pneumatic Piston item.part_lithium.name=Box of Lithium Dust item.part_plutonium.name=Box of Plutonium Dust item.particle_aelectron.name=Positron Capsule diff --git a/src/main/resources/assets/hbm/textures/items/piston_electric.png b/src/main/resources/assets/hbm/textures/items/piston_electric.png new file mode 100644 index 000000000..3d8285ff9 Binary files /dev/null and b/src/main/resources/assets/hbm/textures/items/piston_electric.png differ diff --git a/src/main/resources/assets/hbm/textures/items/upgrade_ejector_1.png b/src/main/resources/assets/hbm/textures/items/upgrade_ejector_1.png new file mode 100644 index 000000000..6395bf3ce Binary files /dev/null and b/src/main/resources/assets/hbm/textures/items/upgrade_ejector_1.png differ diff --git a/src/main/resources/assets/hbm/textures/items/upgrade_ejector_2.png b/src/main/resources/assets/hbm/textures/items/upgrade_ejector_2.png new file mode 100644 index 000000000..60a957235 Binary files /dev/null and b/src/main/resources/assets/hbm/textures/items/upgrade_ejector_2.png differ diff --git a/src/main/resources/assets/hbm/textures/items/upgrade_ejector_3.png b/src/main/resources/assets/hbm/textures/items/upgrade_ejector_3.png new file mode 100644 index 000000000..f79171126 Binary files /dev/null and b/src/main/resources/assets/hbm/textures/items/upgrade_ejector_3.png differ diff --git a/src/main/resources/assets/hbm/textures/items/upgrade_stack_1.png b/src/main/resources/assets/hbm/textures/items/upgrade_stack_1.png new file mode 100644 index 000000000..a478d4b05 Binary files /dev/null and b/src/main/resources/assets/hbm/textures/items/upgrade_stack_1.png differ diff --git a/src/main/resources/assets/hbm/textures/items/upgrade_stack_2.png b/src/main/resources/assets/hbm/textures/items/upgrade_stack_2.png new file mode 100644 index 000000000..b2bcf0eeb Binary files /dev/null and b/src/main/resources/assets/hbm/textures/items/upgrade_stack_2.png differ diff --git a/src/main/resources/assets/hbm/textures/items/upgrade_stack_3.png b/src/main/resources/assets/hbm/textures/items/upgrade_stack_3.png new file mode 100644 index 000000000..705d1dbde Binary files /dev/null and b/src/main/resources/assets/hbm/textures/items/upgrade_stack_3.png differ