a little gift for future me

This commit is contained in:
Boblet 2025-06-04 16:11:38 +02:00
parent 0c9bea7091
commit 25e20662e4
9 changed files with 326 additions and 38 deletions

View File

@ -4,12 +4,16 @@ import org.lwjgl.opengl.GL11;
import com.hbm.inventory.container.ContainerMachineChemicalPlant;
import com.hbm.inventory.recipes.ChemicalPlantRecipes;
import com.hbm.inventory.recipes.loader.GenericRecipe;
import com.hbm.lib.RefStrings;
import com.hbm.tileentity.machine.TileEntityMachineChemicalPlant;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
public class GUIMachineChemicalPlant extends GuiInfoContainer {
@ -35,6 +39,15 @@ public class GUIMachineChemicalPlant extends GuiInfoContainer {
}
this.drawElectricityInfo(this, mouseX, mouseY, guiLeft + 152, guiTop + 18, 16, 61, chemplant.power, chemplant.maxPower);
if(guiLeft + 7 <= mouseX && guiLeft + 7 + 18 > mouseX && guiTop + 125 < mouseY && guiTop + 125 + 18 >= mouseY) {
if(this.chemplant.chemplantModule.recipe != null && ChemicalPlantRecipes.INSTANCE.recipeNameMap.containsKey(this.chemplant.chemplantModule.recipe)) {
GenericRecipe recipe = (GenericRecipe) ChemicalPlantRecipes.INSTANCE.recipeNameMap.get(this.chemplant.chemplantModule.recipe);
this.func_146283_a(recipe.print(), mouseX, mouseY);
} else {
this.drawCreativeTabHoveringText(EnumChatFormatting.YELLOW + "Click to set recipe", mouseX, mouseY);
}
}
}
@Override
@ -61,11 +74,34 @@ public class GUIMachineChemicalPlant extends GuiInfoContainer {
int p = (int) (chemplant.power * 61 / chemplant.maxPower);
drawTexturedModalRect(guiLeft + 152, guiTop + 79 - p, 176, 61 - p, 16, p);
if(chemplant.maxProgress > 0) {
int j = chemplant.progress * 70 / chemplant.maxProgress;
if(chemplant.chemplantModule.progress > 0) {
int j = (int) Math.ceil(70 * chemplant.chemplantModule.progress);
drawTexturedModalRect(guiLeft + 62, guiTop + 126, 176, 61, j, 16);
}
GenericRecipe recipe = ChemicalPlantRecipes.INSTANCE.recipeNameMap.get(chemplant.chemplantModule.recipe);
this.renderItem(recipe != null ? recipe.getIcon() : TEMPLATE_FOLDER, 8, 126);
if(recipe != null && recipe.inputItem != null) {
for(int i = 0; i < recipe.inputItem.length; i++) {
Slot slot = (Slot) this.inventorySlots.inventorySlots.get(chemplant.chemplantModule.inputSlots[i]);
if(!slot.getHasStack()) this.renderItem(recipe.inputItem[i].extractForCyclingDisplay(20), slot.xDisplayPosition, slot.yDisplayPosition, 10F);
}
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
GL11.glColor4f(1F, 1F, 1F, 0.5F);
GL11.glEnable(GL11.GL_BLEND);
this.zLevel = 300F;
for(int i = 0; i < recipe.inputItem.length; i++) {
Slot slot = (Slot) this.inventorySlots.inventorySlots.get(chemplant.chemplantModule.inputSlots[i]);
if(!slot.getHasStack()) drawTexturedModalRect(guiLeft + slot.xDisplayPosition, guiTop + slot.yDisplayPosition, slot.xDisplayPosition, slot.yDisplayPosition, 16, 16);
}
this.zLevel = 0F;
GL11.glColor4f(1F, 1F, 1F, 1F);
GL11.glDisable(GL11.GL_BLEND);
}
for(int i = 0; i < 3; i++) {
chemplant.inputTanks[i].renderTank(guiLeft + 8, guiTop + 52, this.zLevel, 16, 34);
chemplant.outputTanks[i].renderTank(guiLeft + 80, guiTop + 52, this.zLevel, 16, 34);

View File

@ -12,13 +12,20 @@ import com.hbm.interfaces.IControlReceiver;
import com.hbm.inventory.recipes.loader.GenericRecipe;
import com.hbm.inventory.recipes.loader.GenericRecipes;
import com.hbm.lib.RefStrings;
import com.hbm.packet.PacketDispatcher;
import com.hbm.packet.toserver.NBTControlPacket;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
public class GUIScreenRecipeSelector extends GuiScreen {
@ -37,6 +44,7 @@ public class GUIScreenRecipeSelector extends GuiScreen {
protected int pageIndex;
protected int size;
protected String selection;
public static final String NULL_SELECTION = "null";
// callback
protected int index;
protected IControlReceiver tile;
@ -52,6 +60,7 @@ public class GUIScreenRecipeSelector extends GuiScreen {
this.selection = selection;
this.index = index;
this.previousScreen = previousScreen;
if(this.selection == null) this.selection = NULL_SELECTION;
regenerateRecipes();
}
@ -106,6 +115,40 @@ public class GUIScreenRecipeSelector extends GuiScreen {
this.drawGuiContainerForegroundLayer(mouseX, mouseY);
GL11.glEnable(GL11.GL_LIGHTING);
this.handleScroll();
if(guiLeft + 7 <= mouseX && guiLeft + 7 + 144 > mouseX && guiTop + 17 < mouseY && guiTop + 17 + 90 >= mouseY) {
for(int i = pageIndex * 8; i < pageIndex * 8 + 40; i++) {
if(i >= this.recipes.size()) break;
int ind = i - pageIndex * 8;
int ix = 7 + 18 * (ind % 8);
int iy = 17 + 18 * (ind / 8);
if(guiLeft + ix <= mouseX && guiLeft + ix + 18 > mouseX && guiTop + iy < mouseY && guiTop + iy + 18 >= mouseY) {
GenericRecipe recipe = recipes.get(i);
this.func_146283_a(recipe.print(), mouseX, mouseY);
}
}
}
if(guiLeft + 151 <= mouseX && guiLeft + 151 + 18 > mouseX && guiTop + 71 < mouseY && guiTop + 71 + 18 >= mouseY) {
if(this.selection != null && this.recipeSet.recipeNameMap.containsKey(selection)) {
GenericRecipe recipe = (GenericRecipe) this.recipeSet.recipeNameMap.get(selection);
this.func_146283_a(recipe.print(), mouseX, mouseY);
}
}
if(guiLeft + 152 <= mouseX && guiLeft + 152 + 16 > mouseX && guiTop + 90 < mouseY && guiTop + 90 + 16 >= mouseY) {
this.drawCreativeTabHoveringText(EnumChatFormatting.YELLOW + "Close", mouseX, mouseY);
}
if(guiLeft + 134 <= mouseX && guiLeft + 134 + 16 > mouseX && guiTop + 108 < mouseY && guiTop + 108 + 16 >= mouseY) {
this.drawCreativeTabHoveringText(EnumChatFormatting.YELLOW + "Clear search", mouseX, mouseY);
}
if(guiLeft + 8 <= mouseX && guiLeft + 8 + 16 > mouseX && guiTop + 108 < mouseY && guiTop + 108 + 16 >= mouseY) {
this.drawCreativeTabHoveringText(EnumChatFormatting.ITALIC + "Press ENTER to toggle focus", mouseX, mouseY);
}
}
protected void handleScroll() {
@ -118,7 +161,7 @@ public class GUIScreenRecipeSelector extends GuiScreen {
}
private void drawGuiContainerForegroundLayer(int x, int y) {
this.search.drawTextBox();
}
private void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {
@ -126,38 +169,148 @@ public class GUIScreenRecipeSelector extends GuiScreen {
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
if(this.search.isFocused()) {
drawTexturedModalRect(guiLeft + 26, guiTop + 108, 0, 132, 106, 16);
}
if(guiLeft + 152 <= mouseX && guiLeft + 152 + 16 > mouseX && guiTop + 18 < mouseY && guiTop + 18 + 16 >= mouseY) {
drawTexturedModalRect(guiLeft + 152, guiTop + 18, 176, 0, 16, 16);
}
if(guiLeft + 152 <= mouseX && guiLeft + 152 + 16 > mouseX && guiTop + 36 < mouseY && guiTop + 36 + 16 >= mouseY) {
drawTexturedModalRect(guiLeft + 152, guiTop + 36, 176, 16, 16, 16);
}
if(guiLeft + 152 <= mouseX && guiLeft + 152 + 16 > mouseX && guiTop + 90 < mouseY && guiTop + 90 + 16 >= mouseY) {
drawTexturedModalRect(guiLeft + 152, guiTop + 90, 176, 32, 16, 16);
}
if(guiLeft + 134 <= mouseX && guiLeft + 134 + 16 > mouseX && guiTop + 108 < mouseY && guiTop + 108 + 16 >= mouseY) {
drawTexturedModalRect(guiLeft + 134, guiTop + 108, 176, 48, 16, 16);
}
if(guiLeft + 8 <= mouseX && guiLeft + 8 + 16 > mouseX && guiTop + 108 < mouseY && guiTop + 108 + 16 >= mouseY) {
drawTexturedModalRect(guiLeft + 8, guiTop + 108, 176, 64, 16, 16);
}
for(int i = pageIndex * 8; i < pageIndex * 8 + 40; i++) {
if(i >= recipes.size()) break;
int ind = i - pageIndex * 8;
GenericRecipe recipe = recipes.get(i);
if(recipe.getInternalName().equals(this.selection)) this.drawTexturedModalRect(guiLeft + 7 + 18 * (ind % 8), guiTop + 17 + 18 * (ind / 8), 192, 0, 18, 18);
}
for(int i = pageIndex * 8; i < pageIndex * 8 + 40; i++) {
if(i >= recipes.size()) break;
int ind = i - pageIndex * 8;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
RenderHelper.enableGUIStandardItemLighting();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GenericRecipe recipe = recipes.get(i);
FontRenderer font = recipe.getIcon().getItem().getFontRenderer(recipe.getIcon());
if(font == null) font = fontRendererObj;
itemRender.zLevel = 100.0F;
itemRender.renderItemAndEffectIntoGUI(font, this.mc.getTextureManager(), recipe.getIcon(), guiLeft + 8 + 18 * (ind % 8), guiTop + 18 + 18 * (ind / 8));
itemRender.zLevel = 0.0F;
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glDisable(GL11.GL_LIGHTING);
this.renderItem(recipe.getIcon(), 8 + 18 * (ind % 8), 18 + 18 * (ind / 8));
this.mc.getTextureManager().bindTexture(texture);
}
if(recipe.name.equals(this.selection))
this.drawTexturedModalRect(guiLeft + 7 + 18 * (ind % 8), guiTop + 17 + 18 * (ind / 8), 192, 0, 18, 18);
if(this.selection != null && this.recipeSet.recipeNameMap.containsKey(selection)) {
GenericRecipe recipe = (GenericRecipe) this.recipeSet.recipeNameMap.get(selection);
this.renderItem(recipe.getIcon(), 152, 72);
}
}
public void renderItem(ItemStack stack, int x, int y) {
FontRenderer font = stack.getItem().getFontRenderer(stack);
if(font == null) font = fontRendererObj;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
RenderHelper.enableGUIStandardItemLighting();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
itemRender.zLevel = 100.0F;
itemRender.renderItemAndEffectIntoGUI(font, this.mc.getTextureManager(), stack, guiLeft + x, guiTop + y);
itemRender.zLevel = 0.0F;
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glDisable(GL11.GL_LIGHTING);
}
@Override
protected void mouseClicked(int x, int y, int k) {
super.mouseClicked(x, y, k);
this.search.mouseClicked(x, y, k);
if(guiLeft + 152 <= x && guiLeft + 152 + 16 > x && guiTop + 18 < y && guiTop + 18 + 16 >= y) {
click();
if(this.pageIndex > 0) this.pageIndex--;
return;
}
if(guiLeft + 152 <= x && guiLeft + 152 + 16 > x && guiTop + 36 < y && guiTop + 36 + 16 >= y) {
click();
if(this.pageIndex < this.size) this.pageIndex++;
return;
}
if(guiLeft + 134 <= x && guiLeft + 134 + 16 > x && guiTop + 108 < y && guiTop + 108 + 16 >= y) {
this.search.setText("");
this.search("");
this.search.setFocused(true);
return;
}
for(int i = pageIndex * 8; i < pageIndex * 8 + 40; i++) {
if(i >= this.recipes.size()) break;
int ind = i - pageIndex * 8;
int ix = 7 + 18 * (ind % 8);
int iy = 17 + 18 * (ind / 8);
if(guiLeft + ix <= x && guiLeft + ix + 18 > x && guiTop + iy < y && guiTop + iy + 18 >= y) {
String newSelection = ((GenericRecipe) recipes.get(i)).getInternalName();
if(!newSelection.equals(selection))
this.selection = newSelection;
else
this.selection = NULL_SELECTION;
NBTTagCompound data = new NBTTagCompound();
data.setInteger("index", this.index);
data.setString("selection", this.selection);
TileEntity te = (TileEntity) tile;
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, te.xCoord, te.yCoord, te.zCoord));
click();
return;
}
}
if(guiLeft + 151 <= x && guiLeft + 151 + 18 > x && guiTop + 71 < y && guiTop + 71 + 18 >= y) {
if(!NULL_SELECTION.equals(this.selection)) {
this.selection = this.NULL_SELECTION;
NBTTagCompound data = new NBTTagCompound();
data.setInteger("index", this.index);
data.setString("selection", this.selection);
TileEntity te = (TileEntity) tile;
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, te.xCoord, te.yCoord, te.zCoord));
click();
return;
}
}
if(guiLeft + 152 <= x && guiLeft + 152 + 16 > x && guiTop + 90 < y && guiTop + 90 + 16 >= y) {
FMLCommonHandler.instance().showGuiScreen(previousScreen);
}
}
@Override
protected void keyTyped(char typedChar, int keyCode) {
if(keyCode == Keyboard.KEY_RETURN) {
this.search.setFocused(!this.search.isFocused());
return;
}
if(this.search.textboxKeyTyped(typedChar, keyCode)) {
search(this.search.getText());
return;
@ -168,10 +321,8 @@ public class GUIScreenRecipeSelector extends GuiScreen {
}
}
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
}
@Override public void onGuiClosed() { Keyboard.enableRepeatEvents(false); }
@Override public boolean doesGuiPauseGame() { return false; }
public void click() { mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); }
}

View File

@ -15,6 +15,7 @@ import net.minecraft.nbt.NBTTagCompound;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import com.hbm.items.ModItems;
import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType;
import com.hbm.lib.RefStrings;
import com.hbm.tileentity.IUpgradeInfoProvider;
@ -161,7 +162,7 @@ public abstract class GuiInfoContainer extends GuiContainer implements INEIGuiHa
return this.fontRendererObj;
}
/** Draws item with label, excludes all the GL state setup */
protected void drawItemStack(ItemStack stack, int x, int y, String label) {
GL11.glTranslatef(0.0F, 0.0F, 32.0F);
this.zLevel = 200.0F;
@ -175,6 +176,27 @@ public abstract class GuiInfoContainer extends GuiContainer implements INEIGuiHa
itemRender.zLevel = 0.0F;
}
public static final ItemStack TEMPLATE_FOLDER = new ItemStack(ModItems.template_folder);
/** Standardsized item rendering from GUIScreenRecipeSelector */
public void renderItem(ItemStack stack, int x, int y) {
renderItem(stack, x, y, 100F);
}
public void renderItem(ItemStack stack, int x, int y, float layer) {
FontRenderer font = stack.getItem().getFontRenderer(stack);
if(font == null) font = fontRendererObj;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
RenderHelper.enableGUIStandardItemLighting();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
itemRender.zLevel = layer;
itemRender.renderItemAndEffectIntoGUI(font, this.mc.getTextureManager(), stack, guiLeft + x, guiTop + y);
itemRender.zLevel = 0.0F;
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glDisable(GL11.GL_LIGHTING);
}
protected void drawStackText(List lines, int x, int y, FontRenderer font) {
if(!lines.isEmpty()) {

View File

@ -1,5 +1,7 @@
package com.hbm.inventory.recipes.loader;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import com.hbm.inventory.FluidStack;
@ -13,10 +15,11 @@ import com.hbm.util.i18n.I18nUtil;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
public class GenericRecipe {
public String name;
protected final String name;
public AStack[] inputItem;
public FluidStack[] inputFluid;
public IOutput[] outputItem;
@ -62,12 +65,31 @@ public class GenericRecipe {
return icon;
}
public String getName() {
public String getInternalName() {
return this.name;
}
public String getLocalizedName() {
if(customLocalization) return I18nUtil.resolveKey(name);
return this.getIcon().getDisplayName();
}
public List<String> print() {
List<String> list = new ArrayList();
list.add(EnumChatFormatting.YELLOW + this.getLocalizedName());
list.add(EnumChatFormatting.BOLD + "Input:");
if(inputItem != null) for(AStack stack : inputItem) {
ItemStack display = stack.extractForCyclingDisplay(20);
list.add(" " + EnumChatFormatting.GRAY + display.stackSize + "x " + display.getDisplayName());
}
if(inputFluid != null) for(FluidStack fluid : inputFluid) list.add(" " + EnumChatFormatting.BLUE + fluid.fill + "mB " + fluid.type.getLocalizedName() + (fluid.pressure == 0 ? "" : "at " + EnumChatFormatting.RED + fluid.pressure + " PU"));
list.add(EnumChatFormatting.BOLD + "Output:");
if(outputItem != null) for(IOutput output : outputItem) for(String line : output.getLabel()) list.add(" " + line);
if(outputFluid != null) for(FluidStack fluid : outputFluid) list.add(" " + EnumChatFormatting.BLUE + fluid.fill + "mB " + fluid.type.getLocalizedName() + (fluid.pressure == 0 ? "" : "at " + EnumChatFormatting.RED + fluid.pressure + " PU"));
return list;
}
public boolean matchesSearch(String substring) {
return getName().toLowerCase(Locale.US).contains(substring.toLowerCase(Locale.US));
return getLocalizedName().toLowerCase(Locale.US).contains(substring.toLowerCase(Locale.US));
}
}

View File

@ -14,6 +14,7 @@ import com.hbm.inventory.FluidStack;
import com.hbm.inventory.RecipesCommon.AStack;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.WeightedRandom;
/**
@ -157,6 +158,7 @@ public abstract class GenericRecipes<T extends GenericRecipe> extends Serializab
public ItemStack collapse();
public void serialize(JsonWriter writer) throws IOException;
public void deserialize(JsonArray array);
public String[] getLabel();
}
/** A chance output, produces either an ItemStack or null */
@ -216,6 +218,11 @@ public abstract class GenericRecipes<T extends GenericRecipe> extends Serializab
if(array.size() > 2) this.itemWeight = array.get(2).getAsInt();
}
}
@Override
public String[] getLabel() {
return new String[] {EnumChatFormatting.GRAY + "" + this.stack.stackSize + "x " + this.stack.getDisplayName() + (this.chance >= 1 ? "" : " (" + (int)(this.chance * 1000) / 10F + "%)")};
}
}
/** Multiple choice chance output, produces a ChanceOutput chosen randomly by weight */
@ -242,5 +249,18 @@ public abstract class GenericRecipes<T extends GenericRecipe> extends Serializab
pool.add(output);
}
}
@Override
public String[] getLabel() {
String[] label = new String[pool.size() + 1];
label[0] = "One of:";
int totalWeight = WeightedRandom.getTotalWeight(pool);
for(int i = 1; i < label.length; i++) {
ChanceOutput output = pool.get(i - 1);
float chance = (float) output.itemWeight / (float) totalWeight * output.chance;
label[i] = " " + EnumChatFormatting.GRAY + output.stack.stackSize + "x " + output.stack.getDisplayName() + " (" + (int)(chance * 1000F) / 10F + "%)";
}
return label;
}
}
}

View File

@ -5,6 +5,8 @@ import com.hbm.inventory.recipes.ChemicalPlantRecipes;
import com.hbm.inventory.recipes.loader.GenericRecipe;
import api.hbm.energymk2.IEnergyHandlerMK2;
import cpw.mods.fml.common.network.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;
/**
@ -23,7 +25,7 @@ public class ModuleMachineChemplant {
public FluidTank[] inputTanks = new FluidTank[3];
public FluidTank[] outputTanks = new FluidTank[3];
public String recipe;
public String recipe = "null";
public float progress;
public ModuleMachineChemplant(int index, IEnergyHandlerMK2 battery, ItemStack[] slots) {
@ -45,11 +47,33 @@ public class ModuleMachineChemplant {
public void resetProgress() { this.progress = 0F; }
public void update() {
//TBI
}
public boolean isItemValid(int slot, ItemStack stack) {
GenericRecipe recipe = ChemicalPlantRecipes.INSTANCE.recipeNameMap.get(this.recipe);
if(recipe == null) return false;
if(recipe.inputItem == null) return false;
for(int i = 0; i < Math.min(inputSlots.length, recipe.inputItem.length); i++) {
if(recipe.inputItem[i].matchesRecipe(stack, true)) return true;
}
return false;
}
public ModuleMachineChemplant iInput(int a, int b, int c) { inputSlots[0] = a; inputSlots[1] = b; inputSlots[2] = c; return this; }
public ModuleMachineChemplant iOutput(int a, int b, int c) { outputSlots[0] = a; outputSlots[1] = b; outputSlots[2] = c; return this; }
public ModuleMachineChemplant fInput(FluidTank a, FluidTank b, FluidTank c) { inputTanks[0] = a; inputTanks[1] = b; inputTanks[2] = c; return this; }
public ModuleMachineChemplant fOutput(FluidTank a, FluidTank b, FluidTank c) { outputTanks[0] = a; outputTanks[1] = b; outputTanks[2] = c; return this; }
public void serialize(ByteBuf buf) {
buf.writeFloat(progress);
ByteBufUtils.writeUTF8String(buf, recipe);
}
public void deserialize(ByteBuf buf) {
this.progress = buf.readFloat();
this.recipe = ByteBufUtils.readUTF8String(buf);
}
}

View File

@ -10,6 +10,7 @@ import com.hbm.inventory.container.ContainerMachineChemicalPlant;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank;
import com.hbm.inventory.gui.GUIMachineChemicalPlant;
import com.hbm.items.machine.ItemMachineUpgrade;
import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType;
import com.hbm.lib.Library;
import com.hbm.module.ModuleMachineChemplant;
@ -26,6 +27,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.EnumChatFormatting;
@ -38,8 +40,6 @@ public class TileEntityMachineChemicalPlant extends TileEntityMachineBase implem
public long power;
public long maxPower = 1_000_000;
public int progress;
public int maxProgress;
public ModuleMachineChemplant chemplantModule;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT(this);
@ -85,8 +85,7 @@ public class TileEntityMachineChemicalPlant extends TileEntityMachineBase implem
for(FluidTank tank : outputTanks) tank.serialize(buf);
buf.writeLong(power);
buf.writeLong(maxPower);
buf.writeInt(progress);
buf.writeInt(maxProgress);
this.chemplantModule.serialize(buf);
}
@Override
@ -96,8 +95,7 @@ public class TileEntityMachineChemicalPlant extends TileEntityMachineBase implem
for(FluidTank tank : outputTanks) tank.deserialize(buf);
this.power = buf.readLong();
this.maxPower = buf.readLong();
this.progress = buf.readInt();
this.maxProgress = buf.readInt();
this.chemplantModule.deserialize(buf);
}
@Override
@ -122,6 +120,16 @@ public class TileEntityMachineChemicalPlant extends TileEntityMachineBase implem
}
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
if(slot == 0) return true; // battery
if(slot >= 2 && slot <= 3 && stack.getItem() instanceof ItemMachineUpgrade) return true; // upgades
if(slot >= 10 && slot <= 12) return true; // input fluid
if(slot >= 16 && slot <= 18) return true; // output fluid
if(this.chemplantModule.isItemValid(slot, stack)) return true; // recipe input crap
return false;
}
@Override public long getPower() { return power; }
@Override public void setPower(long power) { this.power = power; }
@Override public long getMaxPower() { return maxPower; }
@ -137,7 +145,12 @@ public class TileEntityMachineChemicalPlant extends TileEntityMachineBase implem
@Override
public void receiveControl(NBTTagCompound data) {
if(data.hasKey("index") && data.hasKey("selection")) {
int index = data.getInteger("index");
String selection = data.getString("selection");
if(index == 0) this.chemplantModule.recipe = selection;
this.markChanged();
}
}
AxisAlignedBB bb = null;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB