Work on droppers! Easiest way to get rid of leftover fluids and gasses in machine gauges.

This commit is contained in:
Aidan C. Brady 2015-02-26 19:30:19 -05:00
parent 7a1085d38d
commit 49d0a7fc4b
14 changed files with 384 additions and 15 deletions

View file

@ -1,8 +1,12 @@
package mekanism.client.gui;
import mekanism.api.Coord4D;
import mekanism.common.Mekanism;
import mekanism.common.base.IDropperHandler;
import mekanism.common.network.PacketDropperUse.DropperUseMessage;
import mekanism.common.util.LangUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.Fluid;
@ -26,6 +30,25 @@ public class GuiFluidGauge extends GuiGauge<Fluid>
return gauge;
}
@Override
public void mouseClicked(int xAxis, int yAxis, int button)
{
if(guiObj instanceof GuiMekanism)
{
TileEntity tile = ((GuiMekanism)guiObj).tileEntity;
if(tile instanceof IDropperHandler)
{
int index = ((IDropperHandler)tile).getTankId(infoHandler.getTank());
if(index != -1)
{
Mekanism.packetHandler.sendToServer(new DropperUseMessage(Coord4D.get(tile), button, index));
}
}
}
}
@Override
public int getScaledLevel()

View file

@ -1,9 +1,14 @@
package mekanism.client.gui;
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.base.IRedstoneControl.RedstoneControl;
import mekanism.common.network.PacketDropperUse.DropperUseMessage;
import mekanism.common.util.MekanismUtils;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
@ -25,6 +30,25 @@ public class GuiGasGauge extends GuiGauge<Gas>
return gauge;
}
@Override
public void mouseClicked(int xAxis, int yAxis, int button)
{
if(guiObj instanceof GuiMekanism)
{
TileEntity tile = ((GuiMekanism)guiObj).tileEntity;
if(tile instanceof IDropperHandler)
{
int index = ((IDropperHandler)tile).getTankId(infoHandler.getTank());
if(index != -1)
{
Mekanism.packetHandler.sendToServer(new DropperUseMessage(Coord4D.get(tile), button, index));
}
}
}
}
@Override
public int getScaledLevel()

View file

@ -1,12 +1,12 @@
package mekanism.client.gui;
import mekanism.client.render.MekanismRenderer;
import mekanism.common.base.IDropperHandler;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import codechicken.lib.vec.Rectangle4i;
public abstract class GuiGauge<T> extends GuiElement
@ -21,7 +21,7 @@ public abstract class GuiGauge<T> extends GuiElement
protected boolean dummy;
protected T dummyType;
public GuiGauge(Type type, IGuiWrapper gui, ResourceLocation def, int x, int y)
{
super(MekanismUtils.getResource(ResourceType.GUI_ELEMENT, type.textureLocation), gui, def);
@ -117,7 +117,7 @@ public abstract class GuiGauge<T> extends GuiElement
@Override
public void mouseClicked(int xAxis, int yAxis, int button)
{
}
public void setDummyType(T type)

View file

@ -23,7 +23,7 @@ public abstract class GuiMekanism extends GuiContainer implements IGuiWrapper
{
public Set<GuiElement> guiElements = new HashSet<GuiElement>();
private TileEntityContainerBlock tileEntity;
public TileEntityContainerBlock tileEntity;
public GuiMekanism(Container container)
{

View file

@ -18,8 +18,7 @@ public class GuiMekanismConfig extends GuiConfig
{
public GuiMekanismConfig(GuiScreen parent)
{
super(parent, getConfigElements(),
"Mekanism", false, false, "Mekanism");
super(parent, getConfigElements(), "Mekanism", false, false, "Mekanism");
}
private static List<IConfigElement> getConfigElements()

View file

@ -15,6 +15,7 @@ import mekanism.common.item.ItemFilterCard;
import mekanism.common.item.ItemFlamethrower;
import mekanism.common.item.ItemFreeRunners;
import mekanism.common.item.ItemGasMask;
import mekanism.common.item.ItemGaugeDropper;
import mekanism.common.item.ItemHDPE;
import mekanism.common.item.ItemIngot;
import mekanism.common.item.ItemJetpack;
@ -30,7 +31,6 @@ import mekanism.common.item.ItemUpgrade;
import mekanism.common.item.ItemWalkieTalkie;
import mekanism.common.multipart.ItemGlowPanel;
import mekanism.common.multipart.ItemPartTransmitter;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -73,6 +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 Item FilterCard = new ItemFilterCard().setUnlocalizedName("FilterCard");
public static final Item PartTransmitter = new ItemPartTransmitter().setUnlocalizedName("MultipartTransmitter");
public static final Item GlowPanel = new ItemGlowPanel().setUnlocalizedName("GlowPanel");
@ -147,6 +148,7 @@ public class MekanismItems
GameRegistry.registerItem(BioFuel, "BioFuel");
GameRegistry.registerItem(GlowPanel, "GlowPanel");
GameRegistry.registerItem(Flamethrower, "Flamethrower");
GameRegistry.registerItem(GaugeDropper, "GaugeDropper");
FluidContainerRegistry.registerFluidContainer(FluidRegistry.getFluid("brine"), new ItemStack(BrineBucket), FluidContainerRegistry.EMPTY_BUCKET);
FluidContainerRegistry.registerFluidContainer(FluidRegistry.getFluid("lithium"), new ItemStack(LithiumBucket), FluidContainerRegistry.EMPTY_BUCKET);

View file

@ -1,5 +1,7 @@
package mekanism.common;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.List;
@ -20,6 +22,8 @@ import mekanism.common.network.PacketDigitUpdate;
import mekanism.common.network.PacketDigitUpdate.DigitUpdateMessage;
import mekanism.common.network.PacketDigitalMinerGui;
import mekanism.common.network.PacketDigitalMinerGui.DigitalMinerGuiMessage;
import mekanism.common.network.PacketDropperUse;
import mekanism.common.network.PacketDropperUse.DropperUseMessage;
import mekanism.common.network.PacketEditFilter;
import mekanism.common.network.PacketEditFilter.EditFilterMessage;
import mekanism.common.network.PacketElectricBowState;
@ -60,7 +64,6 @@ import mekanism.common.network.PacketTransmitterUpdate;
import mekanism.common.network.PacketTransmitterUpdate.TransmitterUpdateMessage;
import mekanism.common.network.PacketWalkieTalkieState;
import mekanism.common.network.PacketWalkieTalkieState.WalkieTalkieStateMessage;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
@ -77,8 +80,6 @@ import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;
import io.netty.buffer.ByteBuf;
/**
* Mekanism packet handler. As always, use packets sparingly!
* @author AidanBrady
@ -125,6 +126,7 @@ public class PacketHandler
netHandler.registerMessage(PacketPortableTankState.class, PortableTankStateMessage.class, 25, Side.SERVER);
netHandler.registerMessage(PacketContainerEditMode.class, ContainerEditModeMessage.class, 26, Side.SERVER);
netHandler.registerMessage(PacketFlamethrowerActive.class, FlamethrowerActiveMessage.class, 27, Side.SERVER);
netHandler.registerMessage(PacketDropperUse.class, DropperUseMessage.class, 28, Side.SERVER);
}
/**

View file

@ -0,0 +1,10 @@
package mekanism.common.base;
import net.minecraft.entity.player.EntityPlayer;
public interface IDropperHandler
{
public int getTankId(Object tank);
public void useDropper(EntityPlayer player, int tankId);
}

View file

@ -1065,7 +1065,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer
LASER_AMPLIFIER(MachineBlock.MACHINE_BLOCK_2, 14, "LaserAmplifier", 44, TileEntityLaserAmplifier.class, false, true, false),
LASER_TRACTOR_BEAM(MachineBlock.MACHINE_BLOCK_2, 15, "LaserTractorBeam", 45, TileEntityLaserTractorBeam.class, false, true, false),
ENTANGLED_BLOCK(MachineBlock.MACHINE_BLOCK_3, 0, "EntangledBlock", 46, TileEntityEntangledBlock.class, true, false, false),
SOLAR_NEUTRON_ACTIVATOR(MachineBlock.MACHINE_BLOCK_3, 1, "SolarNeutronActivator", -1/*48*/, TileEntitySolarNeutronActivator.class, false, true, false),
SOLAR_NEUTRON_ACTIVATOR(MachineBlock.MACHINE_BLOCK_3, 1, "SolarNeutronActivator", 47, TileEntitySolarNeutronActivator.class, false, true, false),
AMBIENT_ACCUMULATOR(MachineBlock.MACHINE_BLOCK_3, 2, "AmbientAccumulator", 48, TileEntityAmbientAccumulator.class, true, false, false);
public MachineBlock typeBlock;

View file

@ -36,7 +36,7 @@ public class ItemBlockGasTank extends ItemBlock implements IGasItem, ISustainedI
public int MAX_GAS = 96000;
/** How fast this tank can transfer gas. */
public static final int TRANSFER_RATE = 16;
public static final int TRANSFER_RATE = 256;
public ItemBlockGasTank(Block block)
{

View file

@ -0,0 +1,239 @@
package mekanism.common.item;
import java.util.List;
import mekanism.api.energy.IEnergizedItem;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.IGasItem;
import mekanism.common.Mekanism;
import mekanism.common.util.MekanismUtils;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;
public class ItemGaugeDropper extends ItemMekanism implements IGasItem, IFluidContainerItem
{
public static int CAPACITY = FluidContainerRegistry.BUCKET_VOLUME;
public static final int TRANSFER_RATE = 16;
public ItemGaugeDropper()
{
super();
setMaxStackSize(1);
setMaxDamage(100);
setNoRepair();
setCreativeTab(Mekanism.tabMekanism);
}
@Override
public void getSubItems(Item item, CreativeTabs tabs, List list)
{
ItemStack empty = new ItemStack(this);
empty.setItemDamage(100);
list.add(empty);
}
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
{
if(entityplayer.isSneaking())
{
setGas(itemstack, null);
setFluid(itemstack, null);
}
return itemstack;
}
@Override
public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag)
{
GasStack gasStack = getGas(itemstack);
FluidStack fluidStack = getFluid(itemstack);
if(gasStack == null && fluidStack == null)
{
list.add(MekanismUtils.localize("gui.empty") + ".");
}
else if(gasStack != null)
{
list.add(MekanismUtils.localize("tooltip.stored") + " " + gasStack.getGas().getLocalizedName() + ": " + gasStack.amount);
}
else if(fluidStack != null)
{
list.add(MekanismUtils.localize("tooltip.stored") + " " + fluidStack.getFluid().getLocalizedName(fluidStack) + ": " + fluidStack.amount);
}
}
@Override
public FluidStack getFluid(ItemStack container)
{
if(container.stackTagCompound == null)
{
return null;
}
if(container.stackTagCompound.hasKey("fluidStack"))
{
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))));
}
return stack;
}
container.setItemDamage(100);
return null;
}
public void setFluid(ItemStack container, FluidStack stack)
{
if(container.stackTagCompound == null)
{
container.setTagCompound(new NBTTagCompound());
}
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()));
}
}
@Override
public int getCapacity(ItemStack container)
{
return CAPACITY;
}
@Override
public int fill(ItemStack container, FluidStack resource, boolean doFill)
{
return 0;
}
@Override
public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain)
{
return null;
}
@Override
public int getRate(ItemStack itemstack)
{
return TRANSFER_RATE;
}
@Override
public int addGas(ItemStack itemstack, GasStack stack)
{
return 0;
}
@Override
public GasStack removeGas(ItemStack itemstack, int amount)
{
if(getGas(itemstack) == null)
{
return null;
}
Gas type = getGas(itemstack).getGas();
int gasToUse = Math.min(getStored(itemstack), Math.min(getRate(itemstack), amount));
setGas(itemstack, new GasStack(type, getStored(itemstack)-gasToUse));
return new GasStack(type, gasToUse);
}
private int getStored(ItemStack itemstack)
{
return getGas(itemstack) != null ? getGas(itemstack).amount : 0;
}
@Override
public boolean canReceiveGas(ItemStack itemstack, Gas type)
{
return false;
}
@Override
public boolean canProvideGas(ItemStack itemstack, Gas type)
{
return getGas(itemstack) != null && (type == null || getGas(itemstack).getGas() == type);
}
@Override
public GasStack getGas(ItemStack itemstack)
{
if(itemstack.stackTagCompound == null)
{
return null;
}
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))));
}
return stored;
}
@Override
public void setGas(ItemStack itemstack, GasStack stack)
{
if(itemstack.stackTagCompound == null)
{
itemstack.setTagCompound(new NBTTagCompound());
}
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()));
}
}
@Override
public int getMaxGas(ItemStack itemstack)
{
return CAPACITY;
}
@Override
public boolean isMetadataSpecific(ItemStack itemstack)
{
return false;
}
}

View file

@ -0,0 +1,69 @@
package mekanism.common.network;
import io.netty.buffer.ByteBuf;
import mekanism.api.Coord4D;
import mekanism.common.PacketHandler;
import mekanism.common.base.IDropperHandler;
import mekanism.common.network.PacketDropperUse.DropperUseMessage;
import net.minecraft.tileentity.TileEntity;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
public class PacketDropperUse implements IMessageHandler<DropperUseMessage, IMessage>
{
@Override
public IMessage onMessage(DropperUseMessage message, MessageContext context)
{
TileEntity tileEntity = message.coord4D.getTileEntity(PacketHandler.getPlayer(context).worldObj);
if(tileEntity instanceof IDropperHandler)
{
try {
((IDropperHandler)tileEntity).useDropper(PacketHandler.getPlayer(context), message.tankId);
} catch(Exception e) {
e.printStackTrace();
}
}
return null;
}
public static class DropperUseMessage implements IMessage
{
public Coord4D coord4D;
public int mouseButton;
public int tankId;
public DropperUseMessage() {}
public DropperUseMessage(Coord4D coord, int button, int id)
{
coord4D = coord;
mouseButton = button;
tankId = id;
}
@Override
public void toBytes(ByteBuf dataStream)
{
dataStream.writeInt(coord4D.xCoord);
dataStream.writeInt(coord4D.yCoord);
dataStream.writeInt(coord4D.zCoord);
dataStream.writeInt(coord4D.dimensionId);
dataStream.writeInt(mouseButton);
dataStream.writeInt(tankId);
}
@Override
public void fromBytes(ByteBuf dataStream)
{
coord4D = new Coord4D(dataStream.readInt(), dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
mouseButton = dataStream.readInt();
tankId = dataStream.readInt();
}
}
}

View file

@ -43,6 +43,7 @@ item.HDPESheet.name=HDPE Sheet
item.PlaStick.name=PlaStick
item.Substrate.name=Substrate
item.Flamethrower.name=Flamethrower
item.GaugeDropper.name=Gauge Dropper
//Control Circuits
item.BasicControlCircuit.name=Basic Control Circuit

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB