From 2ff7052ca373e97c0525790da6191ab893e7f1cf Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 12 Dec 2022 22:39:07 +0100 Subject: [PATCH] return of the radio --- src/main/java/com/hbm/blocks/ModBlocks.java | 2 - .../java/com/hbm/blocks/machine/RadioRec.java | 138 ++++----- src/main/java/com/hbm/handler/GUIHandler.java | 15 - .../container/ContainerRadioRec.java | 17 -- .../com/hbm/inventory/gui/GUIRadioRec.java | 273 ++++++------------ .../inventory/gui/GUIScreenRadioTorch.java | 1 - .../java/com/hbm/packet/AuxButtonPacket.java | 14 - .../java/com/hbm/packet/AuxGaugePacket.java | 13 - .../machine/TileEntityRadioRec.java | 74 ++++- .../hbm/tileentity/network/RTTYSystem.java | 124 +++++++- .../network/TileEntityRadioTorchReceiver.java | 57 ++-- src/main/java/com/hbm/util/NoteBuilder.java | 74 +++++ .../assets/hbm/textures/gui/gui_radiorec.png | Bin 1132 -> 0 bytes .../hbm/textures/gui/machine/gui_radio.png | Bin 0 -> 1068 bytes 14 files changed, 437 insertions(+), 365 deletions(-) delete mode 100644 src/main/java/com/hbm/inventory/container/ContainerRadioRec.java create mode 100644 src/main/java/com/hbm/util/NoteBuilder.java delete mode 100644 src/main/resources/assets/hbm/textures/gui/gui_radiorec.png create mode 100644 src/main/resources/assets/hbm/textures/gui/machine/gui_radio.png diff --git a/src/main/java/com/hbm/blocks/ModBlocks.java b/src/main/java/com/hbm/blocks/ModBlocks.java index c7485f6bb..bda9dda99 100644 --- a/src/main/java/com/hbm/blocks/ModBlocks.java +++ b/src/main/java/com/hbm/blocks/ModBlocks.java @@ -1092,9 +1092,7 @@ public class ModBlocks { public static Block radiobox; public static final int guiID_radiobox = 66; - public static Block radiorec; - public static final int guiID_radiorec = 69; public static Block machine_forcefield; public static final int guiID_forcefield = 75; diff --git a/src/main/java/com/hbm/blocks/machine/RadioRec.java b/src/main/java/com/hbm/blocks/machine/RadioRec.java index 9bb6b8caf..53792b48b 100644 --- a/src/main/java/com/hbm/blocks/machine/RadioRec.java +++ b/src/main/java/com/hbm/blocks/machine/RadioRec.java @@ -1,131 +1,113 @@ package com.hbm.blocks.machine; +import com.hbm.inventory.gui.GUIRadioRec; +import com.hbm.main.MainRegistry; +import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.machine.TileEntityRadioRec; +import cpw.mods.fml.common.network.internal.FMLNetworkHandler; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -public class RadioRec extends BlockContainer { +public class RadioRec extends BlockContainer implements IGUIProvider { - public RadioRec(Material p_i45386_1_) { - super(p_i45386_1_); + public RadioRec(Material mat) { + super(mat); } @Override - public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { + public TileEntity createNewTileEntity(World world, int meta) { return new TileEntityRadioRec(); } - + @Override - public int getRenderType(){ + public int getRenderType() { return -1; } - + @Override public boolean isOpaqueCube() { return false; } - + @Override public boolean renderAsNormalBlock() { return false; } - + @Override public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack) { int i = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3; - - if(i == 0) - { - world.setBlockMetadataWithNotify(x, y, z, 3, 2); - } - if(i == 1) - { - world.setBlockMetadataWithNotify(x, y, z, 4, 2); - } - if(i == 2) - { - world.setBlockMetadataWithNotify(x, y, z, 2, 2); - } - if(i == 3) - { - world.setBlockMetadataWithNotify(x, y, z, 5, 2); + + if(i == 0) world.setBlockMetadataWithNotify(x, y, z, 3, 2); + if(i == 1) world.setBlockMetadataWithNotify(x, y, z, 4, 2); + if(i == 2) world.setBlockMetadataWithNotify(x, y, z, 2, 2); + if(i == 3) world.setBlockMetadataWithNotify(x, y, z, 5, 2); + } + + @Override + public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_) { + int te = p_149719_1_.getBlockMetadata(p_149719_2_, p_149719_3_, p_149719_4_); + float f = 0.0625F; + + this.setBlockBounds(0.0F, 0.0F, 2 * f, 1.0F, 1.0F, 14 * f); + switch(te) { + case 4: this.setBlockBounds(4 * f, 0.0F, 1 * f, 12 * f, 10 * f, 15 * f); break; + case 2: this.setBlockBounds(1 * f, 0.0F, 4 * f, 15 * f, 10 * f, 12 * f); break; + case 5: this.setBlockBounds(4 * f, 0.0F, 1 * f, 12 * f, 10 * f, 15 * f); break; + case 3: this.setBlockBounds(1 * f, 0.0F, 4 * f, 15 * f, 10 * f, 12 * f); break; } } - - @Override - public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_) - { - int te = p_149719_1_.getBlockMetadata(p_149719_2_, p_149719_3_, p_149719_4_); - float f = 0.0625F; - - this.setBlockBounds(0.0F, 0.0F, 2*f, 1.0F, 1.0F, 14*f); - switch(te) - { - case 4: - this.setBlockBounds(4*f, 0.0F, 1*f, 12*f, 10*f, 15*f); - break; - case 2: - this.setBlockBounds(1*f, 0.0F, 4*f, 15*f, 10*f, 12*f); - break; - case 5: - this.setBlockBounds(4*f, 0.0F, 1*f, 12*f, 10*f, 15*f); - break; - case 3: - this.setBlockBounds(1*f, 0.0F, 4*f, 15*f, 10*f, 12*f); - break; - } - } - + @Override public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { int te = world.getBlockMetadata(x, y, z); - float f = 0.0625F; - - this.setBlockBounds(0.0F, 0.0F, 2*f, 1.0F, 1.0F, 14*f); - switch(te) - { - case 4: - this.setBlockBounds(4*f, 0.0F, 1*f, 12*f, 10*f, 15*f); - break; - case 2: - this.setBlockBounds(1*f, 0.0F, 4*f, 15*f, 10*f, 12*f); - break; - case 5: - this.setBlockBounds(4*f, 0.0F, 1*f, 12*f, 10*f, 15*f); - break; - case 3: - this.setBlockBounds(1*f, 0.0F, 4*f, 15*f, 10*f, 12*f); - break; + float f = 0.0625F; + + this.setBlockBounds(0.0F, 0.0F, 2 * f, 1.0F, 1.0F, 14 * f); + switch(te) { + case 4: this.setBlockBounds(4 * f, 0.0F, 1 * f, 12 * f, 10 * f, 15 * f); break; + case 2: this.setBlockBounds(1 * f, 0.0F, 4 * f, 15 * f, 10 * f, 12 * f); break; + case 5: this.setBlockBounds(4 * f, 0.0F, 1 * f, 12 * f, 10 * f, 15 * f); break; + case 3: this.setBlockBounds(1 * f, 0.0F, 4 * f, 15 * f, 10 * f, 12 * f); break; } - + return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ); } @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) - { - return true; - } else if(!player.isSneaking()) - { - //FMLNetworkHandler.openGui(player, MainRegistry.instance, ModBlocks.guiID_radiorec, world, x, y, z); - player.addChatMessage(new ChatComponentText("It's a broken radio, it doesn't do anything. What did you expect, a plasma TV?")); + if(world.isRemote && !player.isSneaking()) { + FMLNetworkHandler.openGui(player, MainRegistry.instance, 0, world, x, y, z); return true; } else { - //return true; - return false; + return !player.isSneaking(); } } + @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) { + TileEntity te = world.getTileEntity(x, y, z); + + if(te instanceof TileEntityRadioRec) + return new GUIRadioRec((TileEntityRadioRec) te); + + return null; + } } diff --git a/src/main/java/com/hbm/handler/GUIHandler.java b/src/main/java/com/hbm/handler/GUIHandler.java index 605338bcf..6d2184ea1 100644 --- a/src/main/java/com/hbm/handler/GUIHandler.java +++ b/src/main/java/com/hbm/handler/GUIHandler.java @@ -20,7 +20,6 @@ import com.hbm.tileentity.turret.*; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; @@ -457,13 +456,6 @@ public class GUIHandler implements IGuiHandler { return null; } - case ModBlocks.guiID_radiorec: { - if(entity instanceof TileEntityRadioRec) { - return new ContainerRadioRec(player.inventory, (TileEntityRadioRec) entity); - } - return null; - } - case ModBlocks.guiID_gascent: { if(entity instanceof TileEntityMachineGasCent) { return new ContainerMachineGasCent(player.inventory, (TileEntityMachineGasCent) entity); @@ -1254,13 +1246,6 @@ public class GUIHandler implements IGuiHandler { return null; } - case ModBlocks.guiID_radiorec: { - if(entity instanceof TileEntityRadioRec) { - return new GUIRadioRec(player.inventory, (TileEntityRadioRec) entity); - } - return null; - } - case ModBlocks.guiID_gascent: { if(entity instanceof TileEntityMachineGasCent) { return new GUIMachineGasCent(player.inventory, (TileEntityMachineGasCent) entity); diff --git a/src/main/java/com/hbm/inventory/container/ContainerRadioRec.java b/src/main/java/com/hbm/inventory/container/ContainerRadioRec.java deleted file mode 100644 index 23c56df06..000000000 --- a/src/main/java/com/hbm/inventory/container/ContainerRadioRec.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.hbm.inventory.container; - -import com.hbm.tileentity.machine.TileEntityRadioRec; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; - -public class ContainerRadioRec extends Container { - - public ContainerRadioRec(InventoryPlayer invPlayer, TileEntityRadioRec tedf) { } - - @Override - public boolean canInteractWith(EntityPlayer p_75145_1_) { - return true; - } -} diff --git a/src/main/java/com/hbm/inventory/gui/GUIRadioRec.java b/src/main/java/com/hbm/inventory/gui/GUIRadioRec.java index 36e70e844..f9014122c 100644 --- a/src/main/java/com/hbm/inventory/gui/GUIRadioRec.java +++ b/src/main/java/com/hbm/inventory/gui/GUIRadioRec.java @@ -1,230 +1,133 @@ package com.hbm.inventory.gui; -import java.math.BigDecimal; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; -import org.apache.commons.lang3.math.NumberUtils; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; -import com.hbm.inventory.container.ContainerRadioRec; import com.hbm.lib.RefStrings; -import com.hbm.packet.AuxButtonPacket; +import com.hbm.packet.NBTControlPacket; import com.hbm.packet.PacketDispatcher; import com.hbm.tileentity.machine.TileEntityRadioRec; +import com.hbm.util.I18nUtil; 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.resources.I18n; -import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; -public class GUIRadioRec extends GuiInfoContainer { +public class GUIRadioRec extends GuiScreen { - private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/gui_radiorec.png"); - private TileEntityRadioRec diFurnace; - - private GuiTextField freqField; - - List buttons = new ArrayList(); + private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/machine/gui_radio.png"); + protected TileEntityRadioRec radio; + protected int xSize = 256; + protected int ySize = 204; + protected int guiLeft; + protected int guiTop; + protected GuiTextField frequency; + public GUIRadioRec(TileEntityRadioRec radio) { + this.radio = radio; - public GUIRadioRec(InventoryPlayer invPlayer, TileEntityRadioRec tedf) { - super(new ContainerRadioRec(invPlayer, tedf)); - diFurnace = tedf; - - this.xSize = 176; - this.ySize = 54; + this.xSize = 220; + this.ySize = 42; } - + + @Override public void initGui() { - super.initGui(); + this.guiLeft = (this.width - this.xSize) / 2; + this.guiTop = (this.height - this.ySize) / 2; - buttons.clear(); - buttons.add(new RadioButton(guiLeft + 25, guiTop + 16, 0, "Save")); - buttons.add(new RadioButton(guiLeft + 61, guiTop + 16, 1, "On/Off")); - - Keyboard.enableRepeatEvents(true); - this.freqField = new GuiTextField(this.fontRendererObj, guiLeft + 100, guiTop + 21, 48, 12); - this.freqField.setTextColor(-1); - this.freqField.setDisabledTextColour(-1); - this.freqField.setEnableBackgroundDrawing(false); - this.freqField.setMaxStringLength(5); - this.freqField.setText(String.valueOf(diFurnace.freq)); - - if(diFurnace.freq == 0) { - double d = 100 + diFurnace.getWorldObj().rand.nextInt(900); - d += (diFurnace.getWorldObj().rand.nextInt(10) * 0.1D); - this.freqField.setText(String.valueOf(d)); - } - - save(); - } - - @Override - public void drawScreen(int i, int j, float f) { - super.drawScreen(i, j, f); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_BLEND); - this.freqField.drawTextBox(); + Keyboard.enableRepeatEvents(true); - for(RadioButton b : buttons) - if(b.isMouseOnButton(i, j)) - b.drawString(i, j); + int oX = 4; + int oY = 4; + + this.frequency = new GuiTextField(this.fontRendererObj, guiLeft + 25 + oX, guiTop + 17 + oY, 90 - oX * 2, 14); + this.frequency.setTextColor(0x00ff00); + this.frequency.setDisabledTextColour(0x00ff00); + this.frequency.setEnableBackgroundDrawing(false); + this.frequency.setMaxStringLength(10); + this.frequency.setText(radio.channel == null ? "" : radio.channel); } @Override - protected void drawGuiContainerForegroundLayer(int i, int j) { - String name = I18n.format("container.radiorec"); - this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752); + 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); } - @Override - protected void drawGuiContainerBackgroundLayer(float f, int i, int j) { + + private void drawGuiContainerForegroundLayer(int x, int y) { + String name = I18nUtil.resolveKey("container.radio"); + this.fontRendererObj.drawString(name, this.guiLeft + this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, this.guiTop + 6, 4210752); + + if(guiLeft + 137 <= x && guiLeft + 137 + 18 > x && guiTop + 17 < y && guiTop + 17 + 18 >= y) { + func_146283_a(Arrays.asList(new String[] { "Save Settings" }), x, y); + } + if(guiLeft + 173 <= x && guiLeft + 173 + 18 > x && guiTop + 17 < y && guiTop + 17 + 18 >= y) { + func_146283_a(Arrays.asList(new String[] { "Toggle" }), 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); - - if(freqField.isFocused()) - drawTexturedModalRect(guiLeft + 97, guiTop + 16, 0, 184 + 18, 54, 18); - else - drawTexturedModalRect(guiLeft + 97, guiTop + 16, 0, 184, 54, 18); - for(RadioButton b : buttons) - b.drawButton(); + if(this.radio.isOn) { + drawTexturedModalRect(guiLeft + 173, guiTop + 17, 0, 42, 18, 18); + } + + this.frequency.drawTextBox(); } - - public void updateScreen() { } - - protected void keyTyped(char p_73869_1_, int p_73869_2_) - { - if (this.freqField.textboxKeyTyped(p_73869_1_, p_73869_2_)) { } - else { - super.keyTyped(p_73869_1_, p_73869_2_); - } - } - - protected void rectify() { - String s = freqField.getText(); - - if(NumberUtils.isNumber(s)) { - double d = Double.parseDouble(s); - d = Math.max(100, Math.min(999.9, d)); - d = truncateDecimal(d, 1).doubleValue(); - s = String.valueOf(d); - } else { - s = "100.0"; - } - - freqField.setText(s); - } - - private BigDecimal truncateDecimal(double x, int numberofDecimals) - { - if (x > 0) { - return new BigDecimal(String.valueOf(x)).setScale(numberofDecimals, BigDecimal.ROUND_FLOOR); - } else { - return new BigDecimal(String.valueOf(x)).setScale(numberofDecimals, BigDecimal.ROUND_CEILING); - } - } - - protected void mouseClicked(int i, int j, int k) - { - super.mouseClicked(i, j, k); - this.freqField.mouseClicked(i, j, k); - - for(RadioButton b : buttons) - if(b.isMouseOnButton(i, j)) - b.executeAction(); - } - - protected void toggle() { - - rectify(); - - PacketDispatcher.wrapper.sendToServer(new AuxButtonPacket(diFurnace.xCoord, diFurnace.yCoord, diFurnace.zCoord, diFurnace.isOn ? 0 : 1, 0)); - } - - protected void save() { - - rectify(); - - String s = freqField.getText(); - double d = Double.parseDouble(s); - PacketDispatcher.wrapper.sendToServer(new AuxButtonPacket(diFurnace.xCoord, diFurnace.yCoord, diFurnace.zCoord, (int)(d * 10D), 1)); - } - - - class RadioButton { - - int xPos; - int yPos; - int buttonType; - String info; - - //0: save - //1: type - //2: music 1 - //3: music 2 - //4: music 3 - //5: music 4 - - public RadioButton(int x, int y, int t, String i) { - xPos = x; - yPos = y; - buttonType = t; - info = i; - } - - public boolean isMouseOnButton(int mouseX, int mouseY) { - return xPos <= mouseX && xPos + 18 > mouseX && yPos < mouseY && yPos + 18 >= mouseY; - } - - public void drawButton() { - - switch(buttonType) { - case 0: - drawTexturedModalRect(xPos, yPos, 176 + 18 * 0, 18 * 0, 18, 18); break; - case 1: - drawTexturedModalRect(xPos, yPos, 176 + 18 * 1, 18 * 0, 18, 18); break; - } - } - - public void drawString(int x, int y) { - if(info == null || info.isEmpty()) - return; - - String s = info; - - if(buttonType == 1) { - if(diFurnace.isOn) - s = "Turn Off"; - else - s = "Turn On"; - } - func_146283_a(Arrays.asList(new String[] { s }), x, y); + @Override + protected void mouseClicked(int x, int y, int i) { + super.mouseClicked(x, y, i); + + this.frequency.mouseClicked(x, y, i); + + if(guiLeft + 137 <= x && guiLeft + 137 + 18 > x && guiTop + 17 < y && guiTop + 17 + 18 >= y) { + mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); + NBTTagCompound data = new NBTTagCompound(); + data.setString("channel", this.frequency.getText()); + PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, radio.xCoord, radio.yCoord, radio.zCoord)); } - public void executeAction() { - + if(guiLeft + 173 <= x && guiLeft + 173 + 18 > x && guiTop + 17 < y && guiTop + 17 + 18 >= y) { mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); - - switch(buttonType) { - case 0: save(); break; - case 1: toggle(); break; - } + NBTTagCompound data = new NBTTagCompound(); + data.setBoolean("isOn", !radio.isOn); + PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, radio.xCoord, radio.yCoord, radio.zCoord)); } - } + } + + @Override + protected void keyTyped(char c, int i) { + + if(this.frequency.textboxKeyTyped(c, i)) + return; + + if(i == 1 || i == this.mc.gameSettings.keyBindInventory.getKeyCode()) { + this.mc.thePlayer.closeScreen(); + this.mc.setIngameFocus(); + } + } @Override public void onGuiClosed() { Keyboard.enableRepeatEvents(false); } + + @Override + public boolean doesGuiPauseGame() { + return false; + } } diff --git a/src/main/java/com/hbm/inventory/gui/GUIScreenRadioTorch.java b/src/main/java/com/hbm/inventory/gui/GUIScreenRadioTorch.java index df1a8441b..fb9f41afc 100644 --- a/src/main/java/com/hbm/inventory/gui/GUIScreenRadioTorch.java +++ b/src/main/java/com/hbm/inventory/gui/GUIScreenRadioTorch.java @@ -101,7 +101,6 @@ public class GUIScreenRadioTorch extends GuiScreen { } } - private void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); Minecraft.getMinecraft().getTextureManager().bindTexture(texture); diff --git a/src/main/java/com/hbm/packet/AuxButtonPacket.java b/src/main/java/com/hbm/packet/AuxButtonPacket.java index d7cff0d63..3cb163883 100644 --- a/src/main/java/com/hbm/packet/AuxButtonPacket.java +++ b/src/main/java/com/hbm/packet/AuxButtonPacket.java @@ -14,8 +14,6 @@ import com.hbm.tileentity.machine.TileEntityForceField; import com.hbm.tileentity.machine.TileEntityMachineMiningLaser; import com.hbm.tileentity.machine.TileEntityMachineMissileAssembly; import com.hbm.tileentity.machine.TileEntityMachineReactorLarge; -import com.hbm.tileentity.machine.TileEntityRadioRec; -import com.hbm.tileentity.machine.TileEntityReactorZirnox; import com.hbm.tileentity.machine.TileEntitySoyuzLauncher; import com.hbm.tileentity.machine.storage.TileEntityBarrel; import com.hbm.tileentity.machine.storage.TileEntityMachineBattery; @@ -81,18 +79,6 @@ public class AuxButtonPacket implements IMessage { //try { TileEntity te = p.worldObj.getTileEntity(m.x, m.y, m.z); - if (te instanceof TileEntityRadioRec) { - TileEntityRadioRec radio = (TileEntityRadioRec)te; - - if(m.id == 0) { - radio.isOn = (m.value == 1); - } - - if(m.id == 1) { - radio.freq = ((double)m.value) / 10D; - } - } - if (te instanceof TileEntityForceField) { TileEntityForceField field = (TileEntityForceField)te; diff --git a/src/main/java/com/hbm/packet/AuxGaugePacket.java b/src/main/java/com/hbm/packet/AuxGaugePacket.java index c7ef122a0..299dee72f 100644 --- a/src/main/java/com/hbm/packet/AuxGaugePacket.java +++ b/src/main/java/com/hbm/packet/AuxGaugePacket.java @@ -19,7 +19,6 @@ import com.hbm.tileentity.machine.TileEntityMachineElectricFurnace; import com.hbm.tileentity.machine.TileEntityMachineReactorLarge; import com.hbm.tileentity.machine.TileEntityMachineReactorLarge.ReactorFuelType; import com.hbm.tileentity.machine.TileEntityMachineSeleniumEngine; -import com.hbm.tileentity.machine.TileEntityRadioRec; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; @@ -129,14 +128,6 @@ public class AuxGaugePacket implements IMessage { if(m.id == 2) bomber.type = m.value; } - if (te instanceof TileEntityRadioRec) { - TileEntityRadioRec radio = (TileEntityRadioRec)te; - - if(m.id == 0) - radio.isOn = (m.value == 1); - if(m.id == 1) - radio.freq = ((double)m.value) / 10D; - } if (te instanceof TileEntityMachineBoiler) { TileEntityMachineBoiler boiler = (TileEntityMachineBoiler)te; @@ -206,10 +197,6 @@ public class AuxGaugePacket implements IMessage { launcher.padSize = PartSize.values()[m.value]; } - - - - if(te instanceof TileEntityMachineBase) { ((TileEntityMachineBase)te).processGauge(m.value, m.id); } diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityRadioRec.java b/src/main/java/com/hbm/tileentity/machine/TileEntityRadioRec.java index 474a695eb..7c1f7ea37 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityRadioRec.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityRadioRec.java @@ -1,31 +1,72 @@ package com.hbm.tileentity.machine; -import com.hbm.packet.AuxGaugePacket; -import com.hbm.packet.PacketDispatcher; +import com.hbm.interfaces.IControlReceiver; +import com.hbm.tileentity.INBTPacketReceiver; +import com.hbm.tileentity.network.RTTYSystem; +import com.hbm.tileentity.network.RTTYSystem.RTTYChannel; +import com.hbm.util.NoteBuilder; +import com.hbm.util.NoteBuilder.Instrument; +import com.hbm.util.NoteBuilder.Note; +import com.hbm.util.NoteBuilder.Octave; +import com.hbm.util.Tuple.Triplet; -import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -public class TileEntityRadioRec extends TileEntity { - - public double freq; +public class TileEntityRadioRec extends TileEntity implements INBTPacketReceiver, IControlReceiver { + + public String channel = ""; public boolean isOn = false; @Override public void updateEntity() { if(!worldObj.isRemote) { - PacketDispatcher.wrapper.sendToAllAround(new AuxGaugePacket(xCoord, yCoord, zCoord, isOn ? 1 : 0, 0), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50)); - PacketDispatcher.wrapper.sendToAllAround(new AuxGaugePacket(xCoord, yCoord, zCoord, (int)(freq * 10D), 1), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50)); + + if(this.isOn && !this.channel.isEmpty()) { + RTTYChannel chan = RTTYSystem.listen(worldObj, this.channel); + + if(chan != null && chan.timeStamp == worldObj.getTotalWorldTime() - 1) { + Triplet[] notes = NoteBuilder.translate(chan.signal + ""); + + for(Triplet note : notes) { + Instrument i = note.getX(); + Note n = note.getY(); + Octave o = note.getZ(); + + int noteId = n.ordinal() + o.ordinal() * 12; + String s = "harp"; + + if(i == Instrument.BASSDRUM) s = "bd"; + if(i == Instrument.SNARE) s = "snare"; + if(i == Instrument.CLICKS) s = "hat"; + if(i == Instrument.BASSGUITAR) s = "bassattack"; + + float f = (float)Math.pow(2.0D, (double)(noteId - 12) / 12.0D); + worldObj.playSoundEffect(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, "note." + s, 3.0F, f); + } + } + } + + NBTTagCompound data = new NBTTagCompound(); + data.setString("channel", channel); + data.setBoolean("isOn", isOn); + INBTPacketReceiver.networkPack(this, data, 15); } } + + @Override + public void networkUnpack(NBTTagCompound nbt) { + channel = nbt.getString("channel"); + isOn = nbt.getBoolean("isOn"); + } @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); - freq = nbt.getDouble("freq"); + channel = nbt.getString("channel"); isOn = nbt.getBoolean("isOn"); } @@ -33,7 +74,20 @@ public class TileEntityRadioRec extends TileEntity { public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); - nbt.setDouble("freq", freq); + nbt.setString("channel", channel); nbt.setBoolean("isOn", isOn); } + + @Override + public boolean hasPermission(EntityPlayer player) { + return player.getDistance(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 16D; + } + + @Override + public void receiveControl(NBTTagCompound data) { + if(data.hasKey("channel")) this.channel = data.getString("channel"); + if(data.hasKey("isOn")) this.isOn = data.getBoolean("isOn"); + + this.markDirty(); + } } diff --git a/src/main/java/com/hbm/tileentity/network/RTTYSystem.java b/src/main/java/com/hbm/tileentity/network/RTTYSystem.java index 03d7d050e..8fae1ef69 100644 --- a/src/main/java/com/hbm/tileentity/network/RTTYSystem.java +++ b/src/main/java/com/hbm/tileentity/network/RTTYSystem.java @@ -3,6 +3,10 @@ package com.hbm.tileentity.network; import java.util.HashMap; import java.util.Map.Entry; +import com.hbm.util.NoteBuilder; +import com.hbm.util.NoteBuilder.Instrument; +import com.hbm.util.NoteBuilder.Note; +import com.hbm.util.NoteBuilder.Octave; import com.hbm.util.Tuple.Pair; import net.minecraft.world.World; @@ -39,12 +43,21 @@ public class RTTYSystem { broadcast.put(identifier, channel); } + + for(Entry, RTTYChannel> entry : broadcast.entrySet()) { + World world = entry.getKey().getKey(); + RTTYChannel chan = new RTTYChannel(); + chan.timeStamp = world.getTotalWorldTime(); + chan.signal = getTestSender(chan.timeStamp); + broadcast.put(new Pair(world, "2012-08-06"), chan); + } + newMessages.clear(); } public static class RTTYChannel { - long timeStamp = -1; //the totalWorldTime at the time of publishing, happens in the server tick event's PRE-phase. the publishing timestamp is that same number minus one - Object signal; // a signal can be anything, a number, an encoded string, an entire blue whale, Steve from accounting, the concept of death, 7492 hot dogs, etc. + public long timeStamp = -1; //the totalWorldTime at the time of publishing, happens in the server tick event's PRE-phase. the publishing timestamp is that same number minus one + public Object signal; // a signal can be anything, a number, an encoded string, an entire blue whale, Steve from accounting, the concept of death, 7492 hot dogs, etc. } /* Special objects for signifying specific signals to be used with RTTY machines (or telex) */ @@ -53,4 +66,111 @@ public class RTTYSystem { STOP_TTY, //end the message block PRINT_BUFFER //print message, literally, it makes a paper printout } + + public static Object getTestSender(long timeStamp) { + + int tempo = 4; + int time = (int) (timeStamp % (tempo * 160)); + + Instrument flute = Instrument.PIANO; + Instrument accordion = Instrument.BASSGUITAR; + + if(time == tempo * 0) return NoteBuilder.start().add(accordion, Note.C, Octave.LOW).end(); + if(time == tempo * 2) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.LOW).end(); + if(time == tempo * 4) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.LOW).end(); + + if(time == tempo * 6) return NoteBuilder.start().add(accordion, Note.C, Octave.LOW).end(); + if(time == tempo * 8) return NoteBuilder.start().add(accordion, Note.E, Octave.LOW).add(accordion, Note.G, Octave.LOW).add(accordion, Note.B, Octave.LOW).end(); + + if(time == tempo * 12) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).end(); + if(time == tempo * 14) return NoteBuilder.start().add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.LOW).add(accordion, Note.C, Octave.MID).end(); + if(time == tempo * 16) return NoteBuilder.start().add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.LOW).add(accordion, Note.C, Octave.MID).end(); + + if(time == tempo * 18) return NoteBuilder.start().add(accordion, Note.C, Octave.LOW).end(); + if(time == tempo * 20) return NoteBuilder.start().add(accordion, Note.E, Octave.LOW).add(accordion, Note.G, Octave.LOW).add(accordion, Note.B, Octave.LOW).end(); + + if(time == tempo * 24) return NoteBuilder.start().add(accordion, Note.C, Octave.LOW).end(); + if(time == tempo * 26) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.LOW).end(); + if(time == tempo * 28) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.LOW).end(); + // + if(time == tempo * 30) return NoteBuilder.start().add(accordion, Note.C, Octave.LOW).end(); + if(time == tempo * 32) return NoteBuilder.start().add(accordion, Note.E, Octave.LOW).add(accordion, Note.G, Octave.LOW).add(accordion, Note.B, Octave.LOW).end(); + + if(time == tempo * 36) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).end(); + if(time == tempo * 38) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.LOW).end(); + if(time == tempo * 40) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.LOW).end(); + + if(time == tempo * 42) return NoteBuilder.start().add(accordion, Note.C, Octave.LOW).end(); + if(time == tempo * 44) return NoteBuilder.start().add(accordion, Note.E, Octave.LOW).add(accordion, Note.G, Octave.LOW).add(accordion, Note.B, Octave.LOW).end(); + + if(time == tempo * 48) return NoteBuilder.start().add(accordion, Note.C, Octave.LOW).add(flute, Note.D, Octave.LOW).end(); + if(time == tempo * 50) return NoteBuilder.start().add(flute, Note.F, Octave.LOW).end(); + if(time == tempo * 52) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.LOW).add(flute, Note.D, Octave.MID).end(); + if(time == tempo * 54) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.LOW); + + if(time == tempo * 56) return NoteBuilder.start().add(accordion, Note.C, Octave.LOW).add(flute, Note.D, Octave.LOW).end(); + if(time == tempo * 58) return NoteBuilder.start().add(flute, Note.F, Octave.LOW).end(); + if(time == tempo * 60) return NoteBuilder.start().add(accordion, Note.E, Octave.LOW).add(accordion, Note.G, Octave.LOW).add(accordion, Note.B, Octave.LOW).add(flute, Note.D, Octave.MID).end(); + + if(time == tempo * 64) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(flute, Note.E, Octave.MID).end(); + if(time == tempo * 66) return NoteBuilder.start().add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.LOW).add(accordion, Note.C, Octave.MID).end(); + if(time == tempo * 67) return NoteBuilder.start().add(flute, Note.F, Octave.MID).end(); + if(time == tempo * 68) return NoteBuilder.start().add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.LOW).add(accordion, Note.C, Octave.MID).add(flute, Note.E, Octave.MID).end(); + if(time == tempo * 69) return NoteBuilder.start().add(flute, Note.F, Octave.MID).end(); + // + if(time == tempo * 70) return NoteBuilder.start().add(accordion, Note.C, Octave.LOW).add(flute, Note.E, Octave.MID).end(); + if(time == tempo * 71) return NoteBuilder.start().add(flute, Note.B, Octave.MID).end(); + if(time == tempo * 72) return NoteBuilder.start().add(accordion, Note.E, Octave.LOW).add(accordion, Note.G, Octave.LOW).add(accordion, Note.B, Octave.LOW).add(flute, Note.A, Octave.MID).end(); + + if(time == tempo * 76) return NoteBuilder.start().add(accordion, Note.G, Octave.LOW).add(flute, Note.A, Octave.MID).end(); + if(time == tempo * 78) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.B, Octave.MID).add(flute, Note.D, Octave.LOW).end(); + if(time == tempo * 80) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.B, Octave.MID).add(flute, Note.F, Octave.LOW).end(); + if(time == tempo * 81) return NoteBuilder.start().add(flute, Note.G, Octave.MID).end(); + + if(time == tempo * 82) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(flute, Note.A, Octave.MID).end(); + if(time == tempo * 84) return NoteBuilder.start().add(accordion, Note.C, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.LOW).end(); + + if(time == tempo * 88) return NoteBuilder.start().add(accordion, Note.G, Octave.LOW).add(flute, Note.A, Octave.MID).end(); + if(time == tempo * 90) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.B, Octave.MID).add(flute, Note.D, Octave.LOW).end(); + if(time == tempo * 92) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.B, Octave.MID).add(flute, Note.F, Octave.LOW).end(); + if(time == tempo * 93) return NoteBuilder.start().add(accordion, Note.B, Octave.MID).add(flute, Note.G, Octave.MID).end(); + + if(time == tempo * 94) return NoteBuilder.start().add(accordion, Note.F, Octave.LOW).add(flute, Note.E, Octave.LOW).end(); + if(time == tempo * 96) return NoteBuilder.start().add(accordion, Note.C, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.LOW).end(); + + if(time == tempo * 100) return NoteBuilder.start().add(accordion, Note.C, Octave.LOW).add(flute, Note.D, Octave.LOW).end(); + if(time == tempo * 101) return NoteBuilder.start().add(flute, Note.F, Octave.LOW).end(); + if(time == tempo * 102) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.B, Octave.MID).add(flute, Note.D, Octave.MID).end(); + if(time == tempo * 104) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.B, Octave.MID).end(); + // + if(time == tempo * 106) return NoteBuilder.start().add(accordion, Note.C, Octave.LOW).add(flute, Note.D, Octave.LOW).end(); + if(time == tempo * 107) return NoteBuilder.start().add(flute, Note.F, Octave.LOW).end(); + if(time == tempo * 108) return NoteBuilder.start().add(accordion, Note.E, Octave.LOW).add(accordion, Note.G, Octave.LOW).add(accordion, Note.B, Octave.MID).add(flute, Note.D, Octave.MID).end(); + + if(time == tempo * 112) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(flute, Note.E, Octave.MID).end(); + if(time == tempo * 114) return NoteBuilder.start().add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.LOW).add(accordion, Note.C, Octave.MID).end(); + if(time == tempo * 115) return NoteBuilder.start().add(flute, Note.F, Octave.MID).end(); + if(time == tempo * 116) return NoteBuilder.start().add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.LOW).add(accordion, Note.C, Octave.MID).add(flute, Note.E, Octave.MID).end(); + if(time == tempo * 117) return NoteBuilder.start().add(flute, Note.F, Octave.MID).end(); + + if(time == tempo * 118) return NoteBuilder.start().add(accordion, Note.C, Octave.LOW).add(flute, Note.E, Octave.MID).end(); + if(time == tempo * 119) return NoteBuilder.start().add(flute, Note.C, Octave.MID).end(); + if(time == tempo * 120) return NoteBuilder.start().add(accordion, Note.E, Octave.LOW).add(accordion, Note.G, Octave.LOW).add(accordion, Note.B, Octave.MID).add(flute, Note.A, Octave.MID).end(); + + if(time == tempo * 124) return NoteBuilder.start().add(accordion, Note.G, Octave.LOW).add(flute, Note.A, Octave.MID).end(); + if(time == tempo * 126) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.MID).add(flute, Note.D, Octave.LOW).end(); + if(time == tempo * 128) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.MID).add(flute, Note.F, Octave.LOW).end(); + if(time == tempo * 129) return NoteBuilder.start().add(flute, Note.G, Octave.MID).end(); + + if(time == tempo * 130) return NoteBuilder.start().add(accordion, Note.F, Octave.LOW).add(flute, Note.A, Octave.MID).end(); + if(time == tempo * 132) return NoteBuilder.start().add(accordion, Note.C, Octave.LOW).add(accordion, Note.E, Octave.LOW).add(accordion, Note.A, Octave.MID).add(accordion, Note.G, Octave.LOW).end(); + if(time == tempo * 134) return NoteBuilder.start().add(flute, Note.A, Octave.MID).end(); + + if(time == tempo * 136) return NoteBuilder.start().add(accordion, Note.C, Octave.LOW).add(flute, Note.D, Octave.LOW).end(); + if(time == tempo * 138) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.MID).end(); + if(time == tempo * 140) return NoteBuilder.start().add(accordion, Note.D, Octave.LOW).add(accordion, Note.F, Octave.LOW).add(accordion, Note.A, Octave.MID).end(); + + + return ""; + } } diff --git a/src/main/java/com/hbm/tileentity/network/TileEntityRadioTorchReceiver.java b/src/main/java/com/hbm/tileentity/network/TileEntityRadioTorchReceiver.java index 4d31f298f..1d2dd4d34 100644 --- a/src/main/java/com/hbm/tileentity/network/TileEntityRadioTorchReceiver.java +++ b/src/main/java/com/hbm/tileentity/network/TileEntityRadioTorchReceiver.java @@ -11,37 +11,38 @@ public class TileEntityRadioTorchReceiver extends TileEntityRadioTorchBase { if(!worldObj.isRemote) { - if(this.channel.isEmpty()) return; - - RTTYChannel chan = RTTYSystem.listen(worldObj, this.channel); - - if(chan != null && (this.polling || (chan.timeStamp > this.lastUpdate - 1 && chan.timeStamp != -1))) { // if we're either polling or a new message has come in - String msg = "" + chan.signal; - this.lastUpdate = worldObj.getTotalWorldTime(); - int nextState = 0; //if no remap apply, default to 0 + if(!this.channel.isEmpty()) { - if(this.customMap) { - for(int i = 15; i >= 0; i--) { // highest to lowest, if duplicates exist for some reason - if(msg.equals(this.mapping[i])) { - nextState = i; - break; + RTTYChannel chan = RTTYSystem.listen(worldObj, this.channel); + + if(chan != null && (this.polling || (chan.timeStamp > this.lastUpdate - 1 && chan.timeStamp != -1))) { // if we're either polling or a new message has come in + String msg = "" + chan.signal; + this.lastUpdate = worldObj.getTotalWorldTime(); + int nextState = 0; //if no remap apply, default to 0 + + if(this.customMap) { + for(int i = 15; i >= 0; i--) { // highest to lowest, if duplicates exist for some reason + if(msg.equals(this.mapping[i])) { + nextState = i; + break; + } } + } else { + int sig = 0; + try { sig = Integer.parseInt(msg); } catch(Exception x) { }; + nextState = MathHelper.clamp_int(sig, 0, 15); + } + + if(chan.timeStamp < this.lastUpdate - 2 && this.polling) { + nextState = 0; + } + + if(this.lastState != nextState) { + this.lastState = nextState; + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, this.getBlockType()); + this.markDirty(); } - } else { - int sig = 0; - try { sig = Integer.parseInt(msg); } catch(Exception x) { }; - nextState = MathHelper.clamp_int(sig, 0, 15); - } - - if(chan.timeStamp < this.lastUpdate - 2 && this.polling) { - nextState = 0; - } - - if(this.lastState != nextState) { - this.lastState = nextState; - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, this.getBlockType()); - this.markDirty(); } } } diff --git a/src/main/java/com/hbm/util/NoteBuilder.java b/src/main/java/com/hbm/util/NoteBuilder.java new file mode 100644 index 000000000..ac04c94dd --- /dev/null +++ b/src/main/java/com/hbm/util/NoteBuilder.java @@ -0,0 +1,74 @@ +package com.hbm.util; + +import com.hbm.util.Tuple.Triplet; + +public class NoteBuilder { + + private String beat = ""; + + public static NoteBuilder start() { + return new NoteBuilder(); + } + + public NoteBuilder add(Instrument instrument, Note note, Octave octave) { + if(!beat.isEmpty()) + beat += "-"; + + String result = instrument.ordinal() + ":" + note.ordinal() + ":" + octave.ordinal(); + + beat += result; + + return this; + } + + public String end() { + return beat; + } + + public static Triplet[] translate(String beat) { + String[] hits = beat.split("-"); + Triplet[] notes = new Triplet[hits.length]; + + try { + for(int i = 0; i < hits.length; i++) { + String[] components = hits[i].split(":"); + Instrument instrument = Instrument.values()[Integer.parseInt(components[0])]; + Note note = Note.values()[Integer.parseInt(components[1])]; + Octave octave = Octave.values()[Integer.parseInt(components[2])]; + + notes[i] = new Triplet(instrument, note, octave); + } + + return notes; + } catch(Exception ex) { + return new Triplet[0]; + } + } + + public static enum Instrument { + PIANO, + BASSDRUM, + SNARE, + CLICKS, + BASSGUITAR; + } + + public static enum Note { + F_SHARP, + G, + G_SHARP, + A, + A_SHARP, + B, + C, + C_SHARP, + D, + D_SHARP, + E, + F; + } + + public static enum Octave { + LOW, MID, HIGH; + } +} diff --git a/src/main/resources/assets/hbm/textures/gui/gui_radiorec.png b/src/main/resources/assets/hbm/textures/gui/gui_radiorec.png deleted file mode 100644 index e2022e4576e29ab605c3b1e4a025cd5131a0135a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1132 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6%N?Bp530R%N1DIGwrvZsq< zNX4ADcQjKeUdhRXUkth1*qS=Fl)bv}@{Z;OaShhs$`>M)uhmX4i&%LV z%Q?z1$^B(fyr8$NvhnqT6=id7O~$r9>C2;Y^M6?>)&1JR zod5W2$!Xp<_Z)Bhd^zK3k!0f0TO9|_vY$J5?$!)uGqc%eAH8^?@$B=@cS;-T%Kq2w z+AP15dp^s7bN<(Ti_jT*p~<#Gn;);UG{oI}5?g0q^Sy)jd(QFrVh)DRw<)XzH8p#_ znyp&Z^|9j40h8b6=esYinE3Y1?9Eq0tKV##E6WrTy7lUJf3?YO`eC=WS5_=JeYt(_ z_Wxqb^B0$=|1f_j!!S2&Utin11D97y|1>#f$>8C`pkT<@aD;_HNSFX;^yVfmW(tPaL(f`ML|UyF8rIo+CaO}oKJsy9lOMefkuhFOK5#Ur*GvD(a;D-TSd z0}2*gK2>0`=C<6T%+S!ICr^52R`cB`PqmP_R{!r~_3dJlXNRBeuCS|(69*EC2s{zsePmHi<)cLfOdWUczWA&hA4vw9kGoO zI=AL64h#+5YRgpOB+1wQHGluV8{cGlEp2KZ^*L-<`2QV8NyU#PXDy{ZADtc#Qq>mD tNOWX79(m>E5Ps3o?i~jU5n=66^`FVYXsNY|Y2Y=Ga!*%3mvv4FO#r(;uzmml diff --git a/src/main/resources/assets/hbm/textures/gui/machine/gui_radio.png b/src/main/resources/assets/hbm/textures/gui/machine/gui_radio.png new file mode 100644 index 0000000000000000000000000000000000000000..014cf8d503277e893aa8c421be602902d84e149f GIT binary patch literal 1068 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6%N?Bp530R%N1DIE+9%#S@? z978JRyuG_I@3xx+`-lFv<2-r_3;Hj-;bp4mGAYYqK9YPvRe$306O%SFclT5^6Bd-}lZXCzSTBVzOvi^q$WovUJU_ zg0JhY_Z^6sYhNvCctOB|vss?+)!W(E1)0}w=w88kAilo-&3bbKr||dF1qBV~pI2rJ zbPNbw;+`F*$jaeDoJ+Yoz;hH(4;6PC<%zh85GXYVGR z$4C30b5drAQ*e#d#&o{dL zSD5<0D>MI=?+RuOnE&v0+Mi`*7Im9nemTv*)$!_>;Ny~YrsH{H`NYSt=Qxwyz_8znBB+p_TM^BJOofweoT z#0B&C`PvJ<{;PU4`}}jk>&bZrF~R~yY77d=ObmP(q5t@=X1a(xKOYyCe}9i$O?u-N zvvQ9RadGjzr7XvCI;{=?Atu9H)`Ald0Gr7W-v7LaN?(K+&j;-<0MnhY%Yc(v$=k&ckB}ixULV(FGC$z btoYA(e6xai3s2lSkY7Aq{an^LB{Ts5E5?0= literal 0 HcmV?d00001