mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 23:28:35 +01:00
-Generalized FluidContainer Emptying and Filling
This commit is contained in:
parent
639062693f
commit
308dc205c0
8 changed files with 52 additions and 66 deletions
|
@ -15,7 +15,7 @@ public class GrinderCrafting{
|
||||||
|
|
||||||
public static void init(){
|
public static void init(){
|
||||||
Util.logInfo("Initializing Crusher Recipes...");
|
Util.logInfo("Initializing Crusher Recipes...");
|
||||||
GrinderRecipeManualRegistry.recipes.clear();
|
GrinderRecipeManualRegistry.clearRecipeList();
|
||||||
|
|
||||||
GrinderRecipeManualRegistry.registerRecipe(new ItemStack(Blocks.redstone_ore), new ItemStack(Items.redstone, 10));
|
GrinderRecipeManualRegistry.registerRecipe(new ItemStack(Blocks.redstone_ore), new ItemStack(Items.redstone, 10));
|
||||||
GrinderRecipeManualRegistry.registerRecipe(new ItemStack(Blocks.lapis_ore), new ItemStack(InitItems.itemDust, 12, TheDusts.LAPIS.ordinal()));
|
GrinderRecipeManualRegistry.registerRecipe(new ItemStack(Blocks.lapis_ore), new ItemStack(InitItems.itemDust, 12, TheDusts.LAPIS.ordinal()));
|
||||||
|
|
|
@ -9,6 +9,10 @@ public class GrinderRecipeManualRegistry{
|
||||||
|
|
||||||
public static ArrayList<GrinderRecipe> recipes = new ArrayList<GrinderRecipe>();
|
public static ArrayList<GrinderRecipe> recipes = new ArrayList<GrinderRecipe>();
|
||||||
|
|
||||||
|
public static void clearRecipeList(){
|
||||||
|
recipes.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public static void registerRecipe(ItemStack input, ItemStack outputOne, ItemStack outputTwo, int secondChance){
|
public static void registerRecipe(ItemStack input, ItemStack outputOne, ItemStack outputTwo, int secondChance){
|
||||||
recipes.add(new GrinderRecipe(input, outputOne, outputTwo, secondChance));
|
recipes.add(new GrinderRecipe(input, outputOne, outputTwo, secondChance));
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,14 +52,7 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IE
|
||||||
}
|
}
|
||||||
else this.currentProcessTime = 0;
|
else this.currentProcessTime = 0;
|
||||||
|
|
||||||
if(this.slots[1] != null && this.slots[1].getItem() == Items.bucket && this.slots[2] == null){
|
WorldUtil.fillBucket(tank, slots, 1, 2);
|
||||||
if(this.tank.getFluidAmount() > 0 && this.tank.getFluid().getFluid() == InitBlocks.fluidCanolaOil && this.tank.getFluidAmount() >= FluidContainerRegistry.BUCKET_VOLUME){
|
|
||||||
this.slots[2] = new ItemStack(InitItems.itemBucketCanolaOil);
|
|
||||||
this.slots[1].stackSize--;
|
|
||||||
if(this.slots[1].stackSize == 0) this.slots[1] = null;
|
|
||||||
this.tank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.tank.getFluidAmount() > 0){
|
if(this.tank.getFluidAmount() > 0){
|
||||||
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.DOWN, this.tank);
|
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.DOWN, this.tank);
|
||||||
|
|
|
@ -9,8 +9,8 @@ import ellpeck.actuallyadditions.items.InitItems;
|
||||||
import ellpeck.actuallyadditions.items.ItemCoffee;
|
import ellpeck.actuallyadditions.items.ItemCoffee;
|
||||||
import ellpeck.actuallyadditions.items.metalists.TheMiscItems;
|
import ellpeck.actuallyadditions.items.metalists.TheMiscItems;
|
||||||
import ellpeck.actuallyadditions.network.gui.IButtonReactor;
|
import ellpeck.actuallyadditions.network.gui.IButtonReactor;
|
||||||
|
import ellpeck.actuallyadditions.util.WorldUtil;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.init.Items;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
@ -62,14 +62,7 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.slots[SLOT_WATER_INPUT] != null && FluidContainerRegistry.containsFluid(this.slots[SLOT_WATER_INPUT], new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME)) && (this.slots[SLOT_WATER_OUTPUT] == null || (this.slots[SLOT_WATER_OUTPUT].stackSize < this.slots[SLOT_WATER_OUTPUT].getMaxStackSize()))){
|
WorldUtil.emptyBucket(tank, slots, SLOT_WATER_INPUT, SLOT_WATER_OUTPUT, FluidRegistry.WATER);
|
||||||
if(FluidContainerRegistry.BUCKET_VOLUME <= this.tank.getCapacity()-this.tank.getFluidAmount()){
|
|
||||||
if(this.slots[SLOT_WATER_OUTPUT] == null) this.slots[SLOT_WATER_OUTPUT] = new ItemStack(Items.bucket);
|
|
||||||
else this.slots[SLOT_WATER_OUTPUT].stackSize++;
|
|
||||||
this.slots[SLOT_WATER_INPUT] = null;
|
|
||||||
this.tank.fill(new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void brew(){
|
public void brew(){
|
||||||
|
|
|
@ -4,7 +4,6 @@ import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import ellpeck.actuallyadditions.blocks.InitBlocks;
|
import ellpeck.actuallyadditions.blocks.InitBlocks;
|
||||||
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
||||||
import ellpeck.actuallyadditions.items.InitItems;
|
|
||||||
import ellpeck.actuallyadditions.util.WorldUtil;
|
import ellpeck.actuallyadditions.util.WorldUtil;
|
||||||
import net.minecraft.init.Items;
|
import net.minecraft.init.Items;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -42,23 +41,8 @@ public class TileEntityFermentingBarrel extends TileEntityInventoryBase implemen
|
||||||
}
|
}
|
||||||
else this.currentProcessTime = 0;
|
else this.currentProcessTime = 0;
|
||||||
|
|
||||||
if(this.slots[0] != null && FluidContainerRegistry.containsFluid(this.slots[0], new FluidStack(InitBlocks.fluidCanolaOil, FluidContainerRegistry.BUCKET_VOLUME)) && (this.slots[1] == null || (this.slots[1].stackSize < this.slots[1].getMaxStackSize()))){
|
WorldUtil.emptyBucket(canolaTank, slots, 0, 1, InitBlocks.fluidCanolaOil);
|
||||||
if(FluidContainerRegistry.BUCKET_VOLUME <= this.canolaTank.getCapacity()-this.canolaTank.getFluidAmount()){
|
WorldUtil.fillBucket(oilTank, slots, 2, 3);
|
||||||
if(this.slots[1] == null) this.slots[1] = new ItemStack(Items.bucket);
|
|
||||||
else this.slots[1].stackSize++;
|
|
||||||
this.slots[0] = null;
|
|
||||||
this.canolaTank.fill(new FluidStack(InitBlocks.fluidCanolaOil, FluidContainerRegistry.BUCKET_VOLUME), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.slots[2] != null && this.slots[2].getItem() == Items.bucket && this.slots[3] == null){
|
|
||||||
if(this.oilTank.getFluidAmount() > 0 && this.oilTank.getFluid().getFluid() == InitBlocks.fluidOil && this.oilTank.getFluidAmount() >= FluidContainerRegistry.BUCKET_VOLUME){
|
|
||||||
this.slots[3] = new ItemStack(InitItems.itemBucketOil);
|
|
||||||
this.slots[2].stackSize--;
|
|
||||||
if(this.slots[2].stackSize == 0) this.slots[2] = null;
|
|
||||||
this.oilTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.oilTank.getFluidAmount() > 0){
|
if(this.oilTank.getFluidAmount() > 0){
|
||||||
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.DOWN, this.oilTank);
|
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.DOWN, this.oilTank);
|
||||||
|
|
|
@ -9,7 +9,6 @@ import ellpeck.actuallyadditions.network.PacketHandler;
|
||||||
import ellpeck.actuallyadditions.util.WorldUtil;
|
import ellpeck.actuallyadditions.util.WorldUtil;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.init.Items;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.ChunkCoordinates;
|
import net.minecraft.util.ChunkCoordinates;
|
||||||
|
@ -137,26 +136,8 @@ public class TileEntityFluidCollector extends TileEntityInventoryBase implements
|
||||||
else this.currentTime = this.timeNeeded;
|
else this.currentTime = this.timeNeeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this.isPlacer){
|
if(!this.isPlacer) WorldUtil.fillBucket(tank, slots, 0, 1);
|
||||||
if(this.slots[0] != null && this.slots[0].getItem() == Items.bucket && this.slots[1] == null){
|
else WorldUtil.emptyBucket(tank, slots, 0, 1);
|
||||||
if(this.tank.getFluidAmount() >= FluidContainerRegistry.BUCKET_VOLUME){
|
|
||||||
this.slots[1] = FluidContainerRegistry.fillFluidContainer(this.tank.getFluid(), this.slots[0].copy());
|
|
||||||
this.slots[0].stackSize--;
|
|
||||||
if(this.slots[0].stackSize == 0) this.slots[0] = null;
|
|
||||||
this.tank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
if(this.slots[0] != null && FluidContainerRegistry.isBucket(this.slots[0]) && !this.slots[0].isItemEqual(FluidContainerRegistry.EMPTY_BUCKET) && (this.slots[1] == null || this.slots[1].stackSize < this.slots[1].getMaxStackSize())){
|
|
||||||
if(FluidContainerRegistry.BUCKET_VOLUME <= this.tank.getCapacity()-this.tank.getFluidAmount()){
|
|
||||||
if(this.slots[1] == null) this.slots[1] = new ItemStack(Items.bucket);
|
|
||||||
else this.slots[1].stackSize++;
|
|
||||||
this.tank.fill(FluidContainerRegistry.getFluidForFilledItem(this.slots[0]), true);
|
|
||||||
this.slots[0] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.tank.getFluidAmount() > 0 && !this.isPlacer){
|
if(this.tank.getFluidAmount() > 0 && !this.isPlacer){
|
||||||
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)).getOpposite(), this.tank);
|
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)).getOpposite(), this.tank);
|
||||||
|
@ -164,6 +145,7 @@ public class TileEntityFluidCollector extends TileEntityInventoryBase implements
|
||||||
|
|
||||||
if(amountBefore != this.tank.getFluidAmount()){
|
if(amountBefore != this.tank.getFluidAmount()){
|
||||||
this.sendPacket();
|
this.sendPacket();
|
||||||
|
this.markDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import ellpeck.actuallyadditions.blocks.InitBlocks;
|
import ellpeck.actuallyadditions.blocks.InitBlocks;
|
||||||
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
||||||
import ellpeck.actuallyadditions.util.WorldUtil;
|
import ellpeck.actuallyadditions.util.WorldUtil;
|
||||||
import net.minecraft.init.Items;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
@ -48,14 +47,7 @@ public class TileEntityOilGenerator extends TileEntityInventoryBase implements I
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.slots[0] != null && FluidContainerRegistry.containsFluid(this.slots[0], new FluidStack(InitBlocks.fluidOil, FluidContainerRegistry.BUCKET_VOLUME)) && (this.slots[1] == null || (this.slots[1].stackSize < this.slots[1].getMaxStackSize()))){
|
WorldUtil.emptyBucket(tank, slots, 0, 1, InitBlocks.fluidOil);
|
||||||
if(FluidContainerRegistry.BUCKET_VOLUME <= this.tank.getCapacity()-this.tank.getFluidAmount()){
|
|
||||||
if(this.slots[1] == null) this.slots[1] = new ItemStack(Items.bucket);
|
|
||||||
else this.slots[1].stackSize++;
|
|
||||||
this.slots[0] = null;
|
|
||||||
this.tank.fill(new FluidStack(InitBlocks.fluidOil, FluidContainerRegistry.BUCKET_VOLUME), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.getEnergyStored(ForgeDirection.UNKNOWN) > 0){
|
if(this.getEnergyStored(ForgeDirection.UNKNOWN) > 0){
|
||||||
WorldUtil.pushEnergy(worldObj, xCoord, yCoord, zCoord, ForgeDirection.UP, storage);
|
WorldUtil.pushEnergy(worldObj, xCoord, yCoord, zCoord, ForgeDirection.UP, storage);
|
||||||
|
|
|
@ -114,6 +114,44 @@ public class WorldUtil{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void fillBucket(FluidTank tank, ItemStack[] slots, int inputSlot, int outputSlot){
|
||||||
|
if(slots[inputSlot] != null && tank.getFluid() != null){
|
||||||
|
ItemStack filled = FluidContainerRegistry.fillFluidContainer(tank.getFluid(), slots[inputSlot].copy());
|
||||||
|
if(filled != null && FluidContainerRegistry.isEmptyContainer(slots[inputSlot]) && (slots[outputSlot] == null || (slots[outputSlot].isItemEqual(filled) && slots[outputSlot].stackSize < slots[outputSlot].getMaxStackSize()))){
|
||||||
|
int cap = FluidContainerRegistry.getContainerCapacity(tank.getFluid(), slots[inputSlot]);
|
||||||
|
if(cap > 0 && cap <= tank.getFluidAmount()){
|
||||||
|
if(slots[outputSlot] == null) slots[outputSlot] = FluidContainerRegistry.fillFluidContainer(tank.getFluid(), slots[inputSlot].copy());
|
||||||
|
else slots[outputSlot].stackSize++;
|
||||||
|
|
||||||
|
if(slots[outputSlot] != null){
|
||||||
|
tank.drain(cap, true);
|
||||||
|
slots[inputSlot].stackSize--;
|
||||||
|
if(slots[inputSlot].stackSize <= 0) slots[inputSlot] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void emptyBucket(FluidTank tank, ItemStack[] slots, int inputSlot, int outputSlot){
|
||||||
|
emptyBucket(tank, slots, inputSlot, outputSlot, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void emptyBucket(FluidTank tank, ItemStack[] slots, int inputSlot, int outputSlot, Fluid containedFluid){
|
||||||
|
if(slots[inputSlot] != null && FluidContainerRegistry.isFilledContainer(slots[inputSlot]) && (slots[outputSlot] == null || (slots[outputSlot].isItemEqual(FluidContainerRegistry.drainFluidContainer(slots[inputSlot].copy())) && slots[outputSlot].stackSize < slots[outputSlot].getMaxStackSize()))){
|
||||||
|
if(containedFluid == null || FluidContainerRegistry.containsFluid(slots[inputSlot], new FluidStack(containedFluid, 0))){
|
||||||
|
if((tank.getFluid() == null || FluidContainerRegistry.getFluidForFilledItem(slots[inputSlot]).isFluidEqual(tank.getFluid())) && tank.getCapacity()-tank.getFluidAmount() >= FluidContainerRegistry.getContainerCapacity(slots[inputSlot])){
|
||||||
|
if(slots[outputSlot] == null) slots[outputSlot] = FluidContainerRegistry.drainFluidContainer(slots[inputSlot].copy());
|
||||||
|
else slots[outputSlot].stackSize++;
|
||||||
|
|
||||||
|
tank.fill(FluidContainerRegistry.getFluidForFilledItem(slots[inputSlot]), true);
|
||||||
|
slots[inputSlot].stackSize--;
|
||||||
|
if(slots[inputSlot].stackSize <= 0) slots[inputSlot] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static ForgeDirection getDirectionByRotatingSide(int side){
|
public static ForgeDirection getDirectionByRotatingSide(int side){
|
||||||
switch(side){
|
switch(side){
|
||||||
case 0: return ForgeDirection.UP;
|
case 0: return ForgeDirection.UP;
|
||||||
|
|
Loading…
Reference in a new issue