return of the radio

This commit is contained in:
Bob 2022-12-12 22:39:07 +01:00
parent beee798c70
commit 2ff7052ca3
14 changed files with 437 additions and 365 deletions

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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<RadioButton> buttons = new ArrayList<RadioButton>();
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;
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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);
}

View File

@ -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<Instrument, Note, Octave>[] notes = NoteBuilder.translate(chan.signal + "");
for(Triplet<Instrument, Note, Octave> 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();
}
}

View File

@ -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<Pair<World, String>, 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 "";
}
}

View File

@ -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();
}
}
}

View File

@ -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<Instrument, Note, Octave>[] translate(String beat) {
String[] hits = beat.split("-");
Triplet<Instrument, Note, Octave>[] 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;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB