mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
the telex machine is kept so clean
This commit is contained in:
parent
82dafa437b
commit
360177414a
@ -1,9 +1,12 @@
|
||||
package com.hbm.blocks.network;
|
||||
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
import com.hbm.main.MainRegistry;
|
||||
import com.hbm.tileentity.network.TileEntityRadioTelex;
|
||||
|
||||
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@ -28,4 +31,16 @@ public class RadioTelex extends BlockDummyable {
|
||||
public int getOffset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
||||
if(world.isRemote && !player.isSneaking()) {
|
||||
int[] pos = this.findCore(world, x, y, z);
|
||||
if(pos == null) return false;
|
||||
FMLNetworkHandler.openGui(player, MainRegistry.instance, 0, world, pos[0], pos[1], pos[2]);
|
||||
return true;
|
||||
} else {
|
||||
return !player.isSneaking();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,7 +85,6 @@ public class GUIScreenRadioTorch extends GuiScreen {
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
}
|
||||
|
||||
|
||||
private void drawGuiContainerForegroundLayer(int x, int y) {
|
||||
String name = I18nUtil.resolveKey(this.title);
|
||||
this.fontRendererObj.drawString(name, this.guiLeft + this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, this.guiTop + 6, 4210752);
|
||||
|
||||
321
src/main/java/com/hbm/inventory/gui/GuiScreenRadioTelex.java
Normal file
321
src/main/java/com/hbm/inventory/gui/GuiScreenRadioTelex.java
Normal file
@ -0,0 +1,321 @@
|
||||
package com.hbm.inventory.gui;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.hbm.lib.RefStrings;
|
||||
import com.hbm.packet.NBTControlPacket;
|
||||
import com.hbm.packet.PacketDispatcher;
|
||||
import com.hbm.tileentity.network.TileEntityRadioTelex;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ChatAllowedCharacters;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class GuiScreenRadioTelex extends GuiScreen {
|
||||
|
||||
protected static final ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/machine/gui_telex.png");
|
||||
protected TileEntityRadioTelex telex;
|
||||
protected int xSize = 256;
|
||||
protected int ySize = 244;
|
||||
protected int guiLeft;
|
||||
protected int guiTop;
|
||||
protected GuiTextField txFrequency;
|
||||
protected GuiTextField rxFrequency;
|
||||
protected boolean textFocus = false;
|
||||
|
||||
protected String[] txBuffer;
|
||||
protected int cursorPos = 0;
|
||||
|
||||
public GuiScreenRadioTelex(TileEntityRadioTelex tile) {
|
||||
this.telex = tile;
|
||||
this.txBuffer = new String[tile.txBuffer.length];
|
||||
|
||||
for(int i = 0; i < txBuffer.length; i++) {
|
||||
this.txBuffer[i] = tile.txBuffer[i];
|
||||
}
|
||||
|
||||
for(int i = 4; i > 0; i--) {
|
||||
if(!txBuffer[i].isEmpty()) {
|
||||
cursorPos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
this.guiLeft = (this.width - this.xSize) / 2;
|
||||
this.guiTop = (this.height - this.ySize) / 2;
|
||||
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
|
||||
this.txFrequency = new GuiTextField(this.fontRendererObj, guiLeft + 29, guiTop + 110, 90, 14);
|
||||
this.txFrequency.setTextColor(0x00ff00);
|
||||
this.txFrequency.setDisabledTextColour(0x00ff00);
|
||||
this.txFrequency.setEnableBackgroundDrawing(false);
|
||||
this.txFrequency.setMaxStringLength(10);
|
||||
this.txFrequency.setText(telex.txChannel == null ? "" : telex.txChannel);
|
||||
|
||||
this.rxFrequency = new GuiTextField(this.fontRendererObj, guiLeft + 29, guiTop + 224, 90, 14);
|
||||
this.rxFrequency.setTextColor(0x00ff00);
|
||||
this.rxFrequency.setDisabledTextColour(0x00ff00);
|
||||
this.rxFrequency.setEnableBackgroundDrawing(false);
|
||||
this.rxFrequency.setMaxStringLength(10);
|
||||
this.rxFrequency.setText(telex.rxChannel == null ? "" : telex.rxChannel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float f) {
|
||||
this.drawDefaultBackground();
|
||||
this.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
this.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
}
|
||||
|
||||
private void drawGuiContainerForegroundLayer(int x, int y) {
|
||||
|
||||
if(checkClick(x, y, 7, 85, 18, 18)) this.func_146283_a(Arrays.asList(new String[] {EnumChatFormatting.GOLD + "BELL", "Plays a bell when this character is received"}), x, y);
|
||||
if(checkClick(x, y, 27, 85, 18, 18)) this.func_146283_a(Arrays.asList(new String[] {EnumChatFormatting.GOLD + "PRINT", "Forces recipient to print message after transmission ends"}), x, y);
|
||||
if(checkClick(x, y, 47, 85, 18, 18)) this.func_146283_a(Arrays.asList(new String[] {EnumChatFormatting.GOLD + "CLEAR SCREEN", "Wipes message buffer when this character is received"}), x, y);
|
||||
if(checkClick(x, y, 67, 85, 18, 18)) this.func_146283_a(Arrays.asList(new String[] {EnumChatFormatting.GOLD + "FORMAT", "Inserts format character for message formatting"}), x, y);
|
||||
if(checkClick(x, y, 87, 85, 18, 18)) this.func_146283_a(Arrays.asList(new String[] {EnumChatFormatting.GOLD + "PAUSE", "Pauses message transmission for one second"}), x, y);
|
||||
|
||||
if(checkClick(x, y, 127, 105, 18, 18)) this.func_146283_a(Arrays.asList(new String[] {EnumChatFormatting.GREEN + "SAVE ID"}), x, y);
|
||||
if(checkClick(x, y, 147, 105, 18, 18)) this.func_146283_a(Arrays.asList(new String[] {EnumChatFormatting.YELLOW + "SEND MESSAGE"}), x, y);
|
||||
if(checkClick(x, y, 167, 105, 18, 18)) this.func_146283_a(Arrays.asList(new String[] {EnumChatFormatting.RED + "DELETE MESSAGE BUFFER"}), x, y);
|
||||
|
||||
if(checkClick(x, y, 127, 219, 18, 18)) this.func_146283_a(Arrays.asList(new String[] {EnumChatFormatting.GREEN + "SAVE ID"}), x, y);
|
||||
if(checkClick(x, y, 147, 219, 18, 18)) this.func_146283_a(Arrays.asList(new String[] {EnumChatFormatting.AQUA + "PRINT MESSAGE"}), x, y);
|
||||
if(checkClick(x, y, 167, 219, 18, 18)) this.func_146283_a(Arrays.asList(new String[] {EnumChatFormatting.RED + "CLEAR SCREEN"}), x, y);
|
||||
}
|
||||
|
||||
private void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
|
||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
||||
|
||||
this.txFrequency.drawTextBox();
|
||||
this.rxFrequency.drawTextBox();
|
||||
|
||||
for(int line = 0; line < 5; line++) {
|
||||
String text = txBuffer[line];
|
||||
int y = 11 + 14 * line;
|
||||
|
||||
String format = EnumChatFormatting.RESET + "";
|
||||
|
||||
for(int index = 0; index < text.length(); index++) {
|
||||
int x = 11 + 7 * index;
|
||||
char c = text.charAt(index);
|
||||
x += (7 - this.fontRendererObj.getCharWidth(c)) / 2;
|
||||
if(c == '§' && text.length() > index + 1) {
|
||||
format = "\u00a7" + text.charAt(index + 1);
|
||||
x -= 3;
|
||||
}
|
||||
String glyph = format + c;
|
||||
if(c == '\u0007') glyph = EnumChatFormatting.RED + "B";
|
||||
if(c == '\u000c') glyph = EnumChatFormatting.RED + "P";
|
||||
if(c == '\u007f') glyph = EnumChatFormatting.RED + "<";
|
||||
if(c == '\u0016') glyph = EnumChatFormatting.RED + "W";
|
||||
this.fontRendererObj.drawString(glyph, guiLeft + x, guiTop + y, 0x00ff00);
|
||||
}
|
||||
|
||||
if(System.currentTimeMillis() % 1000 < 500 && this.textFocus) {
|
||||
int x = Math.max(11 + 7 * (text.length() - 1) + 7, 11);
|
||||
if(this.cursorPos == line) {
|
||||
this.fontRendererObj.drawString("|", guiLeft + x, guiTop + y, 0x00ff00);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int line = 0; line < 5; line++) {
|
||||
String text = telex.rxBuffer[line];
|
||||
int y = 145 + 14 * line;
|
||||
|
||||
String format = EnumChatFormatting.RESET + "";
|
||||
|
||||
int x = 11;
|
||||
|
||||
for(int index = 0; index < text.length(); index++) {
|
||||
|
||||
char c = text.charAt(index);
|
||||
x += (7 - this.fontRendererObj.getCharWidth(c)) / 2;
|
||||
if(c == '§' && text.length() > index + 1) {
|
||||
format = "\u00a7" + text.charAt(index + 1);
|
||||
c = ' ';
|
||||
} else if(c == '§') {
|
||||
c = ' ';
|
||||
} else if(index > 0 && text.charAt(index - 1) == '§') {
|
||||
c = ' ';
|
||||
x -= 14;
|
||||
}
|
||||
String glyph = format + c;
|
||||
this.fontRendererObj.drawString(glyph, guiLeft + x, guiTop + y, 0x00ff00);
|
||||
x += 7;
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glLineWidth(3F);
|
||||
Random rand = new Random(telex.sendingChar);
|
||||
Tessellator tess = Tessellator.instance;
|
||||
tess.startDrawing(GL11.GL_LINES);
|
||||
tess.setColorOpaque_I(0x00ff00);
|
||||
double offset = 0;
|
||||
for(int i = 0; i < 48; i++) {
|
||||
tess.addVertex(guiLeft + 199 + i, guiTop + 93.5 + offset, this.zLevel + 10);
|
||||
if(telex.sendingChar != ' ' && i > 4 && i < 43) offset = rand.nextGaussian() * 7; else offset = 0;
|
||||
offset = MathHelper.clamp_double(offset, -7D, 7D);
|
||||
tess.addVertex(guiLeft + 199 + i + 1, guiTop + 93.5 + offset, this.zLevel + 10);
|
||||
}
|
||||
tess.draw();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int i) {
|
||||
super.mouseClicked(x, y, i);
|
||||
|
||||
this.txFrequency.mouseClicked(x, y, i);
|
||||
this.rxFrequency.mouseClicked(x, y, i);
|
||||
|
||||
if(guiLeft + 7 <= x && guiLeft + 7 + 242 > x && guiTop + 7 < y && guiTop + 7 + 74 >= y) {
|
||||
this.textFocus = true;
|
||||
} else {
|
||||
this.textFocus = false;
|
||||
}
|
||||
|
||||
char character = '\0';
|
||||
String cmd = null;
|
||||
|
||||
/* special characters */
|
||||
// BEL
|
||||
if(checkClick(x, y, 7, 85, 18, 18)) character = '\u0007'; // bell
|
||||
// PRT
|
||||
if(checkClick(x, y, 27, 85, 18, 18)) character = '\u000c'; // form feed
|
||||
// CLS
|
||||
if(checkClick(x, y, 47, 85, 18, 18)) character = '\u007f'; // delete
|
||||
// FMT
|
||||
if(checkClick(x, y, 67, 85, 18, 18)) character = '§'; // minecraft formatting character
|
||||
// PSE
|
||||
if(checkClick(x, y, 87, 85, 18, 18)) character = '\u0016'; // synchronous idle
|
||||
|
||||
// SVE
|
||||
if(checkClick(x, y, 127, 105, 18, 18) || checkClick(x, y, 127, 219, 18, 18)) cmd = "sve"; // save channel
|
||||
// SND
|
||||
if(checkClick(x, y, 147, 105, 18, 18)) cmd = "snd"; // send message in TX buffer
|
||||
// DEL
|
||||
if(checkClick(x, y, 167, 105, 18, 18)) { // delete message in TX buffer
|
||||
cmd = "rxdel";
|
||||
for(int j = 0; j < 5; j++) this.txBuffer[j] = "";
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
for(int j = 0; j < 5; j++) data.setString("tx" + j, this.txBuffer[j]);
|
||||
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, telex.xCoord, telex.yCoord, telex.zCoord));
|
||||
}
|
||||
// PRT
|
||||
if(checkClick(x, y, 147, 219, 18, 18)) cmd = "rxprt"; // print message in RX buffer
|
||||
// CLS
|
||||
if(checkClick(x, y, 167, 219, 18, 18)) cmd = "rxcls"; // delete message in RX buffer
|
||||
|
||||
if(cmd != null) {
|
||||
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setString("cmd", cmd);
|
||||
|
||||
if("snd".equals(cmd)) {
|
||||
for(int j = 0; j < 5; j++) data.setString("tx" + j, this.txBuffer[j]);
|
||||
}
|
||||
|
||||
if("sve".equals(cmd)) {
|
||||
data.setString("txChan", this.txFrequency.getText());
|
||||
data.setString("rxChan", this.rxFrequency.getText());
|
||||
}
|
||||
|
||||
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, telex.xCoord, telex.yCoord, telex.zCoord));
|
||||
}
|
||||
|
||||
if(character != '\0') {
|
||||
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
setTextFocus();
|
||||
submitChar(character);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
protected void setTextFocus() {
|
||||
this.textFocus = true;
|
||||
this.txFrequency.setFocused(false);
|
||||
this.rxFrequency.setFocused(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char c, int i) {
|
||||
|
||||
if(this.txFrequency.textboxKeyTyped(c, i)) return;
|
||||
if(this.rxFrequency.textboxKeyTyped(c, i)) return;
|
||||
|
||||
if(this.textFocus) {
|
||||
|
||||
if(i == 1) {
|
||||
this.textFocus = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if(i == Keyboard.KEY_UP) this.cursorPos--;
|
||||
if(i == Keyboard.KEY_DOWN) this.cursorPos++;
|
||||
|
||||
this.cursorPos = MathHelper.clamp_int(cursorPos, 0, 4);
|
||||
|
||||
if(ChatAllowedCharacters.isAllowedCharacter(c)) {
|
||||
submitChar(c);
|
||||
return;
|
||||
}
|
||||
|
||||
if(i == Keyboard.KEY_BACK && this.txBuffer[cursorPos].length() > 0) {
|
||||
this.txBuffer[cursorPos] = this.txBuffer[cursorPos].substring(0, this.txBuffer[cursorPos].length() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
if(i == 1 || i == this.mc.gameSettings.keyBindInventory.getKeyCode()) {
|
||||
this.mc.thePlayer.closeScreen();
|
||||
this.mc.setIngameFocus();
|
||||
}
|
||||
}
|
||||
|
||||
protected void submitChar(char c) {
|
||||
String line = this.txBuffer[cursorPos];
|
||||
|
||||
if(line.length() < TileEntityRadioTelex.lineWidth) {
|
||||
this.txBuffer[cursorPos] = line + c;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
for(int j = 0; j < 5; j++) data.setString("tx" + j, this.txBuffer[j]);
|
||||
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, telex.xCoord, telex.yCoord, telex.zCoord));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -40,7 +40,7 @@ public class ArmorTrenchmaster extends ArmorFSB {
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) {
|
||||
super.addInformation(stack, player, list, ext);
|
||||
|
||||
list.add(EnumChatFormatting.RED + " + " + I18nUtil.resolveKey("armor.fasterReload"));
|
||||
list.add(EnumChatFormatting.GRAY + " + " + I18nUtil.resolveKey("armor.moreAmmo"));
|
||||
list.add(EnumChatFormatting.RED + " " + I18nUtil.resolveKey("armor.fasterReload"));
|
||||
list.add(EnumChatFormatting.RED + " " + I18nUtil.resolveKey("armor.moreAmmo"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -783,7 +783,7 @@ public class CraftingManager {
|
||||
addShapelessAuto(new ItemStack(ModItems.ams_catalyst_dineutronium, 1), new Object[] { ModItems.ams_catalyst_blank, ModItems.rune_hagalaz, ModItems.rune_hagalaz, ModItems.rune_thurisaz, ModItems.rune_thurisaz, DNT.dust(), DNT.dust(), DNT.dust(), DNT.dust() });
|
||||
addRecipeAuto(new ItemStack(ModBlocks.dfc_core, 1), new Object[] { "DLD", "LML", "DLD", 'D', ModItems.ingot_bismuth, 'L', DNT.block(), 'M', KEY_CIRCUIT_BISMUTH });
|
||||
addRecipeAuto(new ItemStack(ModBlocks.dfc_emitter, 1), new Object[] { "SDS", "TXL", "SDS", 'S', OSMIRIDIUM.plateCast(), 'D', ModItems.plate_desh, 'T', ModBlocks.machine_transformer_dnt, 'X', ModItems.crystal_xen, 'L', ModItems.sat_head_laser });
|
||||
addRecipeAuto(new ItemStack(ModBlocks.dfc_receiver, 1), new Object[] { "SDS", "TXL", "SDS", 'S', OSMIRIDIUM.plateCast(), 'D', ModItems.plate_desh, 'T', ModBlocks.machine_transformer_dnt, 'X', new ItemStack(ModBlocks.sellafield, 1, 5), 'L', ModItems.hull_small_steel });
|
||||
addRecipeAuto(new ItemStack(ModBlocks.dfc_receiver, 1), new Object[] { "SDS", "TXL", "SDS", 'S', OSMIRIDIUM.plateCast(), 'D', ModItems.plate_desh, 'T', ModBlocks.machine_transformer_dnt, 'X', ModBlocks.block_dineutronium, 'L', ModItems.hull_small_steel });
|
||||
addRecipeAuto(new ItemStack(ModBlocks.dfc_injector, 1), new Object[] { "SDS", "TXL", "SDS", 'S', OSMIRIDIUM.plateCast(), 'D', CMB.plate(), 'T', ModBlocks.machine_fluidtank, 'X', ModItems.motor, 'L', ModItems.pipes_steel });
|
||||
addRecipeAuto(new ItemStack(ModBlocks.dfc_stabilizer, 1), new Object[] { "SDS", "TXL", "SDS", 'S', OSMIRIDIUM.plateCast(), 'D', ModItems.plate_desh, 'T', ModItems.singularity_spark, 'X', ModItems.magnet_circular, 'L', ModItems.crystal_xen });
|
||||
addRecipeAuto(new ItemStack(ModBlocks.barrel_plastic, 1), new Object[] { "IPI", "I I", "IPI", 'I', ModItems.plate_polymer, 'P', AL.plate() });
|
||||
|
||||
@ -1,7 +1,194 @@
|
||||
package com.hbm.tileentity.network;
|
||||
|
||||
import com.hbm.interfaces.IControlReceiver;
|
||||
import com.hbm.inventory.gui.GuiScreenRadioTelex;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.INBTPacketReceiver;
|
||||
import com.hbm.tileentity.network.RTTYSystem.RTTYChannel;
|
||||
import com.hbm.util.ItemStackUtil;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TileEntityRadioTelex extends TileEntity {
|
||||
public class TileEntityRadioTelex extends TileEntity implements INBTPacketReceiver, IControlReceiver, IGUIProvider {
|
||||
|
||||
public static final int lineWidth = 33;
|
||||
public String txChannel = "";
|
||||
public String rxChannel = "";
|
||||
public String[] txBuffer = new String[] {"", "", "", "", ""};
|
||||
public String[] rxBuffer = new String[] {"", "", "", "", ""};
|
||||
public int sendingLine = 0;
|
||||
public int sendingIndex = 0;
|
||||
public boolean isSending = false;
|
||||
public int sendingWait = 0;
|
||||
public int writingLine = 0;
|
||||
public boolean printAfterRx = false;
|
||||
public boolean deleteOnReceive = true;
|
||||
public char sendingChar = ' ';
|
||||
|
||||
public static final char eol = '\n';
|
||||
public static final char eot = '\u0004';
|
||||
public static final char bell = '\u0007';
|
||||
public static final char print = '\u000c';
|
||||
public static final char pause = '\u0016';
|
||||
public static final char clear = '\u007f';
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
this.sendingChar = ' ';
|
||||
|
||||
if(this.isSending && this.txChannel.isEmpty()) this.isSending = false;
|
||||
|
||||
if(this.isSending) {
|
||||
|
||||
if(sendingWait > 0) {
|
||||
sendingWait--;
|
||||
} else {
|
||||
|
||||
String line = txBuffer[sendingLine];
|
||||
|
||||
if(line.length() > sendingIndex) {
|
||||
char c = line.charAt(sendingIndex);
|
||||
sendingIndex++;
|
||||
if(c == pause) {
|
||||
sendingWait = 20;
|
||||
} else {
|
||||
RTTYSystem.broadcast(worldObj, this.txChannel, c);
|
||||
this.sendingChar = c;
|
||||
}
|
||||
} else {
|
||||
|
||||
if(sendingLine >= 4) {
|
||||
this.isSending = false;
|
||||
RTTYSystem.broadcast(worldObj, this.txChannel, eot);
|
||||
this.sendingLine = 0;
|
||||
this.sendingIndex = 0;
|
||||
} else {
|
||||
RTTYSystem.broadcast(worldObj, this.txChannel, eol);
|
||||
this.sendingLine++;
|
||||
this.sendingIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!this.rxChannel.isEmpty()) {
|
||||
RTTYChannel chan = RTTYSystem.listen(worldObj, this.rxChannel);
|
||||
|
||||
if(chan != null && chan.signal instanceof Character && (chan.timeStamp > worldObj.getTotalWorldTime() - 2 && chan.timeStamp != -1)) {
|
||||
char c = (char) chan.signal;
|
||||
|
||||
if(this.deleteOnReceive) {
|
||||
this.deleteOnReceive = false;
|
||||
for(int i = 0; i < 5; i++) this.rxBuffer[i] = "";
|
||||
this.writingLine = 0;
|
||||
}
|
||||
|
||||
if(c == eot) {
|
||||
if(this.printAfterRx) {
|
||||
this.printAfterRx = false;
|
||||
this.print();
|
||||
}
|
||||
this.deleteOnReceive = true;
|
||||
} else if(c == eol) {
|
||||
if(this.writingLine < 4) this.writingLine++;
|
||||
} else if(c == bell) {
|
||||
worldObj.playSoundEffect(xCoord, yCoord, zCoord, "random.orb", 2F, 0.5F);
|
||||
} else if(c == print) {
|
||||
this.printAfterRx = true;
|
||||
} else if(c == clear) {
|
||||
for(int i = 0; i < 5; i++) this.rxBuffer[i] = "";
|
||||
this.writingLine = 0;
|
||||
} else {
|
||||
this.rxBuffer[this.writingLine] += c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
for(int i = 0; i < 5; i++) {
|
||||
data.setString("tx" + i, txBuffer[i]);
|
||||
data.setString("rx" + i, rxBuffer[i]);
|
||||
}
|
||||
data.setString("txChan", txChannel);
|
||||
data.setString("rxChan", rxChannel);
|
||||
data.setInteger("sending", sendingChar);
|
||||
INBTPacketReceiver.networkPack(this, data, 16);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void networkUnpack(NBTTagCompound nbt) {
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
txBuffer[i] = nbt.getString("tx" + i);
|
||||
rxBuffer[i] = nbt.getString("rx" + i);
|
||||
}
|
||||
this.txChannel = nbt.getString("txChan");
|
||||
this.rxChannel = nbt.getString("rxChan");
|
||||
this.sendingChar = (char) nbt.getInteger("sending");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveControl(NBTTagCompound data) {
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
if(data.hasKey("tx" + i)) this.txBuffer[i] = data.getString("tx" + i);
|
||||
}
|
||||
|
||||
String cmd = data.getString("cmd");
|
||||
|
||||
if("snd".equals(cmd) && !this.isSending) {
|
||||
this.isSending = true;
|
||||
this.sendingLine = 0;
|
||||
this.sendingIndex = 0;
|
||||
}
|
||||
|
||||
if("rxprt".equals(cmd)) {
|
||||
print();
|
||||
}
|
||||
|
||||
if("rxcls".equals(cmd)) {
|
||||
for(int i = 0; i < 5; i++) this.rxBuffer[i] = "";
|
||||
this.writingLine = 0;
|
||||
}
|
||||
|
||||
if("sve".equals(cmd)) {
|
||||
this.txChannel = data.getString("txChan");
|
||||
this.rxChannel = data.getString("rxChan");
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public void print() {
|
||||
ItemStack stack = new ItemStack(Items.paper);
|
||||
ItemStackUtil.addTooltipToStack(stack, rxBuffer);
|
||||
stack.setStackDisplayName("Message");
|
||||
worldObj.spawnEntityInWorld(new EntityItem(worldObj, xCoord + 0.5, yCoord + 1, zCoord + 0.5, stack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(EntityPlayer player) {
|
||||
return player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 16 * 16;
|
||||
}
|
||||
|
||||
@Override public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) { return null; }
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return new GuiScreenRadioTelex(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ armor.cap=Schadensobergrenze: %s
|
||||
armor.damageModifier=Modifikator: %s (%s)
|
||||
armor.electricJetpack=Ionentriebwerke
|
||||
armor.explosionImmune=Kann nur Schaden durch Explosionen nehmen
|
||||
armor.fasterReload=Schneklleres Nachladen
|
||||
armor.fasterReload=Schnelleres Nachladen
|
||||
armor.fastFall=Schneller Fall
|
||||
armor.fireproof=Feuerfest
|
||||
armor.fullSetBonus=Set-Bonus:
|
||||
|
||||
BIN
src/main/resources/assets/hbm/textures/blocks/radio_telex.png
Normal file
BIN
src/main/resources/assets/hbm/textures/blocks/radio_telex.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 609 B |
Loading…
x
Reference in New Issue
Block a user