got the salvaging system working

This commit is contained in:
DarkGuardsman 2013-09-17 06:09:56 -04:00
parent c4c9922aa8
commit 0cac9216b8
5 changed files with 112 additions and 56 deletions

View file

@ -171,8 +171,8 @@ public class ModelGrinder extends ModelBase
//Set new rotation angle
for (int i = 0; i < 6; i++)
{
topDiskSet[i].offsetX += rotation;
bottomDiskSet[i].offsetX -= rotation;
topDiskSet[i].rotateAngleX += rotation;
bottomDiskSet[i].rotateAngleX -= rotation;
}
//render
@ -191,22 +191,22 @@ public class ModelGrinder extends ModelBase
{
if (i == 0 || i % 2 == 0)
{
topDiskSet[i].offsetX = 0.7853982F;
topDiskSet[i].rotateAngleX = 0.7853982F;
}
else
{
topDiskSet[i].offsetX = 0F;
topDiskSet[i].rotateAngleX = 0F;
}
}
for (int i = 0; i < bottomDiskSet.length; i++)
{
if (i != 0 && i % 2 != 0)
{
bottomDiskSet[i].offsetX = 0.7853982F;
bottomDiskSet[i].rotateAngleX = 0.7853982F;
}
else
{
bottomDiskSet[i].offsetX = 0F;
bottomDiskSet[i].rotateAngleX = 0F;
}
}

View file

@ -51,21 +51,22 @@ public class RenderProcessor extends RenderTileMachine
GL11.glRotatef(270f, 0f, 1f, 0f);
}
if (tileEntity.blockMetadata >= 0 && tileEntity.blockMetadata <= 3)
int g = tileEntity.blockMetadata / 4;
if (g == 0)
{
crusherModel.renderBody(0.0625F);
crusherModel.renderPiston(0.0625F, tileEntity.renderStage);
}
else if (tileEntity.blockMetadata >= 4 && tileEntity.blockMetadata <= 7)
else if (g == 1)
{
grinderModel.renderBody(0.0625F);
grinderModel.renderRotation(0.0625F, tileEntity.renderStage);
}
else if (tileEntity.blockMetadata >= 8 && tileEntity.blockMetadata <= 11)
else if (g == 2)
{
}
else if (tileEntity.blockMetadata >= 12 && tileEntity.blockMetadata <= 15)
else if (g == 3)
{
}
@ -82,8 +83,17 @@ public class RenderProcessor extends RenderTileMachine
@Override
public ResourceLocation getTexture(int block, int meta)
{
int g = meta / 4;
if (g == 0)
{
return new ResourceLocation(AssemblyLine.instance.DOMAIN, AssemblyLine.MODEL_DIRECTORY + "CrusherBlock.png");
}
else if (g == 1)
{
return new ResourceLocation(AssemblyLine.instance.DOMAIN, AssemblyLine.MODEL_DIRECTORY + "GrinderBlock.png");
}
return null;
}
}

View file

@ -41,18 +41,18 @@ 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)
{
if (!world.isRemote)
if (entityPlayer != null)
{
if (world.isRemote)
{
return true;
}
else
{
entityPlayer.openGui(AssemblyLine.instance, CommonProxy.GUI_CRUSHER, world, x, y, z);
return true;
}
return false;
}
@Override
public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
//Open machine calibration menu
return false;
}
@ -76,7 +76,7 @@ public class BlockProcessor extends BlockMachine implements IExtraObjectInfo
@Override
public void getTileEntities(int blockID, Set<Pair<String, Class<? extends TileEntity>>> list)
{
list.add(new Pair<String, Class<? extends TileEntity>>("ALProcessor", TileEntityProcessor.class));
list.add(new Pair<String, Class<? extends TileEntity>>("ALOreProcessor", TileEntityProcessor.class));
}
@Override

View file

@ -128,7 +128,7 @@ public class ContainerProcessor extends Container
}
else if (slotID != 1 && slotID != 0)
{
if (ProcessorRecipes.getOuput(tileEntity.type, slotStack) != null)
if (ProcessorRecipes.getOuput(tileEntity.getProcessorData().type, slotStack) != null)
{
if (!this.mergeItemStack(slotStack, tileEntity.slotInput, 1, false))
{

View file

@ -27,23 +27,29 @@ public class TileEntityProcessor extends TileEntityMachine
public int processingTime = 100;
public int renderStage = 1;
public ProcessorType type;
public ProcessorData processorData;
public boolean invertPiston = false;
protected ItemStack[] outputBuffer;
public ProcessorData getProcessorData()
{
if (this.processorData == null)
{
int g = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord) / 4;
this.processorData = ProcessorData.values()[g];
this.WATTS_PER_TICK = processorData.wattPerTick;
this.MAX_WATTS = this.WATTS_PER_TICK * 20;
this.processingTime = processorData.processingTicks;
}
return processorData;
}
@Override
public void updateEntity()
{
if (this.type == null)
{
int g = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord) / 4;
ProcessorData data = ProcessorData.values()[g];
this.WATTS_PER_TICK = data.wattPerTick;
this.MAX_WATTS = this.WATTS_PER_TICK * 20;
this.processingTicks = data.processingTicks;
}
this.getProcessorData();
super.updateEntity();
if (this.running)
{
@ -51,11 +57,52 @@ public class TileEntityProcessor extends TileEntityMachine
if (!this.worldObj.isRemote)
{
if (this.processingTicks++ >= this.processingTime)
if (this.outputBuffer != null)
{
int nullCount = 0;
for (int i = 0; i < outputBuffer.length; i++)
{
ItemStack outputStack = this.getInventory().getStackInSlot(this.slotOutput);
if (outputBuffer[i] == null)
{
nullCount += 1;
}
else if (outputStack == null)
{
this.getInventory().setInventorySlotContents(this.slotOutput, outputBuffer[i].copy());
outputBuffer[i] = null;
}
else if (outputBuffer[i] != null && outputBuffer[i].isItemEqual(outputStack))
{
ItemStack outStack = outputStack.copy();
int room = Math.min(outputStack.getMaxStackSize() - outputStack.stackSize, this.getInventoryStackLimit());
if (room >= outputBuffer[i].stackSize)
{
outStack.stackSize += outputBuffer[i].stackSize;
outputBuffer[i] = null;
}
else
{
int extract = outputBuffer[i].stackSize - (outputBuffer[i].stackSize - room);
outputBuffer[i].stackSize -= extract;
outStack.stackSize += extract;
}
this.getInventory().setInventorySlotContents(this.slotOutput, outStack);
}
}
if (nullCount >= outputBuffer.length)
{
outputBuffer = null;
}
}
if (outputBuffer == null && this.processingTicks++ >= this.processingTime)
{
this.processingTicks = 0;
this.process();
this.processingTicks = 0;
}
}
}
@ -63,7 +110,7 @@ public class TileEntityProcessor extends TileEntityMachine
public void doAnimation()
{
if (this.type == ProcessorType.CRUSHER || this.type == ProcessorType.PRESS)
if (this.getProcessorData().type == ProcessorType.CRUSHER || this.getProcessorData().type == ProcessorType.PRESS)
{
if (invertPiston)
{
@ -104,22 +151,28 @@ public class TileEntityProcessor extends TileEntityMachine
{
inputStack = inputStack.copy();
inputStack.stackSize = 1;
ItemStack outputResult = ProcessorRecipes.getOuput(this.type, inputStack);
ItemStack[] outputResult = ProcessorRecipes.getOuput(this.getProcessorData().type, inputStack);
if (outputResult != null)
{
if (outputStack == null)
{
return true;
}
else if (outputResult.isItemEqual(outputStack))
else
{
if (Math.min(outputStack.getMaxStackSize() - outputStack.stackSize, this.getInventoryStackLimit()) >= outputResult.stackSize)
for (int i = 0; i < outputResult.length; i++)
{
if (outputResult[i] != null && outputResult[i].isItemEqual(outputStack))
{
if (Math.min(outputStack.getMaxStackSize() - outputStack.stackSize, this.getInventoryStackLimit()) >= outputResult[i].stackSize)
{
return true;
}
}
}
}
}
}
return false;
}
@ -127,23 +180,16 @@ public class TileEntityProcessor extends TileEntityMachine
public void process()
{
ItemStack inputSlotStack = this.getInventory().getStackInSlot(this.slotInput);
ItemStack outputSlotStack = this.getInventory().getStackInSlot(this.slotOutput);
if (inputSlotStack != null)
{
inputSlotStack = inputSlotStack.copy();
inputSlotStack.stackSize = 1;
ItemStack receipeResult = ProcessorRecipes.getOuput(this.type, inputSlotStack);
if (receipeResult != null && (outputSlotStack == null || outputSlotStack.isItemEqual(receipeResult)))
ItemStack[] receipeResult = ProcessorRecipes.getOuput(this.getProcessorData().type, inputSlotStack);
if (receipeResult != null && this.outputBuffer == null)
{
ItemStack outputStack = outputSlotStack == null ? receipeResult.copy() : outputSlotStack.copy();
if (outputSlotStack != null)
{
outputStack.stackSize += receipeResult.stackSize;
}
this.getInventory().decrStackSize(this.slotInput, 1);
this.getInventory().setInventorySlotContents(this.slotOutput, outputStack);
this.outputBuffer = receipeResult;
}
}
}
@ -161,7 +207,7 @@ public class TileEntityProcessor extends TileEntityMachine
@Override
public boolean canStore(ItemStack stack, int slot, ForgeDirection side)
{
if (slotInput == slot && ProcessorRecipes.getOuput(this.type, stack) != null)
if (slotInput == slot && ProcessorRecipes.getOuput(this.getProcessorData().type, stack) != null)
{
return true;
}
@ -204,9 +250,9 @@ public class TileEntityProcessor extends TileEntityMachine
@Override
public String getInvName()
{
if (this.type != null)
if (this.getProcessorData() != null)
{
return type.unlocalizedContainerName;
return "gui." + getProcessorData().unlocalizedName + ".name";
}
return "gui.processor.name";
}