Various usability tweaks to the refinery

Filters are now set automatically by the first fluid to be inserted. You
can reset them with a wrench Shift-Right Click.
This commit is contained in:
CovertJaguar 2013-08-16 23:42:49 -07:00
parent 2f5a61217f
commit 7071314d37
6 changed files with 89 additions and 98 deletions

View file

@ -16,6 +16,9 @@ public class ItemWrench extends ItemBuildCraft implements IToolWrench {
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
if(player.isSneaking())
return false;
int blockId = world.getBlockId(x, y, z);
Block block = Block.blocksList[blockId];
if (block != null && block.blockID != Block.lever.blockID && block.rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side))) {

View file

@ -30,18 +30,22 @@ public class SingleUseTank extends Tank {
public int fill(FluidStack resource, boolean doFill) {
if (resource == null)
return 0;
if (acceptedFluid == null)
if (doFill && acceptedFluid == null)
acceptedFluid = resource.getFluid();
if (acceptedFluid != resource.getFluid())
return 0;
return super.fill(resource, doFill);
if (acceptedFluid == null || acceptedFluid == resource.getFluid())
return super.fill(resource, doFill);
return 0;
}
public void reset() {
acceptedFluid = null;
}
public Fluid getAcceptedFluid(){
public void setAcceptedFluid(Fluid fluid) {
this.acceptedFluid = fluid;
}
public Fluid getAcceptedFluid() {
return acceptedFluid;
}

View file

@ -28,19 +28,19 @@ import net.minecraftforge.fluids.IFluidHandler;
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public class TankManager extends ForwardingList<Tank> implements IFluidHandler, List<Tank> {
public class TankManager<T extends Tank> extends ForwardingList<T> implements IFluidHandler, List<T> {
private List<Tank> tanks = new ArrayList<Tank>();
private List<T> tanks = new ArrayList<T>();
public TankManager() {
}
public TankManager(Tank... tanks) {
public TankManager(T... tanks) {
addAll(Arrays.asList(tanks));
}
@Override
protected List<Tank> delegate() {
protected List<T> delegate() {
return tanks;
}

View file

@ -13,7 +13,7 @@ import buildcraft.api.core.Position;
import buildcraft.api.tools.IToolWrench;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.GuiIds;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.fluids.FluidUtils;
import buildcraft.core.utils.Utils;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -29,8 +29,11 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import static net.minecraftforge.common.ForgeDirection.EAST;
import static net.minecraftforge.common.ForgeDirection.NORTH;
import static net.minecraftforge.common.ForgeDirection.SOUTH;
import static net.minecraftforge.common.ForgeDirection.WEST;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
public class BlockRefinery extends BlockContainer {
@ -77,53 +80,54 @@ public class BlockRefinery extends BlockContainer {
}
@Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) {
// Drop through if the player is sneaking
if (entityplayer.isSneaking()) {
public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis) {
int meta = world.getBlockMetadata(x, y, z);
switch (ForgeDirection.getOrientation(meta)) {
case WEST:
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.SOUTH.ordinal(), 3);
break;
case EAST:
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.NORTH.ordinal(), 3);
break;
case NORTH:
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.WEST.ordinal(), 3);
break;
case SOUTH:
default:
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.EAST.ordinal(), 3);
break;
}
world.markBlockForUpdate(x, y, z);
return true;
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (!(tile instanceof TileRefinery))
return false;
ItemStack current = player.getCurrentEquippedItem();
Item equipped = current != null ? current.getItem() : null;
if (player.isSneaking() && equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(player, x, y, z)) {
((TileRefinery)tile).resetFilters();
((IToolWrench) equipped).wrenchUsed(player, x, y, z);
return true;
}
Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null;
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, i, j, k)) {
int meta = world.getBlockMetadata(i, j, k);
switch (ForgeDirection.values()[meta]) {
case WEST:
world.setBlockMetadataWithNotify(i, j, k, ForgeDirection.SOUTH.ordinal(), 0);
break;
case EAST:
world.setBlockMetadataWithNotify(i, j, k, ForgeDirection.NORTH.ordinal(), 0);
break;
case NORTH:
world.setBlockMetadataWithNotify(i, j, k, ForgeDirection.WEST.ordinal(), 0);
break;
case SOUTH:
default:
world.setBlockMetadataWithNotify(i, j, k, ForgeDirection.EAST.ordinal(), 0);
break;
}
((IToolWrench) equipped).wrenchUsed(entityplayer, i, j, k);
world.markBlockForUpdate(i, j, k);
return true;
} else {
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(entityplayer.getCurrentEquippedItem());
if (liquid != null) {
int qty = ((TileRefinery) world.getBlockTileEntity(i, j, k)).fill(ForgeDirection.UNKNOWN, liquid, true);
if (qty != 0 && !BuildCraftCore.debugMode && !entityplayer.capabilities.isCreativeMode) {
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem,
Utils.consumeItem(entityplayer.inventory.getCurrentItem()));
}
if (current != null && current.itemID != Item.bucketEmpty.itemID) {
if (!world.isRemote) {
if (FluidUtils.handleRightClick((TileRefinery) tile, ForgeDirection.getOrientation(side), player, true, false))
return true;
} else if (FluidContainerRegistry.isContainer(current)) {
return true;
}
}
if (!CoreProxy.proxy.isRenderWorld(world)) {
entityplayer.openGui(BuildCraftFactory.instance, GuiIds.REFINERY, world, i, j, k);
if (!world.isRemote) {
player.openGui(BuildCraftFactory.instance, GuiIds.REFINERY, world, x, y, z);
}
return true;

View file

@ -18,6 +18,7 @@ import buildcraft.api.recipes.RefineryRecipes;
import buildcraft.api.recipes.RefineryRecipes.Recipe;
import buildcraft.core.IMachine;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.fluids.SingleUseTank;
import buildcraft.core.fluids.Tank;
import buildcraft.core.fluids.TankManager;
import buildcraft.core.network.PacketPayload;
@ -43,12 +44,11 @@ import net.minecraftforge.fluids.IFluidHandler;
public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowerReceptor, IInventory, IMachine {
private Fluid[] filters = new Fluid[2];
public static int LIQUID_PER_SLOT = FluidContainerRegistry.BUCKET_VOLUME * 4;
public Tank tank1 = new Tank("tank1", LIQUID_PER_SLOT);
public Tank tank2 = new Tank("tank2", LIQUID_PER_SLOT);
public Tank result = new Tank("result", LIQUID_PER_SLOT);
public TankManager tankManager = new TankManager(tank1, tank2, result);
public SingleUseTank tank1 = new SingleUseTank("tank1", LIQUID_PER_SLOT);
public SingleUseTank tank2 = new SingleUseTank("tank2", LIQUID_PER_SLOT);
public SingleUseTank result = new SingleUseTank("result", LIQUID_PER_SLOT);
public TankManager<SingleUseTank> tankManager = new TankManager<SingleUseTank>(tank1, tank2, result);
public float animationSpeed = 1;
private int animationStage = 0;
SafeTimeTracker time = new SafeTimeTracker();
@ -124,11 +124,11 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
if (CoreProxy.proxy.isRenderWorld(worldObj)) {
simpleAnimationIterate();
return;
} else if (CoreProxy.proxy.isSimulating(worldObj) && updateNetworkTime.markTimeIfDelay(worldObj, 2 * BuildCraftCore.updateFactor)) {
sendNetworkUpdate();
}
if (updateNetworkTime.markTimeIfDelay(worldObj, BuildCraftCore.updateFactor))
sendNetworkUpdate();
isActive = false;
Recipe currentRecipe = RefineryRecipes.findRefineryRecipe(tank1.getFluid(), tank2.getFluid());
@ -217,9 +217,6 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
powerHandler.readFromNBT(data);
initPowerProvider();
filters[0] = FluidRegistry.getFluid(data.getString("filter0"));
filters[1] = FluidRegistry.getFluid(data.getString("filter1"));
}
@Override
@ -231,11 +228,6 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
data.setInteger("animationStage", animationStage);
data.setFloat("animationSpeed", animationSpeed);
powerHandler.writeToNBT(data);
if (filters[0] != null)
data.setString("filter0", filters[0].getName());
if (filters[1] != null)
data.setString("filter1", filters[1].getName());
}
public int getAnimationStage() {
@ -295,12 +287,18 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
public void closeChest() {
}
public void resetFilters() {
for (SingleUseTank tank : tankManager) {
tank.setAcceptedFluid(null);
}
}
public void setFilter(int number, Fluid fluid) {
filters[number] = fluid;
tankManager.get(number).setAcceptedFluid(fluid);
}
public Fluid getFilter(int number) {
return filters[number];
return tankManager.get(number).getAcceptedFluid();
}
@Override
@ -312,19 +310,19 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
public void getGUINetworkData(int id, int data) {
switch (id) {
case 0:
filters[0] = FluidRegistry.getFluid(data);
setFilter(0, FluidRegistry.getFluid(data));
break;
case 1:
filters[1] = FluidRegistry.getFluid(data);
setFilter(1, FluidRegistry.getFluid(data));
break;
}
}
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
if (filters[0] != null)
iCrafting.sendProgressBarUpdate(container, 0, filters[0].getID());
if (filters[1] != null)
iCrafting.sendProgressBarUpdate(container, 1, filters[1].getID());
if (getFilter(0) != null)
iCrafting.sendProgressBarUpdate(container, 0, getFilter(0).getID());
if (getFilter(1) != null)
iCrafting.sendProgressBarUpdate(container, 1, getFilter(1).getID());
}
/* ITANKCONTAINER */
@ -333,26 +331,9 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
int used = 0;
FluidStack resourceUsing = resource.copy();
if (filters[0] != null || filters[1] != null) {
if (filters[0] == resource.getFluid()) {
used += tank1.fill(resourceUsing, doFill);
}
resourceUsing.amount -= used;
if (filters[1] == resource.getFluid()) {
used += tank2.fill(resourceUsing, doFill);
}
} else {
used += tank1.fill(resourceUsing, doFill);
resourceUsing.amount -= used;
used += tank2.fill(resourceUsing, doFill);
}
if (doFill && used > 0) {
updateNetworkTime.markTime(worldObj);
sendNetworkUpdate();
}
used += tank1.fill(resourceUsing, doFill);
resourceUsing.amount -= used;
used += tank2.fill(resourceUsing, doFill);
return used;
}

View file

@ -76,7 +76,7 @@ public class GuiRefinery extends GuiAdvancedInterface {
if (position >= 0 && position < 2) {
if (k == 0) {
if (!this.isShiftKeyDown()) {
if (!isShiftKeyDown()) {
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(mc.thePlayer.inventory.getItemStack());
if (liquid == null) {
@ -84,7 +84,6 @@ public class GuiRefinery extends GuiAdvancedInterface {
}
container.setFilter(position, liquid.getFluid());
return;
} else {
container.setFilter(position, null);
}