diff --git a/src/main/java/com/hbm/inventory/container/ContainerPADetector.java b/src/main/java/com/hbm/inventory/container/ContainerPADetector.java new file mode 100644 index 000000000..08e8f9e81 --- /dev/null +++ b/src/main/java/com/hbm/inventory/container/ContainerPADetector.java @@ -0,0 +1,77 @@ +package com.hbm.inventory.container; + +import com.hbm.inventory.SlotTakeOnly; +import com.hbm.items.ModItems; +import com.hbm.tileentity.machine.albion.TileEntityPADetector; + +import api.hbm.energymk2.IBatteryItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class ContainerPADetector extends Container { + + private TileEntityPADetector detector; + + public ContainerPADetector(InventoryPlayer playerInv, TileEntityPADetector tile) { + detector = tile; + + //Battery + this.addSlotToContainer(new Slot(tile, 0, 8, 72)); + //Containers + this.addSlotToContainer(new Slot(tile, 1, 62, 18)); + this.addSlotToContainer(new Slot(tile, 2, 80, 18)); + //Outputs + this.addSlotToContainer(new SlotTakeOnly(tile, 3, 62, 45)); + this.addSlotToContainer(new SlotTakeOnly(tile, 4, 80, 45)); + + for(int i = 0; i < 3; i++) { + for(int j = 0; j < 9; j++) { + this.addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 122 + i * 18)); + } + } + + for(int i = 0; i < 9; i++) { + this.addSlotToContainer(new Slot(playerInv, i, 8 + i * 18, 180)); + } + } + + @Override + public boolean canInteractWith(EntityPlayer player) { + return detector.isUseableByPlayer(player); + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int index) { + ItemStack rStack = null; + Slot slot = (Slot) this.inventorySlots.get(index); + + if(slot != null && slot.getHasStack()) { + ItemStack stack = slot.getStack(); + rStack = stack.copy(); + + if(index <= 5) { + if(!this.mergeItemStack(stack, 6, this.inventorySlots.size(), true)) { + return null; + } + } else { + + if(rStack.getItem() instanceof IBatteryItem || rStack.getItem() == ModItems.battery_creative) { + if(!this.mergeItemStack(stack, 0, 1, false)) return null; + } else { + if(!this.mergeItemStack(stack, 1, 3, false)) return null; + } + } + + if(stack.stackSize == 0) { + slot.putStack((ItemStack) null); + } else { + slot.onSlotChanged(); + } + } + + return rStack; + } +} diff --git a/src/main/java/com/hbm/inventory/container/ContainerPASource.java b/src/main/java/com/hbm/inventory/container/ContainerPASource.java index 90e01d5c4..4b30637f5 100644 --- a/src/main/java/com/hbm/inventory/container/ContainerPASource.java +++ b/src/main/java/com/hbm/inventory/container/ContainerPASource.java @@ -20,7 +20,7 @@ public class ContainerPASource extends Container { //Battery this.addSlotToContainer(new Slot(tile, 0, 8, 72)); - //Inouts + //Inputs this.addSlotToContainer(new Slot(tile, 1, 62, 18)); this.addSlotToContainer(new Slot(tile, 2, 80, 18)); //Containers diff --git a/src/main/java/com/hbm/inventory/gui/GUIPADetector.java b/src/main/java/com/hbm/inventory/gui/GUIPADetector.java new file mode 100644 index 000000000..f426dfad0 --- /dev/null +++ b/src/main/java/com/hbm/inventory/gui/GUIPADetector.java @@ -0,0 +1,65 @@ +package com.hbm.inventory.gui; + +import org.lwjgl.opengl.GL11; + +import com.hbm.inventory.container.ContainerPADetector; +import com.hbm.lib.RefStrings; +import com.hbm.tileentity.machine.albion.TileEntityPADetector; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.ResourceLocation; + +public class GUIPADetector extends GuiInfoContainer { + + private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/particleaccelerator/gui_detector.png"); + private TileEntityPADetector source; + + public GUIPADetector(InventoryPlayer player, TileEntityPADetector source) { + super(new ContainerPADetector(player, source)); + this.source = source; + + this.xSize = 176; + this.ySize = 204; + } + + @Override + public void drawScreen(int mouseX, int mouseY, float f) { + super.drawScreen(mouseX, mouseY, f); + + source.tanks[0].renderTankInfo(this, mouseX, mouseY, guiLeft + 134, guiTop + 36, 16, 52); + source.tanks[1].renderTankInfo(this, mouseX, mouseY, guiLeft + 152, guiTop + 36, 16, 52); + this.drawElectricityInfo(this, mouseX, mouseY, guiLeft + 8, guiTop + 18, 16, 52, source.power, source.getMaxPower()); + } + + @Override + protected void drawGuiContainerForegroundLayer( int i, int j) { + + String name = this.source.hasCustomInventoryName() ? this.source.getInventoryName() : I18n.format(this.source.getInventoryName()); + this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2 - 9, 6, 4210752); + this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752); + + this.fontRendererObj.drawString(EnumChatFormatting.AQUA + "/123K", 136, 22, 4210752); + int heat = (int) Math.ceil(source.temperature); + String label = (heat > 123 ? EnumChatFormatting.RED : EnumChatFormatting.AQUA) + "" + heat + "K"; + this.fontRendererObj.drawString(label, 166 - this.fontRendererObj.getStringWidth(label), 12, 4210752); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float interp, int x, int y) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + Minecraft.getMinecraft().getTextureManager().bindTexture(texture); + drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); + + int j = (int) (source.power * 52 / source.getMaxPower()); + drawTexturedModalRect(guiLeft + 8, guiTop + 70 - j, 184, 52 - j, 16, j); + + int heat = (int) Math.ceil(source.temperature); + if(heat <= 123) drawTexturedModalRect(guiLeft + 44, guiTop + 18, 176, 8, 8, 8); + + source.tanks[0].renderTank(guiLeft + 134, guiTop + 88, this.zLevel, 16, 52); + source.tanks[1].renderTank(guiLeft + 152, guiTop + 88, this.zLevel, 16, 52); + } +} diff --git a/src/main/java/com/hbm/qmaw/QMAWLoader.java b/src/main/java/com/hbm/qmaw/QMAWLoader.java index 955873a66..71215402e 100644 --- a/src/main/java/com/hbm/qmaw/QMAWLoader.java +++ b/src/main/java/com/hbm/qmaw/QMAWLoader.java @@ -1,8 +1,10 @@ package com.hbm.qmaw; import java.io.File; +import java.io.FileReader; import java.io.InputStream; import java.io.InputStreamReader; +import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.zip.ZipEntry; @@ -26,21 +28,22 @@ import net.minecraft.launchwrapper.Launch; @NotableComments public class QMAWLoader implements IResourceManagerReloadListener { - public static final HashSet registeredSexOffenders = new HashSet(); + public static final HashSet registeredModFiles = new HashSet(); public static final Gson gson = new Gson(); public static final JsonParser parser = new JsonParser(); public static HashMap qmaw = new HashMap(); @Override public void onResourceManagerReload(IResourceManager resMan) { + long timestamp = System.currentTimeMillis(); MainRegistry.logger.info("[QMAW] Reloading manual..."); init(); - MainRegistry.logger.info("[QMAW] Loaded " + qmaw.size() + " manual entries!"); + MainRegistry.logger.info("[QMAW] Loaded " + qmaw.size() + " manual entries! (" + (System.currentTimeMillis() - timestamp) + "ms)"); } /** For the like 2 people who might consider making an NTM addon and want to include manual pages */ public static void registerModFileURL(File file) { - registeredSexOffenders.add(file); + registeredModFiles.add(file); } /** Searches the asset folder for QMAW format JSON files and adds entries based on that */ @@ -52,18 +55,18 @@ public class QMAWLoader implements IResourceManagerReloadListener { qmaw.clear(); agonyEngine(); - - //dynamic file discovery over all resource domains inside the fucking jar is fucking hard } /** "digital equivalent to holywater" yielded few results on google, if only i had the answer i would drown this entire class in it */ public static void agonyEngine() { - for(File modFile : registeredSexOffenders) dissectZip(modFile); + for(File modFile : registeredModFiles) dissectZip(modFile); - File devEnvManualFolder = new File(Launch.minecraftHome /* TODO: this is null, get a new source, shitass */, "/src/main/resources/assets/manual"); - MainRegistry.logger.info("[QMAW] Exploring " + devEnvManualFolder.getPath()); - if(devEnvManualFolder.exists() && devEnvManualFolder.isDirectory()) dissectManualFolder(devEnvManualFolder); + File devEnvManualFolder = new File(Minecraft.getMinecraft().mcDataDir.getAbsolutePath().replace("/eclipse/.", "") + "/src/main/resources/assets/hbm/manual"); + if(devEnvManualFolder.exists() && devEnvManualFolder.isDirectory()) { + MainRegistry.logger.info("[QMAW] Exploring " + devEnvManualFolder.getAbsolutePath()); + dissectManualFolder(devEnvManualFolder); + } ResourcePackRepository repo = Minecraft.getMinecraft().getResourcePackRepository(); @@ -82,9 +85,11 @@ public class QMAWLoader implements IResourceManagerReloadListener { } } } + + public static void logPackAttempt(String name) { MainRegistry.logger.info("[QMAW] Dissecting resource " + name); } + public static void logFoundManual(String name) { MainRegistry.logger.info("[QMAW] Found manual " + name); } - public static void logPackAttempt(String name) { MainRegistry.logger.info("[QMAW] Desecrating Corpse of " + name); } - + /** You put your white gloves on, you get your hand in there, and then you iterate OVER THE ENTIRE FUCKING ZIP until we find things we deem usable */ public static void dissectZip(File zipFile) { if(zipFile == null) { @@ -96,23 +101,28 @@ public class QMAWLoader implements IResourceManagerReloadListener { try { zip = new ZipFile(zipFile); + Enumeration enumerator = zip.entries(); - while(zip.entries().hasMoreElements()) { - ZipEntry entry = zip.entries().nextElement(); + while(enumerator.hasMoreElements()) { + ZipEntry entry = enumerator.nextElement(); String name = entry.getName(); - MainRegistry.logger.info("[QMAW] Found " + name); - if(name.startsWith("assets/hbm/manual/") && entry.getName().endsWith(".json")) { + if(name.startsWith("assets/hbm/manual/") && name.endsWith(".json")) { InputStream fileStream = zip.getInputStream(entry); InputStreamReader reader = new InputStreamReader(fileStream); - JsonObject obj = (JsonObject) parser.parse(reader); - //TBI - reader.close(); - MainRegistry.logger.info("[QMAW] Found manual " + name); + try { + JsonObject obj = (JsonObject) parser.parse(reader); + String manName = name.replace("assets/hbm/manual/", ""); + registerJson(manName, obj); + reader.close(); + logFoundManual(manName); + } catch(Exception ex) { + MainRegistry.logger.info("[QMAW] Error reading manual " + name + ": " + ex); + } } } } catch(Exception ex) { - MainRegistry.logger.info("Ball explosion " + ex); + MainRegistry.logger.info("[QMAW] Error dissecting zip " + zipFile.getName() + ": " + ex); } finally { try { if(zip != null) zip.close(); @@ -120,14 +130,32 @@ public class QMAWLoader implements IResourceManagerReloadListener { } } + /** Opens a resource pack folder, skips to the manual folder, then tries to dissect that */ public static void dissectFolder(File folder) { File manualFolder = new File(folder, "/assets/manual"); if(manualFolder.exists() && manualFolder.isDirectory()) dissectManualFolder(manualFolder); } + /** Anal bleeding */ public static void dissectManualFolder(File folder) { - for(File file : folder.listFiles()) { - MainRegistry.logger.info("[QMAW] Found " + file.getName()); + + File[] files = folder.listFiles(); + for(File file : files) { + String name = file.getName(); + if(file.isFile() && name.endsWith(".json")) { + try { + FileReader reader = new FileReader(file); + JsonObject obj = (JsonObject) parser.parse(reader); + registerJson(name, obj); + logFoundManual(name); + } catch(Exception ex) { + MainRegistry.logger.info("[QMAW] Error reading manual " + name + ": " + ex); + } + } } } + + public static void registerJson(String name, JsonObject json) { + //TBI + } } diff --git a/src/main/java/com/hbm/tileentity/machine/albion/TileEntityPADetector.java b/src/main/java/com/hbm/tileentity/machine/albion/TileEntityPADetector.java index 14d16e722..7a07ae593 100644 --- a/src/main/java/com/hbm/tileentity/machine/albion/TileEntityPADetector.java +++ b/src/main/java/com/hbm/tileentity/machine/albion/TileEntityPADetector.java @@ -1,11 +1,39 @@ package com.hbm.tileentity.machine.albion; +import com.hbm.inventory.container.ContainerPADetector; +import com.hbm.inventory.gui.GUIPADetector; +import com.hbm.tileentity.IGUIProvider; +import com.hbm.util.fauxpointtwelve.DirPos; + import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.tileentity.TileEntity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; -public class TileEntityPADetector extends TileEntity { +public class TileEntityPADetector extends TileEntityCooledBase implements IGUIProvider { + + public TileEntityPADetector() { + super(5); + } + + @Override + public String getName() { + return "container.paDetector"; + } + + @Override + public DirPos[] getConPos() { + return new DirPos[] { + + }; + } + + @Override + public long getMaxPower() { + return 10_000_000; + } AxisAlignedBB bb = null; @@ -31,4 +59,14 @@ public class TileEntityPADetector extends TileEntity { public double getMaxRenderDistanceSquared() { return 65536.0D; } + + @Override + public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) { + return new ContainerPADetector(player.inventory, this); + } + + @Override + public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { + return new GUIPADetector(player.inventory, this); + } } diff --git a/src/main/resources/assets/hbm/manual/demo.json b/src/main/resources/assets/hbm/manual/demo.json index cb65f7fb9..f21a54d12 100644 --- a/src/main/resources/assets/hbm/manual/demo.json +++ b/src/main/resources/assets/hbm/manual/demo.json @@ -2,8 +2,6 @@ "name": "DEMO", "icon": ["hbm:item.gun_light_revolver", 1, 0], "content": { - "en_US": { - "This is a test page that links to [[Demo|DEMO]].\n\nFormat line break" - } + "en_US": "This is a test page that links to [[Demo|DEMO]].\n\nFormat line break" } }