finished inserter + basic extractor functionality
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -17,8 +17,8 @@ public class ItemEnumMulti extends Item {
|
||||
|
||||
//hell yes, now we're thinking with enums!
|
||||
protected Class<? extends Enum> theEnum;
|
||||
private boolean multiName;
|
||||
private boolean multiTexture;
|
||||
protected boolean multiName;
|
||||
protected boolean multiTexture;
|
||||
|
||||
public ItemEnumMulti(Class<? extends Enum> 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) {
|
||||
|
||||
39
src/main/java/com/hbm/items/ItemGenericPart.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
|
||||
@ -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 });
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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<? extends TileEntity> clazz, String... names) {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
BIN
src/main/resources/assets/hbm/textures/items/piston_electric.png
Normal file
|
After Width: | Height: | Size: 370 B |
|
After Width: | Height: | Size: 403 B |
|
After Width: | Height: | Size: 409 B |
|
After Width: | Height: | Size: 373 B |
BIN
src/main/resources/assets/hbm/textures/items/upgrade_stack_1.png
Normal file
|
After Width: | Height: | Size: 407 B |
BIN
src/main/resources/assets/hbm/textures/items/upgrade_stack_2.png
Normal file
|
After Width: | Height: | Size: 405 B |
BIN
src/main/resources/assets/hbm/textures/items/upgrade_stack_3.png
Normal file
|
After Width: | Height: | Size: 391 B |