add larger buffer

This commit is contained in:
GlodBlock committed 2022-07-13 21:16:19 +08:00
1 parent 61cdd8c487
commit 35f2dd4073
12 files changed
+398

No files matched your search

@@ -0,0 +1,99 @@
package com.glodblock.github.client.gui;
import appeng.api.storage.data.IAEFluidStack;
import appeng.client.gui.AEBaseGui;
import appeng.core.localization.GuiText;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.ContainerLargeIngredientBuffer;
import com.glodblock.github.common.tile.TileLargeIngredientBuffer;
import com.glodblock.github.inventory.IAEFluidTank;
import com.glodblock.github.inventory.gui.ButtonMouseHandler;
import com.glodblock.github.inventory.gui.MouseRegionManager;
import com.glodblock.github.inventory.gui.TankMouseHandler;
import com.glodblock.github.util.NameConst;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
import javax.annotation.Nullable;
public class GuiLargeIngredientBuffer extends AEBaseGui {
private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/large_ingredient_buffer.png");
private static final int TANK_X = 13, TANK_X_OFF = 22, TANK_Y = 18;
private static final int TANK_WIDTH = 16, TANK_HEIGHT = 37;
private final ContainerLargeIngredientBuffer cont;
private final MouseRegionManager mouseRegions = new MouseRegionManager(this);
public GuiLargeIngredientBuffer(InventoryPlayer ipl, TileLargeIngredientBuffer tile) {
super(new ContainerLargeIngredientBuffer(ipl, tile));
this.cont = (ContainerLargeIngredientBuffer) inventorySlots;
this.ySize = 222;
for (int i = 0; i < 7; i++) {
mouseRegions.addRegion(TANK_X + TANK_X_OFF * i, TANK_Y, TANK_WIDTH, TANK_HEIGHT,
new TankMouseHandler(cont.getTile().getFluidInventory(), i));
mouseRegions.addRegion(TANK_X + 10 + 22 * i, TANK_Y + TANK_HEIGHT + 2, 7, 7,
ButtonMouseHandler.dumpTank(cont, i));
}
}
@Override
protected void mouseClicked(int xCoord, int yCoord, int btn) {
if (mouseRegions.onClick(xCoord, yCoord, btn)) {
super.mouseClicked(xCoord, yCoord, btn);
}
}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
mc.getTextureManager().bindTexture(TEX_BG);
drawTexturedModalRect(offsetX, offsetY, 0, 0, 176, ySize);
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
fontRendererObj.drawString(getGuiDisplayName(I18n.format(NameConst.GUI_LARGE_INGREDIENT_BUFFER)), 8, 6, 0x404040);
fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, ySize - 94, 0x404040);
GL11.glColor4f(1F, 1F, 1F, 1F);
IAEFluidTank fluidInv = cont.getTile().getFluidInventory();
mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
for (int i = 0; i < 7; i++) {
renderFluidIntoGui(TANK_X + i * TANK_X_OFF, TANK_Y, TANK_WIDTH, TANK_HEIGHT,
fluidInv.getFluidInSlot(i), fluidInv.getTankInfo(ForgeDirection.UNKNOWN)[i].capacity);
}
GL11.glColor4f(1F, 1F, 1F, 1F);
mouseRegions.render(mouseX, mouseY);
}
public void renderFluidIntoGui(int x, int y, int width, int height,
@Nullable IAEFluidStack aeFluidStack, int capacity) {
if (aeFluidStack != null) {
GL11.glDisable(2896);
GL11.glColor3f(1.0F, 1.0F, 1.0F);
int hi = (int) (height * ((double) aeFluidStack.getStackSize() / capacity));
if (aeFluidStack.getStackSize() > 0 && hi > 0) {
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
IIcon fluidIcon = aeFluidStack.getFluid().getStillIcon();
GL11.glColor3f((float)(aeFluidStack.getFluid().getColor() >> 16 & 255) / 255.0F, (float)(aeFluidStack.getFluid().getColor() >> 8 & 255) / 255.0F, (float)(aeFluidStack.getFluid().getColor() & 255) / 255.0F);
for (int th = 0; th <= hi; th += 16) {
if (hi - th <= 0) break;
this.drawTexturedModelRectFromIcon(x, y + height - Math.min(16, hi - th) - th, fluidIcon, width, Math.min(16, hi - th));
}
GL11.glColor3f(1.0F, 1.0F, 1.0F);
}
}
}
public void update(int slot, IAEFluidStack aeFluidStack) {
cont.getTile().getFluidInventory().setFluidInSlot(slot, aeFluidStack);
}
}
@@ -0,0 +1,67 @@
package com.glodblock.github.client.gui.container;
import appeng.api.storage.data.IAEFluidStack;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotNormal;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.TankDumpable;
import com.glodblock.github.common.tile.TileLargeIngredientBuffer;
import com.glodblock.github.network.SPacketFluidUpdate;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import java.util.HashMap;
import java.util.Map;
public class ContainerLargeIngredientBuffer extends AEBaseContainer implements TankDumpable {
private final TileLargeIngredientBuffer tile;
public ContainerLargeIngredientBuffer(InventoryPlayer ipl, TileLargeIngredientBuffer tile) {
super(ipl, tile);
this.tile = tile;
IInventory inv = tile.getInternalInventory();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++) {
addSlotToContainer(new SlotNormal(inv, i * 9 + j, 8 + 18 * j, 72 + 18 * i));
}
}
bindPlayerInventory(ipl, 0, 140);
}
public TileLargeIngredientBuffer getTile() {
return tile;
}
@Override
public boolean canDumpTank(int index) {
return tile.getFluidInventory().getFluidInSlot(index) != null;
}
@Override
public void dumpTank(int index) {
if (index >= 0 && index < tile.getFluidInventory().getSlots()) {
tile.getFluidInventory().setFluidInSlot(index, null);
}
}
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
Map<Integer, IAEFluidStack> tmp = new HashMap<>();
for (int i = 0; i < tile.getFluidInventory().getSlots(); i ++) {
tmp.put(i, tile.getFluidInventory().getFluidInSlot(i));
}
for( final Object g : this.crafters )
{
if( g instanceof EntityPlayer)
{
FluidCraft.proxy.netHandler.sendTo(new SPacketFluidUpdate(tmp), (EntityPlayerMP) g);
}
}
}
}
@@ -0,0 +1,55 @@
package com.glodblock.github.common.block;
import appeng.block.AEBaseItemBlock;
import com.glodblock.github.common.tile.TileLargeIngredientBuffer;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.util.BlockPos;
import com.glodblock.github.util.NameConst;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
public class BlockLargeIngredientBuffer extends FCBaseBlock {
public BlockLargeIngredientBuffer() {
super(Material.iron, NameConst.BLOCK_LARGE_INGREDIENT_BUFFER);
setTileEntity(TileLargeIngredientBuffer.class);
setOpaque(false);
setFullBlock(false);
this.lightOpacity = 4;
}
@Override
public boolean onActivated(World world, int x, int y, int z, EntityPlayer player, int facing, float hitX, float hitY, float hitZ) {
if (player.isSneaking()) {
return false;
}
TileLargeIngredientBuffer tile = getTileEntity(world, x, y, z);
if (tile != null) {
if (!world.isRemote) {
InventoryHandler.openGui(player, world, new BlockPos(x, y, z), EnumFacing.getFront(facing), GuiType.LARGE_INGREDIENT_BUFFER);
}
return true;
}
return false;
}
public BlockLargeIngredientBuffer register() {
GameRegistry.registerBlock(this, AEBaseItemBlock.class, NameConst.BLOCK_LARGE_INGREDIENT_BUFFER);
GameRegistry.registerTileEntity(TileLargeIngredientBuffer.class, NameConst.BLOCK_LARGE_INGREDIENT_BUFFER);
return this;
}
public ItemStack stack(int size) {
return new ItemStack(this, size);
}
public ItemStack stack() {
return new ItemStack(this, 1);
}
}
@@ -0,0 +1,154 @@
package com.glodblock.github.common.tile;
import appeng.api.storage.data.IAEFluidStack;
import appeng.tile.AEBaseInvTile;
import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.item.AEFluidStack;
import com.glodblock.github.inventory.AEFluidInventory;
import com.glodblock.github.inventory.IAEFluidInventory;
import com.glodblock.github.inventory.IAEFluidTank;
import cpw.mods.fml.common.network.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import javax.annotation.Nonnull;
import java.io.IOException;
public class TileLargeIngredientBuffer extends AEBaseInvTile implements IAEFluidInventory, IFluidHandler {
private final AppEngInternalInventory invItems = new AppEngInternalInventory(this, 27);
private final AEFluidInventory invFluids = new AEFluidInventory(this, 7, 64000);
@Nonnull
@Override
public IInventory getInternalInventory() {
return invItems;
}
public IAEFluidTank getFluidInventory() {
return invFluids;
}
@Override
public boolean canBeRotated() {
return false;
}
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added) {
markForUpdate();
}
@Override
public int[] getAccessibleSlotsBySide(ForgeDirection whichSide) {
return new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26};
}
@Override
public void onFluidInventoryChanged(IAEFluidTank inv, int slot) {
saveChanges();
markForUpdate();
}
@TileEvent(TileEventType.NETWORK_WRITE)
protected void writeToStream(ByteBuf data) throws IOException {
for (int i = 0; i < invItems.getSizeInventory(); i++) {
ByteBufUtils.writeItemStack(data, invItems.getStackInSlot(i));
}
int fluidMask = 0;
for (int i = 0; i < invFluids.getSlots(); i++) {
if (invFluids.getFluidInSlot(i) != null) {
fluidMask |= 1 << i;
}
}
data.writeByte(fluidMask);
for (int i = 0; i < invFluids.getSlots(); i++) {
IAEFluidStack fluid = invFluids.getFluidInSlot(i);
if (fluid != null) {
fluid.writeToPacket(data);
}
}
}
@TileEvent(TileEventType.NETWORK_READ)
protected boolean readFromStream(ByteBuf data) throws IOException {
boolean changed = false;
for (int i = 0; i < invItems.getSizeInventory(); i++) {
ItemStack stack = ByteBufUtils.readItemStack(data);
if (!ItemStack.areItemStacksEqual(stack, invItems.getStackInSlot(i))) {
invItems.setInventorySlotContents(i, stack);
changed = true;
}
}
int fluidMask = data.readByte();
for (int i = 0; i < invFluids.getSlots(); i++) {
if ((fluidMask & (1 << i)) != 0) {
IAEFluidStack fluid = AEFluidStack.loadFluidStackFromPacket(data);
if (fluid != null) { // this shouldn't happen, but better safe than sorry
IAEFluidStack origFluid = invFluids.getFluidInSlot(i);
if (!fluid.equals(origFluid) || fluid.getStackSize() != origFluid.getStackSize()) {
invFluids.setFluidInSlot(i, fluid);
changed = true;
}
}
} else if (invFluids.getFluidInSlot(i) != null) {
invFluids.setFluidInSlot(i, null);
changed = true;
}
}
return changed;
}
@TileEvent(TileEventType.WORLD_NBT_READ)
public void readFromNBTEvent(NBTTagCompound data) {
invItems.readFromNBT(data, "ItemInv");
invFluids.readFromNBT(data, "FluidInv");
}
@TileEvent(TileEventType.WORLD_NBT_WRITE)
public NBTTagCompound writeToNBTEvent(NBTTagCompound data) {
invItems.writeToNBT(data, "ItemInv");
invFluids.writeToNBT(data, "FluidInv");
return data;
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
return invFluids.fill(from, resource, doFill);
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
return invFluids.drain(from, resource, doDrain);
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
return invFluids.drain(from, maxDrain, doDrain);
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid) {
return invFluids.canFill(from, fluid);
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid) {
return invFluids.canDrain(from, fluid);
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
return invFluids.getTankInfo(from);
}
}
@@ -128,6 +128,18 @@ public enum GuiType {
}
}),
LARGE_INGREDIENT_BUFFER(new TileGuiFactory<TileLargeIngredientBuffer>(TileLargeIngredientBuffer.class) {
@Override
protected Object createServerGui(EntityPlayer player, TileLargeIngredientBuffer inv) {
return new ContainerLargeIngredientBuffer(player.inventory, inv);
}
@Override
protected Object createClientGui(EntityPlayer player, TileLargeIngredientBuffer inv) {
return new GuiLargeIngredientBuffer(player.inventory, inv);
}
}),
FLUID_PAT_TERM_CRAFTING_STATUS(new PartGuiFactory<FCBasePart>(FCBasePart.class) {
@Override
protected Object createServerGui(EntityPlayer player, FCBasePart inv) {
@@ -29,6 +29,7 @@ public class ItemAndBlockHolder {
public static BlockFluidPacketDecoder DECODER = new BlockFluidPacketDecoder().register();
public static BlockFluidInterface INTERFACE = new BlockFluidInterface().register();
public static BlockIngredientBuffer BUFFER = new BlockIngredientBuffer().register();
public static BlockLargeIngredientBuffer LARGE_BUFFER = new BlockLargeIngredientBuffer().register();
public static BlockOCPatternEditor OC_EDITOR = new BlockOCPatternEditor().register();
public static void loadSetting() {
@@ -48,6 +48,7 @@ public class RecipeLoader implements Runnable {
GameRegistry.addShapelessRecipe(FLUID_TERMINAL.stack(), AE2_PATTERN_TERM, ENCODER);
GameRegistry.addShapelessRecipe(FLUID_TERMINAL_EX.stack(), FLUID_TERMINAL.stack(), AE2_PROCESS_CAL, AE2_PROCESS_ENG, AE2_PROCESS_LOG);
GameRegistry.addRecipe(new ShapedOreRecipe(BUFFER.stack(), "ILI", "AGF", "IBI", 'I', "ingotIron", 'G', AE2_QUARTZ_GLASS, 'L', AE2_CELL_1K, 'A', AE2_CORE_ANN, 'F', AE2_CORE_FOM, 'B', BUCKET));
GameRegistry.addRecipe(new ShapedOreRecipe(LARGE_BUFFER.stack(), "BGB", "GEG", "BGB", 'B', BUFFER.stack(), 'G', AE2_QUARTZ_GLASS, 'E', AE2_PROCESS_ENG));
if (Config.fluidCells) {
OreDictionary.registerOre("anyCertusCrystal", AE2_PURE_CERTUS);
@@ -5,6 +5,7 @@ import appeng.util.item.AEFluidStack;
import com.glodblock.github.client.gui.GuiFluidIO;
import com.glodblock.github.client.gui.GuiFluidInterface;
import com.glodblock.github.client.gui.GuiIngredientBuffer;
import com.glodblock.github.client.gui.GuiLargeIngredientBuffer;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
@@ -75,6 +76,10 @@ public class SPacketFluidUpdate implements IMessage {
for (Map.Entry<Integer, IAEFluidStack> e : message.list.entrySet() ) {
( (GuiIngredientBuffer) gs ).update(e.getKey(), e.getValue());
}
} else if (gs instanceof GuiLargeIngredientBuffer) {
for (Map.Entry<Integer, IAEFluidStack> e : message.list.entrySet() ) {
( (GuiLargeIngredientBuffer) gs ).update(e.getKey(), e.getValue());
}
} else if( gs instanceof GuiFluidIO)
{
for (Map.Entry<Integer, IAEFluidStack> e : message.list.entrySet() ) {
@@ -9,6 +9,7 @@ public class NameConst {
public static final String BLOCK_FLUID_PACKET_DECODER = "fluid_packet_decoder";
public static final String BLOCK_FLUID_INTERFACE = "fluid_interface";
public static final String BLOCK_INGREDIENT_BUFFER = "ingredient_buffer";
public static final String BLOCK_LARGE_INGREDIENT_BUFFER = "large_ingredient_buffer";
public static final String BLOCK_OC_PATTERN_EDITOR = "oc_pattern_editor";
public static final String ITEM_FLUID_DROP = "fluid_drop";
@@ -37,6 +38,7 @@ public class NameConst {
public static final String GUI_FLUID_PATTERN_ENCODER = GUI_KEY + BLOCK_FLUID_PATTERN_ENCODER;
public static final String GUI_FLUID_PACKET_DECODER = GUI_KEY + BLOCK_FLUID_PACKET_DECODER;
public static final String GUI_INGREDIENT_BUFFER = GUI_KEY + BLOCK_INGREDIENT_BUFFER;
public static final String GUI_LARGE_INGREDIENT_BUFFER = GUI_KEY + BLOCK_LARGE_INGREDIENT_BUFFER;
public static final String GUI_FLUID_INTERFACE = GUI_KEY + BLOCK_FLUID_INTERFACE;
public static final String GUI_OC_PATTERN_EDITOR = GUI_KEY + BLOCK_OC_PATTERN_EDITOR;
@@ -26,6 +26,7 @@ tile.fluid_pattern_encoder.name=Fluid Pattern Encoder
tile.fluid_packet_decoder.name=ME Fluid Packet Decoder
tile.fluid_interface.name=ME Dual Interface
tile.ingredient_buffer.name=Ingredient Buffer
tile.large_ingredient_buffer.name=Large Ingredient Buffer
tile.oc_pattern_editor.name=OC Pattern Editor
ae2fc.tooltip.invalid_fluid=Invalid fluid!
@@ -40,6 +41,7 @@ ae2fc.gui.part_fluid_pattern_terminal_ex=Fluid Processing Pattern Terminal
ae2fc.gui.fluid_pattern_encoder=Fluid Pattern Encoder
ae2fc.gui.fluid_packet_decoder=ME Fluid Packet Decoder
ae2fc.gui.ingredient_buffer=Ingredient Buffer
ae2fc.gui.large_ingredient_buffer=Large Ingredient Buffer
ae2fc.gui.fluid_interface=ME Dual Interface
ae2fc.gui.fluid_interface.0=D
ae2fc.gui.fluid_interface.1=U
Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB