Made the Ore Magnet accept and use Power and oil

This commit is contained in:
Ellpeck 2015-07-30 23:07:31 +02:00
parent b5b8730642
commit e72b8a8fbd
3 changed files with 90 additions and 43 deletions

View file

@ -21,10 +21,11 @@ public class ContainerOreMagnet extends Container{
public ContainerOreMagnet(InventoryPlayer inventory, TileEntityBase tile){
this.magnet = (TileEntityOreMagnet)tile;
this.addSlotToContainer(new Slot(this.magnet, 0, 98, 74));
this.addSlotToContainer(new SlotOutput(this.magnet, 1, 98, 43));
this.addSlotToContainer(new Slot(this.magnet, TileEntityOreMagnet.SLOT_OIL_INPUT, 98, 74));
this.addSlotToContainer(new SlotOutput(this.magnet, TileEntityOreMagnet.SLOT_OIL_OUTPUT, 98, 43));
this.addSlotToContainer(new SlotOutput(this.magnet, 2, 71, 43));
//TODO Change away from SlotOutput when implementing upgrades
this.addSlotToContainer(new SlotOutput(this.magnet, TileEntityOreMagnet.SLOT_UPGRADE, 71, 43));
for (int i = 0; i < 3; i++){
for (int j = 0; j < 9; j++){
@ -43,7 +44,7 @@ public class ContainerOreMagnet extends Container{
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot){
final int inventoryStart = 2;
final int inventoryStart = 3;
final int inventoryEnd = inventoryStart+26;
final int hotbarStart = inventoryEnd+1;
final int hotbarEnd = hotbarStart+8;
@ -57,9 +58,8 @@ public class ContainerOreMagnet extends Container{
//Other Slots in Inventory excluded
if(slot >= inventoryStart){
//Shift from Inventory
//TODO
if(FluidContainerRegistry.containsFluid(newStack, new FluidStack(InitBlocks.fluidOil, 1))){
if(!this.mergeItemStack(newStack, 0, 1, false)) return null;
if(!this.mergeItemStack(newStack, TileEntityOreMagnet.SLOT_OIL_INPUT, TileEntityOreMagnet.SLOT_OIL_INPUT+1, false)) return null;
}
//

View file

@ -12,6 +12,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import java.util.Arrays;
import java.util.Collections;
@SideOnly(Side.CLIENT)
@ -47,6 +48,11 @@ public class GuiOreMagnet extends GuiContainer{
int i = this.magnet.getEnergyScaled(83);
drawTexturedModalRect(this.guiLeft+43, this.guiTop+89-i, 176, 0, 16, i);
}
if(this.magnet.tank.getFluidAmount() > 0){
int i = this.magnet.getTankScaled(83);
drawTexturedModalRect(this.guiLeft+117, this.guiTop+89-i, 192, 0, 16, i);
}
}
@Override
@ -60,5 +66,9 @@ public class GuiOreMagnet extends GuiContainer{
if(x >= guiLeft+117 && y >= guiTop+6 && x <= guiLeft+132 && y <= guiTop+88){
this.func_146283_a(Collections.singletonList(text2), x, y);
}
//TODO Upgrade Slot Joke
if(x >= guiLeft+70 && y >= guiTop+42 && x <= guiLeft+70+18 && y <= guiTop+42+18){
this.func_146283_a(Arrays.asList("@SuppressWarnings(\"unused\")", "This slot is currently unused. Ignore it."), x, y);
}
}
}

View file

@ -7,6 +7,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import ellpeck.actuallyadditions.blocks.InitBlocks;
import ellpeck.actuallyadditions.network.sync.IPacketSyncerToClient;
import ellpeck.actuallyadditions.network.sync.PacketSyncerToClient;
import ellpeck.actuallyadditions.util.WorldUtil;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -17,12 +18,23 @@ import net.minecraftforge.oredict.OreDictionary;
public class TileEntityOreMagnet extends TileEntityInventoryBase implements IEnergyReceiver, IFluidHandler, IPacketSyncerToClient{
public EnergyStorage storage = new EnergyStorage(40000);
public FluidTank tank = new FluidTank(8*FluidContainerRegistry.BUCKET_VOLUME);
public static final int SLOT_OIL_INPUT = 0;
public static final int SLOT_OIL_OUTPUT = 1;
@SuppressWarnings("unused")
public static final int SLOT_UPGRADE = 2;
public EnergyStorage storage = new EnergyStorage(2000000);
private int lastEnergy;
public FluidTank tank = new FluidTank(16*FluidContainerRegistry.BUCKET_VOLUME);
private int lastTankAmount;
private int currentWorkTimer;
private static final int MAX_WORK_TIMER = 30;
private static final int RANGE = 5;
private int maxWorkTimer = 15;
private int range = 10;
private int oilUsePerTick = 50;
private int energyUsePerTick = 400;
public TileEntityOreMagnet(){
super(3, "oreMagnet");
@ -33,12 +45,13 @@ public class TileEntityOreMagnet extends TileEntityInventoryBase implements IEne
public void updateEntity(){
if(!worldObj.isRemote){
if(this.storage.getEnergyStored() >= this.energyUsePerTick && this.tank.getFluid() != null && this.tank.getFluid().getFluid() == InitBlocks.fluidOil && this.tank.getFluidAmount() >= this.oilUsePerTick && !worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){
if(this.currentWorkTimer > 0){
currentWorkTimer--;
if(currentWorkTimer <= 0){
int x = MathHelper.getRandomIntegerInRange(worldObj.rand, -RANGE, RANGE);
int z = MathHelper.getRandomIntegerInRange(worldObj.rand, -RANGE, RANGE);
int x = MathHelper.getRandomIntegerInRange(worldObj.rand, -range, range);
int z = MathHelper.getRandomIntegerInRange(worldObj.rand, -range, range);
//Can the block at the top be replaced?
for(int toPlaceY = 0; toPlaceY < 5; toPlaceY++){
if(worldObj.isAirBlock(xCoord+x, yCoord+toPlaceY, zCoord+z) || worldObj.getBlock(xCoord+x, yCoord+toPlaceY, zCoord+z).isReplaceable(worldObj, xCoord+x, yCoord+toPlaceY, zCoord+z)){
@ -60,6 +73,8 @@ public class TileEntityOreMagnet extends TileEntityInventoryBase implements IEne
worldObj.setBlock(xCoord+x, yCoord+toPlaceY, zCoord+z, block, meta, 2);
worldObj.playSoundEffect((double)xCoord+x+0.5D, (double)yCoord+toPlaceY+0.5D, (double)zCoord+z+0.5D, block.stepSound.func_150496_b(), (block.stepSound.getVolume()+1.0F)/2.0F, block.stepSound.getPitch()*0.8F);
//Extract oil
this.tank.drain(this.oilUsePerTick, true);
return;
}
}
@ -68,7 +83,21 @@ public class TileEntityOreMagnet extends TileEntityInventoryBase implements IEne
}
}
}
else this.currentWorkTimer = MathHelper.getRandomIntegerInRange(worldObj.rand, MAX_WORK_TIMER, MAX_WORK_TIMER*5);
else this.currentWorkTimer = maxWorkTimer+MathHelper.getRandomIntegerInRange(worldObj.rand, 0, maxWorkTimer);
//Extract energy
this.storage.extractEnergy(this.energyUsePerTick, false);
}
//Update Clients
if(this.lastEnergy != this.storage.getEnergyStored() || this.lastTankAmount != this.tank.getFluidAmount()){
this.lastEnergy = this.storage.getEnergyStored();
this.lastTankAmount = this.tank.getFluidAmount();
this.sendUpdate();
}
//Empty Oil Bucket
WorldUtil.emptyBucket(this.tank, this.slots, SLOT_OIL_INPUT, SLOT_OIL_OUTPUT);
}
}
@ -77,10 +106,16 @@ public class TileEntityOreMagnet extends TileEntityInventoryBase implements IEne
return this.storage.getEnergyStored() * i / this.storage.getMaxEnergyStored();
}
@SideOnly(Side.CLIENT)
public int getTankScaled(int i){
return this.tank.getFluidAmount() * i / this.tank.getCapacity();
}
@Override
public void writeToNBT(NBTTagCompound compound){
this.storage.writeToNBT(compound);
this.tank.writeToNBT(compound);
compound.setInteger("CurrentWorkTimer", this.currentWorkTimer);
super.writeToNBT(compound);
}
@ -88,13 +123,13 @@ public class TileEntityOreMagnet extends TileEntityInventoryBase implements IEne
public void readFromNBT(NBTTagCompound compound){
this.storage.readFromNBT(compound);
this.tank.readFromNBT(compound);
this.currentWorkTimer = compound.getInteger("CurrentWorkTimer");
super.readFromNBT(compound);
}
@Override
public boolean isItemValidForSlot(int i, ItemStack stack){
return false;
//TODO
return FluidContainerRegistry.containsFluid(stack, new FluidStack(InitBlocks.fluidOil, 1)) && i == SLOT_OIL_INPUT;
}
@Override
@ -104,8 +139,7 @@ public class TileEntityOreMagnet extends TileEntityInventoryBase implements IEne
@Override
public boolean canExtractItem(int slot, ItemStack stack, int side){
return false;
//TODO
return slot == SLOT_OIL_OUTPUT;
}
@Override
@ -161,13 +195,16 @@ public class TileEntityOreMagnet extends TileEntityInventoryBase implements IEne
@Override
public int[] getValues(){
//TODO
return new int[0];
return new int[]{this.storage.getEnergyStored(), this.tank.getFluidAmount(), this.tank.getFluid() == null ? -1 : this.tank.getFluid().getFluidID()};
}
@Override
public void setValues(int[] values){
//TODO
this.storage.setEnergyStored(values[0]);
if(values[2] != -1){
this.tank.setFluid(new FluidStack(FluidRegistry.getFluid(values[2]), values[1]));
}
else this.tank.setFluid(null);
}
@Override