fix: force engine GUI

This commit is contained in:
LordMZTE 2024-05-05 16:13:50 +02:00
parent 9842cc1b6c
commit 422982d8a5
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
5 changed files with 75 additions and 115 deletions

View file

@ -33,10 +33,12 @@ public class BlockForceEngine extends BlockContainer implements ITEProvider {
setBlockName("forceengine"); setBlockName("forceengine");
} }
@Override
public TileEntity createNewTileEntity(World world, int var2) { public TileEntity createNewTileEntity(World world, int var2) {
return new TileEntityForceEngine(); return new TileEntityForceEngine();
} }
@Override
public boolean onBlockActivated( public boolean onBlockActivated(
World world, World world,
int x, int x,
@ -81,6 +83,7 @@ public class BlockForceEngine extends BlockContainer implements ITEProvider {
} }
} }
@Override
public void onBlockPlacedBy( public void onBlockPlacedBy(
World world, int x, int y, int z, EntityLivingBase living, ItemStack stack World world, int x, int y, int z, EntityLivingBase living, ItemStack stack
) { ) {
@ -91,6 +94,7 @@ public class BlockForceEngine extends BlockContainer implements ITEProvider {
} }
} }
@Override
public int getLightValue(IBlockAccess world, int x, int y, int z) { public int getLightValue(IBlockAccess world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z); TileEntity te = world.getTileEntity(x, y, z);
return te instanceof TileEntityForceEngine return te instanceof TileEntityForceEngine
@ -98,18 +102,22 @@ public class BlockForceEngine extends BlockContainer implements ITEProvider {
: 0; : 0;
} }
@Override
public int getRenderType() { public int getRenderType() {
return -1; return -1;
} }
@Override
public boolean isOpaqueCube() { public boolean isOpaqueCube() {
return false; return false;
} }
@Override
public boolean renderAsNormalBlock() { public boolean renderAsNormalBlock() {
return false; return false;
} }
@Override
public void breakBlock(World world, int x, int y, int z, Block par5, int par6) { public void breakBlock(World world, int x, int y, int z, Block par5, int par6) {
if (Dartcraft.proxy.isSimulating(world)) { if (Dartcraft.proxy.isSimulating(world)) {
TileEntity tile = world.getTileEntity(x, y, z); TileEntity tile = world.getTileEntity(x, y, z);

View file

@ -22,7 +22,9 @@ public class ContainerForceEngine extends Container {
this.user = player; this.user = player;
this.engine = engine; this.engine = engine;
this.playerInv = (IInventory) player.inventory; this.playerInv = (IInventory) player.inventory;
this.addSlotToContainer(new FuelSlot((IInventory) engine.liquidInventory, 0, 38, 33)); this.addSlotToContainer(
new FuelSlot((IInventory) engine.liquidInventory, 0, 38, 33)
);
this.addSlotToContainer( this.addSlotToContainer(
new ThrottleSlot((IInventory) engine.liquidInventory, 1, 122, 33) new ThrottleSlot((IInventory) engine.liquidInventory, 1, 122, 33)
); );
@ -37,16 +39,7 @@ public class ContainerForceEngine extends Container {
this.addSlotToContainer(new Slot(this.playerInv, i, 8 + 18 * i, 137)); this.addSlotToContainer(new Slot(this.playerInv, i, 8 + 18 * i, 137));
} }
public void detectAndSendChanges() { @Override
super.detectAndSendChanges();
for (int i = 0; i < crafters.size(); i++)
this.engine.sendGuiNetworkData(this, (ICrafting) crafters.get(i));
}
public void updateProgressBar(int i, int j) {
this.engine.receiveGuiNetworkData(i, j);
}
public ItemStack transferStackInSlot(EntityPlayer player, int index) { public ItemStack transferStackInSlot(EntityPlayer player, int index) {
ItemStack returnStack = null; ItemStack returnStack = null;
Slot slot = (Slot) inventorySlots.get(index); Slot slot = (Slot) inventorySlots.get(index);
@ -78,9 +71,11 @@ public class ContainerForceEngine extends Container {
return returnStack; return returnStack;
} }
@Override
protected void protected void
retrySlotClick(int par1, int par2, boolean par3, EntityPlayer par4EntityPlayer) {} retrySlotClick(int par1, int par2, boolean par3, EntityPlayer par4EntityPlayer) {}
@Override
public boolean canInteractWith(EntityPlayer player) { public boolean canInteractWith(EntityPlayer player) {
return true; return true;
} }
@ -90,6 +85,7 @@ public class ContainerForceEngine extends Container {
super(par1iInventory, par2, par3, par4); super(par1iInventory, par2, par3, par4);
} }
@Override
public boolean isItemValid(ItemStack stack) { public boolean isItemValid(ItemStack stack) {
if (stack.getItem() == DartItems.forcegem) if (stack.getItem() == DartItems.forcegem)
return true; return true;
@ -104,6 +100,7 @@ public class ContainerForceEngine extends Container {
super(par1iInventory, par2, par3, par4); super(par1iInventory, par2, par3, par4);
} }
@Override
public boolean isItemValid(ItemStack stack) { public boolean isItemValid(ItemStack stack) {
return ForceEngineLiquids.isThrottle( return ForceEngineLiquids.isThrottle(
FluidContainerRegistry.getFluidForFilledItem(stack) FluidContainerRegistry.getFluidForFilledItem(stack)

View file

@ -1,5 +1,13 @@
package ley.modding.dartcraft.client.gui; package ley.modding.dartcraft.client.gui;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.opengl.GL11;
import codechicken.nei.guihook.IContainerTooltipHandler;
import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Loader;
import ley.modding.dartcraft.Dartcraft; import ley.modding.dartcraft.Dartcraft;
import ley.modding.dartcraft.api.energy.EngineLiquid; import ley.modding.dartcraft.api.energy.EngineLiquid;
@ -8,18 +16,16 @@ import ley.modding.dartcraft.client.gui.tabs.Tab;
import ley.modding.dartcraft.tile.TileEntityForceEngine; import ley.modding.dartcraft.tile.TileEntityForceEngine;
import ley.modding.dartcraft.util.ForceEngineLiquids; import ley.modding.dartcraft.util.ForceEngineLiquids;
import ley.modding.dartcraft.util.FortunesUtil; import ley.modding.dartcraft.util.FortunesUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon; import net.minecraft.util.IIcon;
import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11;
import java.awt.*; public class GuiEngine extends GuiTab implements IContainerTooltipHandler {
import java.util.ArrayList;
import java.util.List;
public class GuiEngine extends GuiTab {
private TileEntityForceEngine engine; private TileEntityForceEngine engine;
private ContainerForceEngine container; private ContainerForceEngine container;
@ -48,8 +54,26 @@ public class GuiEngine extends GuiTab {
this.throttleBounds = new Rectangle(this.guiLeft + 94, this.guiTop + 11, 16, 58); this.throttleBounds = new Rectangle(this.guiLeft + 94, this.guiTop + 11, 16, 58);
} }
@Override
public List<String> public List<String>
handleItemTooltip(ItemStack stack, int x, int y, List<String> tooltip) { handleTooltip(GuiContainer gui, int mousex, int mousey, List<String> currenttip) {
return currenttip;
}
@Override
public List<String> handleItemDisplayName(
GuiContainer gui, ItemStack itemstack, List<String> currenttip
) {
return currenttip;
}
@Override
protected void drawTooltips() {}
@Override
public List<String> handleItemTooltip(
GuiContainer gui, ItemStack itemstack, int x, int y, List<String> tooltip
) {
Point pointerLoc = new Point(x, y); Point pointerLoc = new Point(x, y);
if (this.fuelBounds.contains(pointerLoc)) if (this.fuelBounds.contains(pointerLoc))
try { try {
@ -78,15 +102,15 @@ public class GuiEngine extends GuiTab {
Dartcraft.proxy.bindTexture("engineGui.png"); Dartcraft.proxy.bindTexture("engineGui.png");
int posX = (this.width - this.xSize) / 2; int posX = (this.width - this.xSize) / 2;
int posY = (this.height - this.ySize) / 2; int posY = (this.height - this.ySize) / 2;
drawTexturedModalRect(posX, posY, 0, 0, this.xSize, this.ySize); this.drawTexturedModalRect(posX, posY, 0, 0, this.xSize, this.ySize);
if (this.engine.fuelTank.getFluid() != null if (this.engine.fuelTank.getFluid() != null
&& (this.engine.fuelTank.getFluid()).amount > 0) && (this.engine.fuelTank.getFluid()).amount > 0)
displayGauge( this.displayGauge(
this.fuelBounds.x, this.fuelBounds.y, this.engine.fuelTank.getFluid() this.fuelBounds.x, this.fuelBounds.y, this.engine.fuelTank.getFluid()
); );
if (this.engine.throttleTank.getFluid() != null if (this.engine.throttleTank.getFluid() != null
&& (this.engine.throttleTank.getFluid()).amount > 0) && (this.engine.throttleTank.getFluid()).amount > 0)
displayGauge( this.displayGauge(
this.throttleBounds.x, this.throttleBounds.x,
this.throttleBounds.y, this.throttleBounds.y,
this.engine.throttleTank.getFluid() this.engine.throttleTank.getFluid()
@ -99,7 +123,9 @@ public class GuiEngine extends GuiTab {
return; return;
int start = 0; int start = 0;
int squaled = (int) (58.0F * liquid.amount / 10000.0F); int squaled = (int) (58.0F * liquid.amount / 10000.0F);
Dartcraft.proxy.bindTexture("textures/atlas/blocks.png"); Minecraft.getMinecraft().getTextureManager().bindTexture(
TextureMap.locationBlocksTexture
);
do { do {
tempx = 0; tempx = 0;
if (squaled > 16) { if (squaled > 16) {
@ -112,17 +138,15 @@ public class GuiEngine extends GuiTab {
IIcon icon = liquid.getFluid().getStillIcon(); IIcon icon = liquid.getFluid().getStillIcon();
if (icon == null) if (icon == null)
icon = FluidRegistry.LAVA.getStillIcon(); icon = FluidRegistry.LAVA.getStillIcon();
drawTexturedModelRectFromIcon( this.drawTexturedModelRectFromIcon(
x, y + 58 - tempx - start, icon, 16, 16 - 16 - tempx x, y + 58 - tempx - start, icon, 16, 16 - (16 - tempx)
); );
start += 16; start += 16;
} while (tempx != 0 && squaled != 0); } while (tempx != 0 && squaled != 0);
Dartcraft.proxy.bindTexture("engineGui.png"); Dartcraft.proxy.bindTexture("engineGui.png");
drawTexturedModalRect(x, y, 176, 0, 16, 58); this.drawTexturedModalRect(x, y, 176, 0, 16, 58);
} }
protected void drawTooltips() {}
private class EnergyTab extends Tab { private class EnergyTab extends Tab {
public EnergyTab(Gui gui) { public EnergyTab(Gui gui) {
super(gui); super(gui);

View file

@ -7,6 +7,8 @@ import ley.modding.dartcraft.Dartcraft;
import ley.modding.dartcraft.api.energy.EngineLiquid; import ley.modding.dartcraft.api.energy.EngineLiquid;
import ley.modding.dartcraft.item.DartItems; import ley.modding.dartcraft.item.DartItems;
import ley.modding.dartcraft.util.ForceEngineLiquids; import ley.modding.dartcraft.util.ForceEngineLiquids;
import net.anvilcraft.alec.jalec.AlecLogger;
import net.anvilcraft.anvillib.vector.WorldVec;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
@ -195,6 +197,7 @@ public class TileEntityForceEngine extends TileEntity
&& this.throttleTank.getFluid().amount <= 0) { && this.throttleTank.getFluid().amount <= 0) {
this.throttleTank.setFluid(null); this.throttleTank.setFluid(null);
} }
new WorldVec(this).markForUpdate();
} }
} }
@ -246,6 +249,7 @@ public class TileEntityForceEngine extends TileEntity
} else { } else {
this.liquidInventory.decrStackSize(0, 1); this.liquidInventory.decrStackSize(0, 1);
} }
new WorldVec(this).markForUpdate();
} }
} }
@ -260,6 +264,7 @@ public class TileEntityForceEngine extends TileEntity
new FluidStack(curCycle, (int) (1000.0F * Config.gemValue)), true new FluidStack(curCycle, (int) (1000.0F * Config.gemValue)), true
); );
this.liquidInventory.decrStackSize(0, 1); this.liquidInventory.decrStackSize(0, 1);
new WorldVec(this).markForUpdate();
} }
} }
@ -284,6 +289,7 @@ public class TileEntityForceEngine extends TileEntity
); );
} else { } else {
this.liquidInventory.decrStackSize(1, 1); this.liquidInventory.decrStackSize(1, 1);
new WorldVec(this).markForUpdate();
} }
} }
} }
@ -311,7 +317,7 @@ public class TileEntityForceEngine extends TileEntity
} else { } else {
this.isActive = false; this.isActive = false;
} }
//TODO Fix Cycling update // TODO Fix Cycling update
} }
} }
@ -325,12 +331,16 @@ public class TileEntityForceEngine extends TileEntity
this.fuelTank.setFluid( this.fuelTank.setFluid(
FluidStack.loadFluidStackFromNBT(data.getCompoundTag("fuel")) FluidStack.loadFluidStackFromNBT(data.getCompoundTag("fuel"))
); );
} else {
this.fuelTank.setFluid(null);
} }
if (data.hasKey("throttle")) { if (data.hasKey("throttle")) {
this.throttleTank.setFluid( this.throttleTank.setFluid(
FluidStack.loadFluidStackFromNBT(data.getCompoundTag("throttle")) FluidStack.loadFluidStackFromNBT(data.getCompoundTag("throttle"))
); );
} else {
this.throttleTank.setFluid(null);
} }
if (data.hasKey("fuelSlot")) { if (data.hasKey("fuelSlot")) {
@ -338,7 +348,7 @@ public class TileEntityForceEngine extends TileEntity
0, ItemStack.loadItemStackFromNBT(data.getCompoundTag("fuelSlot")) 0, ItemStack.loadItemStackFromNBT(data.getCompoundTag("fuelSlot"))
); );
} else { } else {
this.liquidInventory.setInventorySlotContents(0, (ItemStack) null); this.liquidInventory.setInventorySlotContents(0, null);
} }
if (data.hasKey("throttleSlot")) { if (data.hasKey("throttleSlot")) {
@ -346,7 +356,7 @@ public class TileEntityForceEngine extends TileEntity
1, ItemStack.loadItemStackFromNBT(data.getCompoundTag("throttleSlot")) 1, ItemStack.loadItemStackFromNBT(data.getCompoundTag("throttleSlot"))
); );
} else { } else {
this.liquidInventory.setInventorySlotContents(1, (ItemStack) null); this.liquidInventory.setInventorySlotContents(1, null);
} }
} }
@ -515,95 +525,17 @@ public class TileEntityForceEngine extends TileEntity
this.throttleTank.getInfo() }; this.throttleTank.getInfo() };
} }
@Override
public Packet getDescriptionPacket() { public Packet getDescriptionPacket() {
NBTTagCompound comp = new NBTTagCompound(); NBTTagCompound comp = new NBTTagCompound();
this.writeToNBT(comp); this.writeToNBT(comp);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, comp); return new S35PacketUpdateTileEntity(
xCoord, yCoord, zCoord, this.getBlockMetadata(), comp
);
} }
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
if (pkt != null && pkt.func_148857_g() != null) { this.readFromNBT(pkt.func_148857_g());
this.readFromNBT(pkt.func_148857_g());
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); //TODO Lighting
//worldObj.updateAllLightTypes(this.field_70329_l, this.field_70330_m,
//this.field_70327_n);
}
}
public void sendGuiNetworkData(Container container, ICrafting craft) {
byte throttleMeta = 0;
int throttleID = 0;
int throttleAmount = 0;
byte fuelMeta = 0;
int fuelID = 0;
int fuelAmount = 0;
if (this.fuelTank.getFluid() != null) {
fuelID = this.fuelTank.getFluid().getFluidID();
fuelAmount = this.fuelTank.getFluid().amount;
}
if (this.throttleTank.getFluid() != null) {
throttleID = this.throttleTank.getFluid().getFluidID();
throttleAmount = this.throttleTank.getFluid().amount;
}
craft.sendProgressBarUpdate(container, 0, fuelID);
craft.sendProgressBarUpdate(container, 1, fuelMeta);
craft.sendProgressBarUpdate(container, 2, fuelAmount);
craft.sendProgressBarUpdate(container, 3, throttleID);
craft.sendProgressBarUpdate(container, 4, throttleMeta);
craft.sendProgressBarUpdate(container, 5, throttleAmount);
if (craft instanceof EntityPlayerMP && Dartcraft.proxy.isSimulating(worldObj)) {
((EntityPlayerMP) craft)
.playerNetServerHandler.sendPacket(getDescriptionPacket());
}
}
public void receiveGuiNetworkData(int i, int j) {
FluidStack tempStack = this.fuelTank.getFluid();
FluidStack tempStack2 = this.throttleTank.getFluid();
switch (i) {
case 0:
if (this.fuelTank.getFluid() != null) {
this.fuelTank.setFluid(
new FluidStack(j, tempStack.amount, tempStack.tag)
);
} else if (j > 0) {
this.fuelTank.setFluid(new FluidStack(j, 0));
}
break;
case 1:
if (this.fuelTank.getFluid() != null) {
this.fuelTank.setFluid(new FluidStack(
tempStack.getFluidID(), tempStack.amount, (NBTTagCompound) null
));
}
break;
case 2:
if (this.fuelTank.getFluid() != null) {
this.fuelTank.getFluid().amount = j;
}
break;
case 3:
if (this.throttleTank.getFluid() != null) {
this.throttleTank.setFluid(
new FluidStack(j, tempStack2.amount, tempStack2.tag)
);
} else if (j > 0) {
this.throttleTank.setFluid(new FluidStack(j, 0));
}
break;
case 4:
if (this.throttleTank.getFluid() != null) {
this.throttleTank.setFluid(new FluidStack(
tempStack2.getFluidID(), tempStack2.amount, (NBTTagCompound) null
));
}
break;
case 5:
if (this.throttleTank.getFluid() != null) {
this.throttleTank.getFluid().amount = j;
}
}
} }
} }

View file

@ -3,7 +3,6 @@ package ley.modding.dartcraft.tile;
import java.util.List; import java.util.List;
import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import ley.modding.dartcraft.Config; import ley.modding.dartcraft.Config;
import ley.modding.dartcraft.Dartcraft; import ley.modding.dartcraft.Dartcraft;
import ley.modding.dartcraft.entity.EntityTime; import ley.modding.dartcraft.entity.EntityTime;