Genericise boiler containers

dev
Arona Jones 2016-02-06 13:21:58 +00:00
parent f47c4dd400
commit e9fb6cc6e9
8 changed files with 31 additions and 350 deletions

4
.eclipse-pmd Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<eclipse-pmd xmlns="http://acanda.ch/eclipse-pmd/0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://acanda.ch/eclipse-pmd/0.8 http://acanda.ch/eclipse-pmd/eclipse-pmd-0.8.xsd">
<analysis enabled="true" />
</eclipse-pmd>

View File

@ -10,7 +10,7 @@ import boilerplate.client.BaseContainerGui;
import org.lwjgl.opengl.GL11;
import steamcraft.common.lib.ModInfo;
import steamcraft.common.tiles.TileNuclearBoiler;
import steamcraft.common.tiles.container.ContainerNuclearBoiler;
import steamcraft.common.tiles.container.ContainerBaseBoiler;
/**
* @author decebaldecebal
@ -24,7 +24,7 @@ public class GuiNuclearBoiler extends BaseContainerGui
public GuiNuclearBoiler(InventoryPlayer player, TileNuclearBoiler tile)
{
super(new ContainerNuclearBoiler(player, tile));
super(new ContainerBaseBoiler(player, tile));
this.boiler = tile;
}

View File

@ -10,7 +10,7 @@ import boilerplate.client.BaseContainerGui;
import org.lwjgl.opengl.GL11;
import steamcraft.common.lib.ModInfo;
import steamcraft.common.tiles.TileSteamBoiler;
import steamcraft.common.tiles.container.ContainerSteamBoiler;
import steamcraft.common.tiles.container.ContainerBaseBoiler;
/**
* @author decebaldecebal
@ -24,7 +24,7 @@ public class GuiSteamBoiler extends BaseContainerGui
public GuiSteamBoiler(InventoryPlayer player, TileSteamBoiler tile)
{
super(new ContainerSteamBoiler(player, tile));
super(new ContainerBaseBoiler(player, tile));
this.boiler = tile;
}

View File

@ -8,7 +8,7 @@ import net.minecraft.world.World;
import boilerplate.api.IOpenableGUI;
import steamcraft.client.gui.GuiNuclearBoiler;
import steamcraft.common.init.InitItems;
import steamcraft.common.tiles.container.ContainerNuclearBoiler;
import steamcraft.common.tiles.container.ContainerBaseBoiler;
/**
* @author Decebaldecebal
@ -36,6 +36,6 @@ public class TileNuclearBoiler extends TileBaseBoiler implements IOpenableGUI
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
return new ContainerNuclearBoiler(player.inventory, (TileNuclearBoiler) world.getTileEntity(x, y, z));
return new ContainerBaseBoiler(player.inventory, (TileNuclearBoiler) world.getTileEntity(x, y, z));
}
}

View File

@ -8,7 +8,7 @@ import net.minecraft.world.World;
import boilerplate.api.IOpenableGUI;
import steamcraft.client.gui.GuiSteamBoiler;
import steamcraft.common.tiles.container.ContainerSteamBoiler;
import steamcraft.common.tiles.container.ContainerBaseBoiler;
/**
* @author Decebaldecebal
@ -34,6 +34,6 @@ public class TileSteamBoiler extends TileBaseBoiler implements IOpenableGUI
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
return new ContainerSteamBoiler(player.inventory, (TileSteamBoiler) world.getTileEntity(x, y, z));
return new ContainerBaseBoiler(player.inventory, (TileSteamBoiler) world.getTileEntity(x, y, z));
}
}

View File

@ -17,7 +17,7 @@ import net.minecraftforge.fluids.FluidStack;
import boilerplate.common.baseclasses.blocks.BaseContainer;
import steamcraft.common.items.ItemCanister;
import steamcraft.common.tiles.TileSteamBoiler;
import steamcraft.common.tiles.TileBaseBoiler;
import steamcraft.common.tiles.container.slot.SlotFluidContainer;
import steamcraft.common.tiles.container.slot.SlotOutput;
@ -25,16 +25,16 @@ import steamcraft.common.tiles.container.slot.SlotOutput;
* @author Decebaldecebal
*
*/
public class ContainerSteamBoiler extends BaseContainer
public class ContainerBaseBoiler extends BaseContainer
{
private TileSteamBoiler tileent;
protected TileBaseBoiler tileent;
private int lastBurnTime = 0;
private int lastItemBurnTime = 0;
private int lastSteamLevel = 0;
private int lastWaterLevel = 0;
protected int lastBurnTime = 0;
protected int lastItemBurnTime = 0;
protected int lastSteamLevel = 0;
protected int lastWaterLevel = 0;
public ContainerSteamBoiler(InventoryPlayer player, TileSteamBoiler tile)
public ContainerBaseBoiler(InventoryPlayer player, TileBaseBoiler tile)
{
this.tileent = tile;
this.setTile(this.tileent);

View File

@ -1,86 +1,41 @@
package steamcraft.common.tiles.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityFurnace;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import boilerplate.common.baseclasses.blocks.BaseContainer;
import steamcraft.common.items.ItemCanister;
import steamcraft.common.tiles.TileLiquidBoiler;
import steamcraft.common.tiles.container.slot.SlotFluidContainer;
/**
* @author Decebaldecebal
*
*/
public class ContainerLiquidBoiler extends BaseContainer
public class ContainerLiquidBoiler extends ContainerBaseBoiler
{
private TileLiquidBoiler tileent;
private int lastBurnTime = 0;
private int lastItemBurnTime = 0;
private int lastSteamLevel = 0;
private int lastFuelLevel = 0;
private int lastWaterLevel = 0;
public ContainerLiquidBoiler(InventoryPlayer player, TileLiquidBoiler tileLiquidBoiler)
{
this.tileent = tileLiquidBoiler;
this.setTile(this.tileent);
this.addSlotToContainer(new Slot(tileLiquidBoiler, 0, 116, 61)
{
@Override
public boolean isItemValid(ItemStack stack)
{
return FluidContainerRegistry.isContainer(stack);
}
});
this.addSlotToContainer(new Slot(tileLiquidBoiler, 1, 135, 61)
{
@Override
public boolean isItemValid(ItemStack stack)
{
return FluidContainerRegistry.isContainer(stack);
}
});
this.addSlotToContainer(new Slot(tileLiquidBoiler, 2, 154, 61)
{
@Override
public boolean isItemValid(ItemStack stack)
{
return stack.getItem() instanceof ItemCanister;
}
});
int var3;
for (var3 = 0; var3 < 3; ++var3)
for (int var4 = 0; var4 < 9; ++var4)
this.addSlotToContainer(new Slot(player, var4 + (var3 * 9) + 9, 8 + (var4 * 18), 84 + (var3 * 18)));
for (var3 = 0; var3 < 9; ++var3)
this.addSlotToContainer(new Slot(player, var3, 8 + (var3 * 18), 142));
super(player, tileLiquidBoiler);
this.tileent = (TileLiquidBoiler) super.tileent;
this.addSlotToContainer(new SlotFluidContainer(tileLiquidBoiler, 0, 116, 61));
this.addSlotToContainer(new SlotFluidContainer(tileLiquidBoiler, 1, 135, 61));
this.addSlotToContainer(new SlotFluidContainer(tileLiquidBoiler, 2, 154, 61));
}
@Override
public void addCraftingToCrafters(ICrafting par1ICrafting)
{
super.addCraftingToCrafters(par1ICrafting);
par1ICrafting.sendProgressBarUpdate(this, 0, this.tileent.furnaceBurnTime);
par1ICrafting.sendProgressBarUpdate(this, 1, this.tileent.steamTank.getFluidAmount());
par1ICrafting.sendProgressBarUpdate(this, 2, this.tileent.fuelTank.getFluidAmount());
par1ICrafting.sendProgressBarUpdate(this, 3, this.tileent.waterTank.getFluidAmount());
}
@Override
@ -90,108 +45,19 @@ public class ContainerLiquidBoiler extends BaseContainer
for (Object obj : this.crafters)
{
ICrafting var2 = (ICrafting) obj;
if (this.lastBurnTime != this.tileent.furnaceBurnTime)
var2.sendProgressBarUpdate(this, 0, this.tileent.furnaceBurnTime);
if (this.lastSteamLevel != this.tileent.steamTank.getFluidAmount())
var2.sendProgressBarUpdate(this, 1, this.tileent.steamTank.getFluidAmount());
if (this.lastFuelLevel != this.tileent.fuelTank.getFluidAmount())
var2.sendProgressBarUpdate(this, 2, this.tileent.fuelTank.getFluidAmount());
if (this.lastWaterLevel != this.tileent.waterTank.getFluidAmount())
var2.sendProgressBarUpdate(this, 3, this.tileent.waterTank.getFluidAmount());
((ICrafting) obj).sendProgressBarUpdate(this, 2, this.tileent.fuelTank.getFluidAmount());
}
this.lastBurnTime = this.tileent.furnaceBurnTime;
this.lastSteamLevel = this.tileent.steamTank.getFluidAmount();
this.lastFuelLevel = this.tileent.fuelTank.getFluidAmount();
this.lastWaterLevel = this.tileent.waterTank.getFluidAmount();
}
@Override
@SideOnly(Side.CLIENT)
public void updateProgressBar(int par1, int par2)
{
if (par1 == 0)
this.tileent.furnaceBurnTime = par2;
else if (par1 == 1)
this.tileent.steamTank.setFluid(new FluidStack(FluidRegistry.getFluid("steam"), par2));
else if (par1 == 2)
super.updateProgressBar(par1, par2);
if (par1 == 2)
// TODO
this.tileent.fuelTank.setFluid(new FluidStack(FluidRegistry.getFluid("whaleoil"), par2));
else if (par1 == 3)
this.tileent.waterTank.setFluid(new FluidStack(FluidRegistry.getFluid("water"), par2));
}
@Override
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
return this.tileent.isUseableByPlayer(par1EntityPlayer);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
{
ItemStack var3 = null;
Slot var4 = (Slot) this.inventorySlots.get(par2);
if ((var4 != null) && var4.getHasStack())
{
ItemStack var5 = var4.getStack();
var3 = var5.copy();
if (par2 > 2)
{
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(var5);
if ((liquid != null) && (liquid.getFluid() == FluidRegistry.WATER))
{
if (!this.mergeItemStack(var5, 1, 2, false))
return null;
}
else if (TileEntityFurnace.getItemBurnTime(var5) > 0)
{
if (!this.mergeItemStack(var5, 0, 1, false))
if ((par2 >= 3) && (par2 < 30))
{
if (!this.mergeItemStack(var5, 30, 39, false))
return null;
}
else if ((par2 >= 30) && (par2 < 39) && !this.mergeItemStack(var5, 3, 30, false))
return null;
}
else if (var5.getItem() instanceof ItemCanister)
{
if (!this.mergeItemStack(var5, 2, 3, false))
if ((par2 >= 3) && (par2 < 30))
{
if (!this.mergeItemStack(var5, 30, 39, false))
return null;
}
else if ((par2 >= 30) && (par2 < 39) && !this.mergeItemStack(var5, 3, 30, false))
return null;
}
else if ((par2 >= 3) && (par2 < 30) && !this.mergeItemStack(var5, 30, 39, false))
return null;
else if ((par2 >= 30) && (par2 < 39) && !this.mergeItemStack(var5, 3, 30, false))
return null;
}
else if (!this.mergeItemStack(var5, 3, 39, false))
return null;
if (var5.stackSize == 0)
var4.putStack(null);
else
var4.onSlotChanged();
if (var5.stackSize == var3.stackSize)
return null;
var4.onPickupFromSlot(par1EntityPlayer, var5);
}
return var3;
}
}

View File

@ -1,189 +0,0 @@
package steamcraft.common.tiles.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityFurnace;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import boilerplate.common.baseclasses.blocks.BaseContainer;
import steamcraft.common.items.ItemCanister;
import steamcraft.common.tiles.TileNuclearBoiler;
/**
* @author Decebaldecebal
*
*/
public class ContainerNuclearBoiler extends BaseContainer
{
private TileNuclearBoiler tileent;
private int lastBurnTime = 0;
private int lastItemBurnTime = 0;
private int lastSteamLevel = 0;
private int lastWaterLevel = 0;
public ContainerNuclearBoiler(InventoryPlayer player, TileNuclearBoiler tile)
{
this.tileent = tile;
this.setTile(this.tileent);
this.addSlotToContainer(new Slot(tile, 0, 42, 52));
this.addSlotToContainer(new Slot(tile, 1, 132, 57)
{
@Override
public boolean isItemValid(ItemStack stack)
{
return FluidContainerRegistry.isContainer(stack);
}
});
this.addSlotToContainer(new Slot(tile, 2, 132, 21)
{
@Override
public boolean isItemValid(ItemStack stack)
{
return stack.getItem() instanceof ItemCanister;
}
});
int var3;
for (var3 = 0; var3 < 3; ++var3)
for (int var4 = 0; var4 < 9; ++var4)
this.addSlotToContainer(new Slot(player, var4 + (var3 * 9) + 9, 8 + (var4 * 18), 84 + (var3 * 18)));
for (var3 = 0; var3 < 9; ++var3)
this.addSlotToContainer(new Slot(player, var3, 8 + (var3 * 18), 142));
}
@Override
public void addCraftingToCrafters(ICrafting par1ICrafting)
{
super.addCraftingToCrafters(par1ICrafting);
par1ICrafting.sendProgressBarUpdate(this, 0, this.tileent.furnaceBurnTime);
par1ICrafting.sendProgressBarUpdate(this, 1, this.tileent.currentFuelBurnTime);
par1ICrafting.sendProgressBarUpdate(this, 2, this.tileent.steamTank.getFluidAmount());
par1ICrafting.sendProgressBarUpdate(this, 3, this.tileent.waterTank.getFluidAmount());
}
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
for (Object obj : this.crafters)
{
ICrafting var2 = (ICrafting) obj;
if (this.lastBurnTime != this.tileent.furnaceBurnTime)
var2.sendProgressBarUpdate(this, 0, this.tileent.furnaceBurnTime);
if (this.lastItemBurnTime != this.tileent.currentFuelBurnTime)
var2.sendProgressBarUpdate(this, 1, this.tileent.currentFuelBurnTime);
if (this.lastSteamLevel != this.tileent.steamTank.getFluidAmount())
var2.sendProgressBarUpdate(this, 2, this.tileent.steamTank.getFluidAmount());
if (this.lastWaterLevel != this.tileent.waterTank.getFluidAmount())
var2.sendProgressBarUpdate(this, 3, this.tileent.waterTank.getFluidAmount());
}
this.lastBurnTime = this.tileent.furnaceBurnTime;
this.lastItemBurnTime = this.tileent.currentFuelBurnTime;
this.lastSteamLevel = this.tileent.steamTank.getFluidAmount();
this.lastWaterLevel = this.tileent.waterTank.getFluidAmount();
}
@Override
@SideOnly(Side.CLIENT)
public void updateProgressBar(int par1, int par2)
{
if (par1 == 0)
this.tileent.furnaceBurnTime = par2;
else if (par1 == 1)
this.tileent.currentFuelBurnTime = par2;
else if (par1 == 2)
this.tileent.steamTank.setFluid(new FluidStack(FluidRegistry.getFluid("steam"), par2));
else if (par1 == 3)
this.tileent.waterTank.setFluid(new FluidStack(FluidRegistry.getFluid("water"), par2));
}
@Override
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
return this.tileent.isUseableByPlayer(par1EntityPlayer);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
{
ItemStack var3 = null;
Slot var4 = (Slot) this.inventorySlots.get(par2);
if ((var4 != null) && var4.getHasStack())
{
ItemStack var5 = var4.getStack();
var3 = var5.copy();
if (par2 > 2)
{
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(var5);
if ((liquid != null) && (liquid.getFluid() == FluidRegistry.WATER))
{
if (!this.mergeItemStack(var5, 1, 2, false))
return null;
}
else if (TileEntityFurnace.getItemBurnTime(var5) > 0)
{
if (!this.mergeItemStack(var5, 0, 1, false))
if ((par2 >= 3) && (par2 < 30))
{
if (!this.mergeItemStack(var5, 30, 39, false))
return null;
}
else if ((par2 >= 30) && (par2 < 39) && !this.mergeItemStack(var5, 3, 30, false))
return null;
}
else if (var5.getItem() instanceof ItemCanister)
{
if (!this.mergeItemStack(var5, 2, 3, false))
if ((par2 >= 3) && (par2 < 30))
{
if (!this.mergeItemStack(var5, 30, 39, false))
return null;
}
else if ((par2 >= 30) && (par2 < 39) && !this.mergeItemStack(var5, 3, 30, false))
return null;
}
else if ((par2 >= 3) && (par2 < 30) && !this.mergeItemStack(var5, 30, 39, false))
return null;
else if ((par2 >= 30) && (par2 < 39) && !this.mergeItemStack(var5, 3, 30, false))
return null;
}
else if (!this.mergeItemStack(var5, 3, 39, false))
return null;
if (var5.stackSize == 0)
var4.putStack(null);
else
var4.onSlotChanged();
if (var5.stackSize == var3.stackSize)
return null;
var4.onPickupFromSlot(par1EntityPlayer, var5);
}
return var3;
}
}