Finished droppers!

This commit is contained in:
Aidan C. Brady 2015-02-26 21:09:04 -05:00
parent c39e3d1c1f
commit 183da4ef75
6 changed files with 82 additions and 43 deletions

View file

@ -3,9 +3,11 @@ package mekanism.client.gui;
import mekanism.api.Coord4D;
import mekanism.common.Mekanism;
import mekanism.common.base.IDropperHandler;
import mekanism.common.item.ItemGaugeDropper;
import mekanism.common.network.PacketDropperUse.DropperUseMessage;
import mekanism.common.util.LangUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
@ -35,17 +37,22 @@ public class GuiFluidGauge extends GuiGauge<Fluid>
@Override
public void mouseClicked(int xAxis, int yAxis, int button)
{
if(guiObj instanceof GuiMekanism)
if(xAxis >= xLocation + 1 && xAxis <= xLocation + width - 1 && yAxis >= yLocation + 1 && yAxis <= yLocation + height - 1)
{
TileEntity tile = ((GuiMekanism)guiObj).getTileEntity();
ItemStack stack = mc.thePlayer.inventory.getItemStack();
if(tile instanceof IDropperHandler)
if(guiObj instanceof GuiMekanism && stack != null && stack.getItem() instanceof ItemGaugeDropper)
{
int index = Arrays.asList(((IDropperHandler)tile).getTanks()).indexOf(infoHandler.getTank());
TileEntity tile = ((GuiMekanism)guiObj).getTileEntity();
if(index != -1)
if(tile instanceof IDropperHandler)
{
Mekanism.packetHandler.sendToServer(new DropperUseMessage(Coord4D.get(tile), button, index));
int index = Arrays.asList(((IDropperHandler)tile).getTanks()).indexOf(infoHandler.getTank());
if(index != -1)
{
Mekanism.packetHandler.sendToServer(new DropperUseMessage(Coord4D.get(tile), button, index));
}
}
}
}

View file

@ -1,16 +1,19 @@
package mekanism.client.gui;
import java.util.Arrays;
import mekanism.api.Coord4D;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasTank;
import mekanism.common.Mekanism;
import mekanism.common.base.IDropperHandler;
import mekanism.common.item.ItemGaugeDropper;
import mekanism.common.network.PacketDropperUse.DropperUseMessage;
import mekanism.common.util.MekanismUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import scala.actors.threadpool.Arrays;
public class GuiGasGauge extends GuiGauge<Gas>
{
@ -34,21 +37,22 @@ public class GuiGasGauge extends GuiGauge<Gas>
@Override
public void mouseClicked(int xAxis, int yAxis, int button)
{
System.out.println("clicked");
if(guiObj instanceof GuiMekanism)
if(xAxis >= xLocation + 1 && xAxis <= xLocation + width - 1 && yAxis >= yLocation + 1 && yAxis <= yLocation + height - 1)
{
System.out.println("mekanism");
TileEntity tile = ((GuiMekanism)guiObj).getTileEntity();
System.out.println(tile);
if(tile instanceof IDropperHandler)
ItemStack stack = mc.thePlayer.inventory.getItemStack();
if(guiObj instanceof GuiMekanism && stack != null && stack.getItem() instanceof ItemGaugeDropper)
{
System.out.println("handler");
int index = Arrays.asList(((IDropperHandler)tile).getTanks()).indexOf(infoHandler.getTank());
TileEntity tile = ((GuiMekanism)guiObj).getTileEntity();
if(index != -1)
if(tile instanceof IDropperHandler)
{
System.out.println("sending " + index);
Mekanism.packetHandler.sendToServer(new DropperUseMessage(Coord4D.get(tile), button, index));
int index = Arrays.asList(((IDropperHandler)tile).getTanks()).indexOf(infoHandler.getTank());
if(index != -1)
{
Mekanism.packetHandler.sendToServer(new DropperUseMessage(Coord4D.get(tile), button, index));
}
}
}
}

View file

@ -61,7 +61,6 @@ import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.machines.SmeltingRecipe;
import mekanism.common.recipe.outputs.ChanceOutput;
import mekanism.common.recipe.outputs.ItemStackOutput;
import mekanism.common.tile.TileEntityAdvancedBoundingBlock;
import mekanism.common.tile.TileEntityBoiler;
@ -450,6 +449,9 @@ public class Mekanism
CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(MekanismItems.Flamethrower.getEmptyItem(), new Object[] {
"TTT", "TGS", "BCB", Character.valueOf('T'), "ingotTin", Character.valueOf('G'), MekanismUtils.getEmptyGasTank(), Character.valueOf('S'), Items.flint_and_steel, Character.valueOf('B'), "ingotBronze", Character.valueOf('C'), "circuitAdvanced"
}));
CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(MekanismItems.GaugeDropper.getEmptyItem(), new Object[] {
" O ", "G G", "GGG", Character.valueOf('O'), "ingotOsmium", Character.valueOf('G'), "paneGlass"
}));
//Energy Cube recipes
CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(MekanismUtils.getEnergyCube(EnergyCubeTier.BASIC), new Object[] {

View file

@ -73,7 +73,7 @@ public class MekanismItems
public static final ItemFlamethrower Flamethrower = (ItemFlamethrower)new ItemFlamethrower().setUnlocalizedName("Flamethrower");
public static final ItemSeismicReader SeismicReader = (ItemSeismicReader)new ItemSeismicReader().setUnlocalizedName("SeismicReader");
public static final Item Dictionary = new ItemDictionary().setUnlocalizedName("Dictionary");
public static final Item GaugeDropper = new ItemGaugeDropper().setUnlocalizedName("GaugeDropper");
public static final ItemGaugeDropper GaugeDropper = (ItemGaugeDropper)new ItemGaugeDropper().setUnlocalizedName("GaugeDropper");
public static final Item FilterCard = new ItemFilterCard().setUnlocalizedName("FilterCard");
public static final Item PartTransmitter = new ItemPartTransmitter().setUnlocalizedName("MultipartTransmitter");
public static final Item GlowPanel = new ItemGlowPanel().setUnlocalizedName("GlowPanel");

View file

@ -4,6 +4,7 @@ import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.common.item.ItemGaugeDropper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
@ -17,9 +18,14 @@ public interface IDropperHandler
public static void useDropper(EntityPlayer player, Object tank, int button)
{
ItemStack stack = player.inventory.getItemStack();
if(stack == null || !(stack.getItem() instanceof ItemGaugeDropper))
{
return;
}
ItemGaugeDropper dropper = (ItemGaugeDropper)stack.getItem();
System.out.println("use dropper " + player + " " + tank + " " + button + " " + stack);
if(stack != null)
{
if(tank instanceof GasTank)
@ -42,6 +48,8 @@ public interface IDropperHandler
int toInsert = Math.min(gasTank.getStored(), ItemGaugeDropper.CAPACITY-dropperStored);
GasStack drawn = gasTank.draw(toInsert, true);
dropper.setGas(stack, new GasStack(gasTank.getGasType(), dropperStored+(drawn != null ? drawn.amount : 0)));
((EntityPlayerMP)player).sendContainerAndContentsToPlayer(player.openContainer, player.openContainer.getInventory());
}
else { //Extract gas from dropper
if(dropper.getFluid(stack) != null || gasTank.getNeeded() == 0)
@ -52,6 +60,8 @@ public interface IDropperHandler
int toExtract = Math.min(gasTank.getNeeded(), dropperStored);
toExtract = gasTank.receive(new GasStack(dropper.getGas(stack).getGas(), toExtract), true);
dropper.setGas(stack, new GasStack(dropper.getGas(stack).getGas(), dropperStored-toExtract));
((EntityPlayerMP)player).sendContainerAndContentsToPlayer(player.openContainer, player.openContainer.getInventory());
}
}
else if(tank instanceof FluidTank)
@ -74,6 +84,8 @@ public interface IDropperHandler
int toInsert = Math.min(fluidTank.getFluidAmount(), ItemGaugeDropper.CAPACITY-dropperStored);
FluidStack drawn = fluidTank.drain(toInsert, true);
dropper.setFluid(stack, new FluidStack(fluidTank.getFluid().getFluid(), dropperStored+(drawn != null ? drawn.amount : 0)));
((EntityPlayerMP)player).sendContainerAndContentsToPlayer(player.openContainer, player.openContainer.getInventory());
}
else { //Extract fluid from dropper
if(dropper.getGas(stack) != null || fluidTank.getCapacity()-fluidTank.getFluidAmount() == 0)
@ -84,6 +96,8 @@ public interface IDropperHandler
int toExtract = Math.min(fluidTank.getCapacity()-fluidTank.getFluidAmount(), dropperStored);
toExtract = fluidTank.fill(new FluidStack(dropper.getFluid(stack).getFluid(), toExtract), true);
dropper.setFluid(stack, new FluidStack(dropper.getFluid(stack).getFluid(), dropperStored-toExtract));
((EntityPlayerMP)player).sendContainerAndContentsToPlayer(player.openContainer, player.openContainer.getInventory());
}
}
}

View file

@ -33,12 +33,36 @@ public class ItemGaugeDropper extends ItemMekanism implements IGasItem, IFluidCo
setCreativeTab(Mekanism.tabMekanism);
}
@Override
public void getSubItems(Item item, CreativeTabs tabs, List list)
private void updateDamage(ItemStack stack)
{
GasStack gas = getGas(stack);
FluidStack fluid = getFluid(stack);
if(gas == null && fluid == null)
{
stack.setItemDamage(100);
}
else if(gas != null)
{
stack.setItemDamage((int)Math.max(1, (Math.abs((((float)gas.amount/getMaxGas(stack))*100)-100))));
}
else if(fluid != null)
{
stack.setItemDamage((int)Math.max(1, (Math.abs((((float)fluid.amount/getCapacity(stack))*100)-100))));
}
}
public ItemStack getEmptyItem()
{
ItemStack empty = new ItemStack(this);
empty.setItemDamage(100);
list.add(empty);
return empty;
}
@Override
public void getSubItems(Item item, CreativeTabs tabs, List list)
{
list.add(getEmptyItem());
}
@Override
@ -85,18 +109,12 @@ public class ItemGaugeDropper extends ItemMekanism implements IGasItem, IFluidCo
{
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("fluidStack"));
if(stack == null)
{
container.setItemDamage(100);
}
else {
container.setItemDamage((int)Math.max(1, (Math.abs((((float)stack.amount/getMaxGas(container))*100)-100))));
}
updateDamage(container);
return stack;
}
container.setItemDamage(100);
updateDamage(container);
return null;
}
@ -110,13 +128,13 @@ public class ItemGaugeDropper extends ItemMekanism implements IGasItem, IFluidCo
if(stack == null || stack.amount == 0 || stack.fluidID == 0)
{
container.setItemDamage(100);
container.stackTagCompound.removeTag("fluidStack");
}
else {
container.setItemDamage((int)Math.max(1, (Math.abs((((float)stack.amount/getMaxGas(container))*100)-100))));
container.stackTagCompound.setTag("fluidStack", stack.writeToNBT(new NBTTagCompound()));
}
updateDamage(container);
}
@Override
@ -192,13 +210,7 @@ public class ItemGaugeDropper extends ItemMekanism implements IGasItem, IFluidCo
GasStack stored = GasStack.readFromNBT(itemstack.stackTagCompound.getCompoundTag("gasStack"));
if(stored == null)
{
itemstack.setItemDamage(100);
}
else {
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)stored.amount/getMaxGas(itemstack))*100)-100))));
}
updateDamage(itemstack);
return stored;
}
@ -213,16 +225,16 @@ public class ItemGaugeDropper extends ItemMekanism implements IGasItem, IFluidCo
if(stack == null || stack.amount == 0)
{
itemstack.setItemDamage(100);
itemstack.stackTagCompound.removeTag("gasStack");
}
else {
int amount = Math.max(0, Math.min(stack.amount, getMaxGas(itemstack)));
GasStack gasStack = new GasStack(stack.getGas(), amount);
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)amount/getMaxGas(itemstack))*100)-100))));
itemstack.stackTagCompound.setTag("gasStack", gasStack.write(new NBTTagCompound()));
}
updateDamage(itemstack);
}
@Override