i need chicken nuggets and a nap

This commit is contained in:
Boblet 2026-05-22 14:16:45 +02:00
parent 2556741a6f
commit 7db05f01ec
2 changed files with 67 additions and 2 deletions

View File

@ -1,12 +1,22 @@
package com.hbm.inventory.gui; package com.hbm.inventory.gui;
import java.io.File;
import java.net.URI;
import java.util.Arrays;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import com.hbm.lib.RefStrings; import com.hbm.lib.RefStrings;
import com.hbm.main.MainRegistry;
import com.hbm.packet.PacketDispatcher;
import com.hbm.packet.toserver.NBTControlPacket;
import com.hbm.tileentity.network.TileEntityRadioAUTOCAL; import com.hbm.tileentity.network.TileEntityRadioAUTOCAL;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
public class GUIScreenRadioAUTOCAL extends GuiScreen { public class GUIScreenRadioAUTOCAL extends GuiScreen {
@ -39,8 +49,59 @@ public class GUIScreenRadioAUTOCAL extends GuiScreen {
GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_LIGHTING);
} }
private void drawGuiContainerForegroundLayer(int x, int y) { @Override
protected void mouseClicked(int x, int y, int i) {
super.mouseClicked(x, y, i);
NBTTagCompound data = null;
if(checkClick(x, y, 8, 36, 18, 18)) { data = new NBTTagCompound(); data.setBoolean("on", true); }
if(checkClick(x, y, 28, 36, 18, 18)) { data = new NBTTagCompound(); data.setBoolean("ignore", true); }
if(checkClick(x, y, 48, 36, 18, 18)) { data = new NBTTagCompound(); data.setBoolean("auto", true); }
if(data != null) {
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, autocal.xCoord, autocal.yCoord, autocal.zCoord));
}
// open folder and generate new script file
if(checkClick(x, y, 104, 36, 18, 18)) {
try {
File uploadFolder = new File(MainRegistry.configDir.getParentFile(), "hbmComputerUpload");
File script = new File(uploadFolder, "script.txt");
if(!uploadFolder.exists()) uploadFolder.mkdir();
if(!script.exists()) script.createNewFile();
script.setExecutable(false);
Class oclass = Class.forName("java.awt.Desktop");
Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object) null, new Object[0]);
oclass.getMethod("browse", new Class[] { URI.class }).invoke(object, new Object[] { uploadFolder.toURI() });
} catch(Throwable ex) { MainRegistry.logger.error("Couldn\'t open link", ex); }
}
// this thing can both upload and download files so let's be careful about this
// the upload is simple, it's just text that is handled by the AUTOCAL, so doing anything malicious isn't more likely than with any other package
// download is iffy, because we take text from the server, fully user-definable, and save it to disk. it's stored as a txt so accudentally running it
// or getting it to run itself, should it be a malicious script, is unlikely. still, we want to minimized the chances as much as we can
// option 1: set file attribute to disallow running (i.e. disable executable perm)
// option 2: add fluff that would break scripts, however they might work. we can't change the actual lines because we want the script to be edited,
// but we can add some extra crap that would either halt common scripting langs entirely or at least disrupt them into not functioning
// option 3: enforce validation so only MS-ES1 script can be received by the client. this means that info such as comments or incorrectly written commands
// are lost, however this is the safest way because it becomes impossible to send malicious code, but it also interferes with regular user operation more
}
protected boolean checkClick(int x, int y, int left, int top, int sizeX, int sizeY) {
return guiLeft + left <= x && guiLeft + left + sizeX > x && guiTop + top < y && guiTop + top + sizeY >= y;
}
private void drawGuiContainerForegroundLayer(int x, int y) {
if(checkClick(x, y, 8, 36, 18, 18)) this.func_146283_a(Arrays.asList(new String[] {EnumChatFormatting.RED + "ON/OFF"}), x, y);
if(checkClick(x, y, 28, 36, 18, 18)) this.func_146283_a(Arrays.asList(new String[] {EnumChatFormatting.RED + "Ignore Errors", "Skips instructions that error,", "leaving the computer turned on.", "May cause unintended behavior", "and inconsistencies."}), x, y);
if(checkClick(x, y, 48, 36, 18, 18)) this.func_146283_a(Arrays.asList(new String[] {EnumChatFormatting.RED + "Automatic Reboot", "Restarts the computer automatically when", "the program stops due to an error", "or after finishing."}), x, y);
if(checkClick(x, y, 84, 36, 18, 18)) this.func_146283_a(Arrays.asList(new String[] {EnumChatFormatting.BLUE + "Upload Program"}), x, y);
if(checkClick(x, y, 104, 36, 18, 18)) this.func_146283_a(Arrays.asList(new String[] {EnumChatFormatting.BLUE + "Open Program Folder"}), x, y);
if(checkClick(x, y, 124, 36, 18, 18)) this.func_146283_a(Arrays.asList(new String[] {EnumChatFormatting.BLUE + "Download Program"}), x, y);
} }
private void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) { private void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {

View File

@ -33,7 +33,7 @@ public class TileEntityRadioAUTOCAL extends TileEntityTickingBase implements ICo
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.networkPackNT(15);
} }
} }
@ -63,6 +63,10 @@ public class TileEntityRadioAUTOCAL extends TileEntityTickingBase implements ICo
@Override @Override
public void receiveControl(NBTTagCompound data) { public void receiveControl(NBTTagCompound data) {
if(data.hasKey("on")) this.isOn = !this.isOn;
if(data.hasKey("ignore")) this.ignoreError = !this.ignoreError;
if(data.hasKey("auto")) this.autoReboot = !this.autoReboot;
this.markChanged();
} }
} }