Got crusher working

Well mostly work, still need to finish up the GUI, and finish animation.
This commit is contained in:
DarkGuardsman 2013-09-14 01:29:07 -04:00
parent 023e752f4f
commit 5b7b064397
8 changed files with 340 additions and 33 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -11,6 +11,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.assembly.client.gui.GuiEncoder;
import dark.assembly.client.gui.GuiImprinter;
import dark.assembly.client.gui.GuiProcessor;
import dark.assembly.client.render.BlockRenderingHandler;
import dark.assembly.client.render.RenderArmbot;
import dark.assembly.client.render.RenderConveyorBelt;
@ -76,6 +77,10 @@ public class ClientProxy extends CommonProxy
{
return new GuiEncoder(player.inventory, (TileEntityEncoder) tileEntity);
}
case GUI_CRUSHER:
{
return new GuiProcessor(player.inventory, (TileEntityProcessor) tileEntity);
}
}
}

View file

@ -0,0 +1,50 @@
package dark.assembly.client.gui;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ContainerFurnace;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import dark.assembly.common.AssemblyLine;
import dark.assembly.common.machine.processor.ContainerProcessor;
import dark.assembly.common.machine.processor.TileEntityProcessor;
@SideOnly(Side.CLIENT)
public class GuiProcessor extends GuiContainer
{
private static final ResourceLocation gui_texture = new ResourceLocation(AssemblyLine.instance.PREFIX + AssemblyLine.GUI_DIRECTORY + "processor.png");
private TileEntityProcessor tileEntity;
public GuiProcessor(InventoryPlayer par1InventoryPlayer, TileEntityProcessor par2TileEntityFurnace)
{
super(new ContainerProcessor(par1InventoryPlayer, par2TileEntityFurnace));
this.tileEntity = par2TileEntityFurnace;
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
String s = this.tileEntity.isInvNameLocalized() ? this.tileEntity.getInvName() : I18n.func_135053_a(this.tileEntity.getInvName());
this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 6, 4210752);
this.fontRenderer.drawString(I18n.func_135053_a("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.func_110434_K().func_110577_a(gui_texture);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
int i1;
i1 = (this.tileEntity.processingTicks / this.tileEntity.processingTime) * 24;
this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16);
}
}

View file

@ -15,11 +15,14 @@ import dark.assembly.common.imprinter.ContainerImprinter;
import dark.assembly.common.imprinter.TileEntityImprinter;
import dark.assembly.common.machine.encoder.ContainerEncoder;
import dark.assembly.common.machine.encoder.TileEntityEncoder;
import dark.assembly.common.machine.processor.ContainerProcessor;
import dark.assembly.common.machine.processor.TileEntityProcessor;
public class CommonProxy implements IGuiHandler
{
public static final int GUI_IMPRINTER = 1;
public static final int GUI_ENCODER = 2;
public static final int GUI_CRUSHER = 3;
public void preInit()
{
@ -108,6 +111,10 @@ public class CommonProxy implements IGuiHandler
if (tileEntity != null && tileEntity instanceof TileEntityEncoder)
return new ContainerEncoder(player.inventory, (TileEntityEncoder) tileEntity);
}
case GUI_CRUSHER:
{
return new ContainerProcessor(player.inventory, (TileEntityProcessor) tileEntity);
}
}
}

View file

@ -13,6 +13,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.assembly.client.render.BlockRenderingHandler;
import dark.assembly.common.AssemblyLine;
import dark.assembly.common.CommonProxy;
import dark.assembly.common.TabAssemblyLine;
import dark.core.common.DarkMain;
import dark.core.prefab.BlockMachine;
@ -34,8 +35,11 @@ public class BlockProcessor extends BlockMachine implements IExtraObjectInfo
@Override
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
//TODO activate GUI, and if GS is installed do user lock protection
//Maybe later add support for button activation to cause animation of the crusher to activate
if (!world.isRemote)
{
entityPlayer.openGui(AssemblyLine.instance, CommonProxy.GUI_CRUSHER, world, x, y, z);
return true;
}
return false;
}

View file

@ -0,0 +1,182 @@
package dark.assembly.common.machine.processor;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotFurnace;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntityFurnace;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ContainerProcessor extends Container
{
private TileEntityProcessor tileEntity;
private int lastCookTime;
private int lastEnergyLevel;
private int lastItemBurnTime;
public ContainerProcessor(InventoryPlayer par1InventoryPlayer, TileEntityProcessor tile)
{
this.tileEntity = tile;
this.addSlotToContainer(new Slot(tile, tile.slotInput, 37, 25));
this.addSlotToContainer(new Slot(tile, tile.slotBatteryCharge, 144, 19));
this.addSlotToContainer(new Slot(tile, tile.slotBatteryDrain, 144, 43));
this.addSlotToContainer(new SlotFurnace(par1InventoryPlayer.player, tile, tile.slotOutput, 95, 27));
int i;
for (i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(par1InventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(par1InventoryPlayer, i, 8 + i * 18, 142));
}
}
@Override
public void addCraftingToCrafters(ICrafting par1ICrafting)
{
super.addCraftingToCrafters(par1ICrafting);
par1ICrafting.sendProgressBarUpdate(this, 0, this.tileEntity.processingTime);
par1ICrafting.sendProgressBarUpdate(this, 1, (int) this.tileEntity.getEnergyStored());
par1ICrafting.sendProgressBarUpdate(this, 2, this.tileEntity.processingTicks);
}
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
for (int i = 0; i < this.crafters.size(); ++i)
{
ICrafting icrafting = (ICrafting) this.crafters.get(i);
if (this.lastCookTime != this.tileEntity.processingTime)
{
icrafting.sendProgressBarUpdate(this, 0, this.tileEntity.processingTime);
}
if (this.lastEnergyLevel != this.tileEntity.getEnergyStored())
{
icrafting.sendProgressBarUpdate(this, 1, (int) this.tileEntity.getEnergyStored());
}
if (this.lastItemBurnTime != this.tileEntity.processingTicks)
{
icrafting.sendProgressBarUpdate(this, 2, this.tileEntity.processingTicks);
}
}
this.lastCookTime = this.tileEntity.processingTime;
this.lastEnergyLevel = (int) this.tileEntity.getEnergyStored();
this.lastItemBurnTime = this.tileEntity.processingTicks;
}
@SideOnly(Side.CLIENT)
@Override
public void updateProgressBar(int par1, int par2)
{
if (par1 == 0)
{
this.tileEntity.processingTime = par2;
}
if (par1 == 1)
{
this.tileEntity.setEnergyStored(par2);
}
if (par1 == 2)
{
this.tileEntity.processingTicks = par2;
}
}
@Override
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
return this.tileEntity.isUseableByPlayer(par1EntityPlayer);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotID)
{
ItemStack itemstack = null;
Slot slot = (Slot) this.inventorySlots.get(slotID);
if (slot != null && slot.getHasStack())
{
ItemStack slotStack = slot.getStack();
itemstack = slotStack.copy();
if (slotID == 2)
{
if (!this.mergeItemStack(slotStack, 3, 39, true))
{
return null;
}
slot.onSlotChange(slotStack, itemstack);
}
else if (slotID != 1 && slotID != 0)
{
if (ProcessorRecipes.getOuput(tileEntity.type, slotStack) != null)
{
if (!this.mergeItemStack(slotStack, tileEntity.slotInput, 1, false))
{
return null;
}
}
else if (tileEntity.isBattery(slotStack))
{
if (!this.mergeItemStack(slotStack, tileEntity.slotBatteryCharge, 2, false))
{
return null;
}
}
else if (slotID >= 3 && slotID < 30)
{
if (!this.mergeItemStack(slotStack, 30, 39, false))
{
return null;
}
}
else if (slotID >= 30 && slotID < 39 && !this.mergeItemStack(slotStack, 3, 30, false))
{
return null;
}
}
else if (!this.mergeItemStack(slotStack, 3, 39, false))
{
return null;
}
if (slotStack.stackSize == 0)
{
slot.putStack((ItemStack) null);
}
else
{
slot.onSlotChanged();
}
if (slotStack.stackSize == itemstack.stackSize)
{
return null;
}
slot.onPickupFromSlot(player, slotStack);
}
return itemstack;
}
}

View file

@ -2,19 +2,21 @@ package dark.assembly.common.machine.processor;
import java.util.HashMap;
import dark.core.prefab.helpers.Pair;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class ProcessorRecipes
{
public static HashMap<ItemStack, ItemStack> crusherRecipes = new HashMap();
public static HashMap<ItemStack, ItemStack> grinderrRecipes = new HashMap();
public static HashMap<ItemStack, ItemStack> pressRecipes = new HashMap();
public static HashMap<Pair<Integer, Integer>, ItemStack> crusherRecipes = new HashMap();
public static HashMap<Pair<Integer, Integer>, ItemStack> grinderrRecipes = new HashMap();
public static HashMap<Pair<Integer, Integer>, ItemStack> pressRecipes = new HashMap();
static
{
createABRecipe(ProcessorType.CRUSHER, Block.stone, Block.cobblestone);
createABRecipe(ProcessorType.CRUSHER, new ItemStack(Block.stone.blockID, 1, 0), new ItemStack(Block.cobblestone.blockID, 1, 0));
}
public static void createABRecipe(ProcessorType type, Object in, Object out)
@ -25,7 +27,7 @@ public class ProcessorRecipes
ItemStack output = convert(out);
if (input != null && output != null)
{
HashMap<ItemStack, ItemStack> map = null;
HashMap<Pair<Integer, Integer>, ItemStack> map = null;
switch (type)
{
case CRUSHER:
@ -40,7 +42,7 @@ public class ProcessorRecipes
}
if (map != null && !crusherRecipes.containsKey(input))
{
crusherRecipes.put(input, output);
crusherRecipes.put(new Pair<Integer, Integer>(input.itemID, input.getItemDamage()), output);
}
}
}
@ -54,11 +56,11 @@ public class ProcessorRecipes
}
if (object instanceof Block)
{
return new ItemStack((Block) object, 1);
return new ItemStack(((Block) object).blockID, 1, -1);
}
if (object instanceof Item)
{
return new ItemStack((Item) object, 1);
return new ItemStack(((Item) object).itemID, 1, -1);
}
return null;
}
@ -69,7 +71,9 @@ public class ProcessorRecipes
{
return null;
}
HashMap<ItemStack, ItemStack> map = null;
HashMap<Pair<Integer, Integer>, ItemStack> map = null;
ItemStack testStack = stack.copy();
testStack.stackSize = 1;
switch (type)
{
case CRUSHER:
@ -82,7 +86,16 @@ public class ProcessorRecipes
map = pressRecipes;
break;
}
return map == null ? null : map.get(stack);
if (map == null)
{
return null;
}
ItemStack re = map.get(new Pair<Integer, Integer>(stack.itemID, -1));
if (re != null)
{
return re;
}
return map.get(new Pair<Integer, Integer>(stack.itemID, stack.getItemDamage()));
}
public static class oreReceipe

View file

@ -4,7 +4,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import dark.assembly.common.machine.processor.ProcessorRecipes.ProcessorType;
import dark.core.interfaces.IInvBox;
import dark.core.prefab.TileEntityMachine;
import dark.core.prefab.invgui.InvChest;
@ -13,10 +12,10 @@ import dark.core.prefab.invgui.InvChest;
* @author DarkGuardsman */
public class TileEntityProcessor extends TileEntityMachine
{
private int slotInput = 0, slotOutput = 1, slotBatteryCharge = 2, slotBatteryDrain = 3;
public int slotInput = 0, slotOutput = 1, slotBatteryCharge = 2, slotBatteryDrain = 3;
private int processingTicks = 0;
private int processingTime = 100;
public int processingTicks = 0;
public int processingTime = 100;
public int renderStage = 1;
public ProcessorType type;
@ -63,20 +62,26 @@ public class TileEntityProcessor extends TileEntityMachine
/** Can the machine process the itemStack */
public boolean canProcess()
{
ItemStack processResult = ProcessorRecipes.getOuput(this.type, this.getInventory().getStackInSlot(this.slotInput));
ItemStack inputStack = this.getInventory().getStackInSlot(this.slotInput);
ItemStack outputStack = this.getInventory().getStackInSlot(this.slotOutput);
if (processResult != null)
if (inputStack != null)
{
if (outputStack == null)
inputStack = inputStack.copy();
inputStack.stackSize = 1;
ItemStack outputResult = ProcessorRecipes.getOuput(this.type, inputStack);
if (outputResult != null)
{
return true;
}
else if (outputStack.equals(processResult))
{
if (Math.min(outputStack.getMaxStackSize() - outputStack.stackSize, this.getInventoryStackLimit()) >= processResult.stackSize)
if (outputStack == null)
{
return true;
}
else if (ItemStack.areItemStacksEqual(outputResult, outputStack))
{
if (Math.min(outputStack.getMaxStackSize() - outputStack.stackSize, this.getInventoryStackLimit()) >= outputResult.stackSize)
{
return true;
}
}
}
}
return false;
@ -85,25 +90,40 @@ public class TileEntityProcessor extends TileEntityMachine
/** Processes the itemStack */
public void process()
{
ItemStack output = ProcessorRecipes.getOuput(this.type, this.getInventory().getStackInSlot(this.slotInput));
ItemStack outputSlot = this.getInventory().getStackInSlot(this.slotOutput);
if (output != null && outputSlot != null && output.equals(outputSlot))
System.out.println("Processing stack");
ItemStack inputSlotStack = this.getInventory().getStackInSlot(this.slotInput);
ItemStack outputSlotStack = this.getInventory().getStackInSlot(this.slotOutput);
if (inputSlotStack != null)
{
ItemStack outputStack = outputSlot.copy();
outputStack.stackSize += outputSlot.stackSize;
this.getInventory().decrStackSize(this.slotInput, 1);
this.getInventory().setInventorySlotContents(this.slotOutput, outputStack);
inputSlotStack = inputSlotStack.copy();
inputSlotStack.stackSize = 1;
ItemStack receipeResult = ProcessorRecipes.getOuput(this.type, inputSlotStack);
System.out.println("Input = " + inputSlotStack.toString());
System.out.println("Output = " + (outputSlotStack == null ? "Null" : outputSlotStack.toString()));
System.out.println("Result = " + (receipeResult == null ? "Null" : receipeResult.toString()));
if (receipeResult != null && (outputSlotStack == null || ItemStack.areItemStacksEqual(outputSlotStack, receipeResult)))
{
ItemStack outputStack = outputSlotStack == null ? receipeResult : outputSlotStack.copy();
if (outputSlotStack != null)
{
outputStack.stackSize += receipeResult.stackSize;
}
this.getInventory().decrStackSize(this.slotInput, 1);
this.getInventory().setInventorySlotContents(this.slotOutput, outputStack);
}
}
}
@Override
public IInvBox getInventory()
public InvChest getInventory()
{
if (inventory == null)
{
inventory = new InvChest(this, 4);
}
return inventory;
return (InvChest) inventory;
}
@Override
@ -150,6 +170,30 @@ public class TileEntityProcessor extends TileEntityMachine
return ForgeDirection.EAST;
}
@Override
public String getInvName()
{
if (this.type == ProcessorType.CRUSHER)
{
return "gui.crushor.name";
}
if (this.type == ProcessorType.GRINDER)
{
return "gui.grinder.name";
}
if (this.type == ProcessorType.PRESS)
{
return "gui.press.name";
}
return "gui.processor.name";
}
@Override
public boolean isInvNameLocalized()
{
return false;
}
/** NBT Data */
@Override
public void readFromNBT(NBTTagCompound nbt)
@ -157,6 +201,7 @@ public class TileEntityProcessor extends TileEntityMachine
super.readFromNBT(nbt);
this.processingTicks = nbt.getInteger("processingTicks");
this.renderStage = nbt.getInteger("renderStage");
this.getInventory().loadInv(nbt);
}
@ -166,6 +211,7 @@ public class TileEntityProcessor extends TileEntityMachine
super.writeToNBT(nbt);
nbt.setInteger("processingTicks", this.processingTicks);
nbt.setInteger("renderStage", this.renderStage);
this.getInventory().saveInv(nbt);
}