From ce34f9ca778522d8c54bdd3968ce1ea506edc60e Mon Sep 17 00:00:00 2001 From: Bob Date: Sat, 26 Nov 2022 23:47:47 +0100 Subject: [PATCH] some more fluid stuff, funny torches --- src/main/java/api/hbm/energy/IPowerNet.java | 2 - .../hbm/blocks/network/RadioTorchBase.java | 21 +++ .../blocks/network/RadioTorchReceiver.java | 23 +++- .../hbm/blocks/network/RadioTorchSender.java | 4 - .../inventory/gui/GUIScreenRadioTorch.java | 71 ++++++++-- src/main/java/com/hbm/main/ClientProxy.java | 9 -- src/main/java/com/hbm/main/ServerProxy.java | 6 - .../com/hbm/render/block/RenderBoxDuct.java | 2 +- .../java/com/hbm/render/block/RenderRTTY.java | 14 +- .../java/com/hbm/sound/nt/ISoundSourceTE.java | 22 --- src/main/java/com/hbm/sound/nt/SoundTE.java | 128 ------------------ .../java/com/hbm/sound/nt/SoundWrapper.java | 6 - .../com/hbm/sound/nt/SoundWrapperClient.java | 19 --- .../machine/TileEntityCondenser.java | 3 +- .../machine/TileEntityMachineBoiler.java | 3 +- .../TileEntityMachineReactorLarge.java | 4 +- .../machine/TileEntitySolarBoiler.java | 3 +- .../TileEntityMachineCatalyticCracker.java | 3 +- .../oil/TileEntityMachineFractionTower.java | 3 +- .../machine/rbmk/TileEntityHeatex.java | 4 +- .../machine/rbmk/TileEntityRBMKBase.java | 3 +- .../machine/rbmk/TileEntityRBMKInlet.java | 3 +- .../machine/rbmk/TileEntityRBMKOutlet.java | 3 +- .../hbm/tileentity/network/RTTYSystem.java | 5 + .../network/TileEntityPipeBaseNT.java | 6 + .../network/TileEntityRadioTorchBase.java | 64 ++++++++- .../network/TileEntityRadioTorchReceiver.java | 46 +++++++ .../network/TileEntityRadioTorchSender.java | 25 ++++ 28 files changed, 278 insertions(+), 227 deletions(-) delete mode 100644 src/main/java/com/hbm/sound/nt/ISoundSourceTE.java delete mode 100644 src/main/java/com/hbm/sound/nt/SoundTE.java delete mode 100644 src/main/java/com/hbm/sound/nt/SoundWrapper.java delete mode 100644 src/main/java/com/hbm/sound/nt/SoundWrapperClient.java diff --git a/src/main/java/api/hbm/energy/IPowerNet.java b/src/main/java/api/hbm/energy/IPowerNet.java index 2c9fc6781..4b82df2e9 100644 --- a/src/main/java/api/hbm/energy/IPowerNet.java +++ b/src/main/java/api/hbm/energy/IPowerNet.java @@ -23,8 +23,6 @@ public interface IPowerNet { /** * When a link is removed, instead of destroying the network, causing it to be recreated from currently loaded conductors, * we re-evaluate it, creating new nets based on the previous links. - * - * NYI */ public void reevaluate(); diff --git a/src/main/java/com/hbm/blocks/network/RadioTorchBase.java b/src/main/java/com/hbm/blocks/network/RadioTorchBase.java index 325990efa..2a57515e7 100644 --- a/src/main/java/com/hbm/blocks/network/RadioTorchBase.java +++ b/src/main/java/com/hbm/blocks/network/RadioTorchBase.java @@ -1,10 +1,12 @@ package com.hbm.blocks.network; import com.hbm.inventory.gui.GUIScreenRadioTorch; +import com.hbm.main.MainRegistry; import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.network.TileEntityRadioTorchBase; import cpw.mods.fml.client.registry.RenderingRegistry; +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; @@ -13,10 +15,13 @@ import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public abstract class RadioTorchBase extends BlockContainer implements IGUIProvider { + + @SideOnly(Side.CLIENT) protected IIcon iconOn; public RadioTorchBase() { super(Material.circuits); @@ -45,10 +50,26 @@ public abstract class RadioTorchBase extends BlockContainer implements IGUIProvi return true; } + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(int side, int metadata) { + return side == 0 ? this.blockIcon : this.iconOn; + } + @Override public int onBlockPlaced(World world, int x, int y, int z, int side, float fX, float fY, float fZ, int meta) { return side; } + + @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()) { + FMLNetworkHandler.openGui(player, MainRegistry.instance, 0, world, x, y, z); + return true; + } else { + return !player.isSneaking(); + } + } @Override public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) { return null; } diff --git a/src/main/java/com/hbm/blocks/network/RadioTorchReceiver.java b/src/main/java/com/hbm/blocks/network/RadioTorchReceiver.java index 19a1bb7d5..1d1d7df14 100644 --- a/src/main/java/com/hbm/blocks/network/RadioTorchReceiver.java +++ b/src/main/java/com/hbm/blocks/network/RadioTorchReceiver.java @@ -7,13 +7,10 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class RadioTorchReceiver extends RadioTorchBase { - - @SideOnly(Side.CLIENT) - protected IIcon iconOn; public RadioTorchReceiver() { super(); @@ -30,4 +27,22 @@ public class RadioTorchReceiver extends RadioTorchBase { public TileEntity createNewTileEntity(World world, int meta) { return new TileEntityRadioTorchReceiver(); } + + @Override + public boolean canProvidePower() { + return true; + } + + @Override + public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side) { + + TileEntity tile = world.getTileEntity(x, y, z); + + if(tile instanceof TileEntityRadioTorchReceiver) { + int state = ((TileEntityRadioTorchReceiver) tile).lastState; + return state; + } + + return 0; + } } diff --git a/src/main/java/com/hbm/blocks/network/RadioTorchSender.java b/src/main/java/com/hbm/blocks/network/RadioTorchSender.java index fa7aaf25a..2e5a675d4 100644 --- a/src/main/java/com/hbm/blocks/network/RadioTorchSender.java +++ b/src/main/java/com/hbm/blocks/network/RadioTorchSender.java @@ -7,13 +7,9 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; import net.minecraft.world.World; public class RadioTorchSender extends RadioTorchBase { - - @SideOnly(Side.CLIENT) - protected IIcon iconOn; public RadioTorchSender() { super(); diff --git a/src/main/java/com/hbm/inventory/gui/GUIScreenRadioTorch.java b/src/main/java/com/hbm/inventory/gui/GUIScreenRadioTorch.java index 422ebe9f3..df1a8441b 100644 --- a/src/main/java/com/hbm/inventory/gui/GUIScreenRadioTorch.java +++ b/src/main/java/com/hbm/inventory/gui/GUIScreenRadioTorch.java @@ -1,23 +1,29 @@ package com.hbm.inventory.gui; +import java.util.Arrays; + 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.TileEntityRadioTorchBase; import com.hbm.tileentity.network.TileEntityRadioTorchSender; 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.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; public class GUIScreenRadioTorch extends GuiScreen { protected ResourceLocation texture; - protected static final ResourceLocation textureSender = new ResourceLocation(RefStrings.MODID + ":textures/gui/machine/gui_rtty_sender.png"); - protected static final ResourceLocation textureReceiver = new ResourceLocation(RefStrings.MODID + ":textures/gui/machine/gui_rtty_receiver.png"); + protected static final ResourceLocation textureSender = new ResourceLocation(RefStrings.MODID + ":textures/gui/machine/gui_rtty_sender.png"); + protected static final ResourceLocation textureReceiver = new ResourceLocation(RefStrings.MODID + ":textures/gui/machine/gui_rtty_receiver.png"); protected TileEntityRadioTorchBase radio; protected String title = ""; protected int xSize = 256; @@ -47,25 +53,25 @@ public class GUIScreenRadioTorch extends GuiScreen { Keyboard.enableRepeatEvents(true); - int oX = 2; - int oY = 2; + int oX = 4; + int oY = 4; int in = radio instanceof TileEntityRadioTorchSender ? 18 : 0; - this.frequency = new GuiTextField(this.fontRendererObj, guiLeft + 25 + oX, guiTop + 17 + oY, 90, 14); + 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(25); + this.frequency.setMaxStringLength(10); this.frequency.setText(radio.channel == null ? "" : radio.channel); this.remap = new GuiTextField[16]; for(int i = 0; i < 16; i++) { - this.remap[i] = new GuiTextField(this.fontRendererObj, guiLeft + 7 + (130 * (i / 8)) + oX + in, guiTop + 53 + (18 * (i % 8)) + oY, 50, 14); + this.remap[i] = new GuiTextField(this.fontRendererObj, guiLeft + 7 + (130 * (i / 8)) + oX + in, guiTop + 53 + (18 * (i % 8)) + oY, 90 - oX * 2, 14); this.remap[i].setTextColor(0x00ff00); this.remap[i].setDisabledTextColour(0x00ff00); this.remap[i].setEnableBackgroundDrawing(false); - this.remap[i].setMaxStringLength(25); + this.remap[i].setMaxStringLength(15); this.remap[i].setText(radio.mapping[i] == null ? "" : radio.mapping[i]); } } @@ -80,9 +86,19 @@ public class GUIScreenRadioTorch extends GuiScreen { } - private void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + private void drawGuiContainerForegroundLayer(int x, int y) { String name = I18nUtil.resolveKey(this.title); - this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752); + 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[] { radio.customMap ? "Custom Mapping" : "Redstone Passthrough" }), x, y); + } + if(guiLeft + 173 <= x && guiLeft + 173 + 18 > x && guiTop + 17 < y && guiTop + 17 + 18 >= y) { + func_146283_a(Arrays.asList(new String[] { radio.polling ? "Polling" : "State Change" }), x, y); + } + if(guiLeft + 209 <= x && guiLeft + 209 + 18 > x && guiTop + 17 < y && guiTop + 17 + 18 >= y) { + func_146283_a(Arrays.asList(new String[] { "Save Settings" }), x, y); + } } @@ -92,12 +108,15 @@ public class GUIScreenRadioTorch extends GuiScreen { if(radio.customMap) { drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); + drawTexturedModalRect(guiLeft + 137, guiTop + 17, 0, 204, 18, 18); + if(radio.polling) drawTexturedModalRect(guiLeft + 173, guiTop + 17, 0, 222, 18, 18); for(int j = 0; j < 16; j++) { this.remap[j].drawTextBox(); } } else { drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, 35); drawTexturedModalRect(guiLeft, guiTop + 35, 0, 197, xSize, 7); + if(radio.polling) drawTexturedModalRect(guiLeft + 173, guiTop + 17, 0, 222, 18, 18); } this.frequency.drawTextBox(); @@ -112,6 +131,28 @@ public class GUIScreenRadioTorch extends GuiScreen { if(radio.customMap) { for(int j = 0; j < 16; j++) this.remap[j].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.setBoolean("m", !radio.customMap); + PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, radio.xCoord, radio.yCoord, radio.zCoord)); + } + + 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)); + NBTTagCompound data = new NBTTagCompound(); + data.setBoolean("p", !radio.polling); + PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, radio.xCoord, radio.yCoord, radio.zCoord)); + } + + if(guiLeft + 209 <= x && guiLeft + 209 + 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("c", this.frequency.getText()); + for(int j = 0; j < 16; j++) data.setString("m" + j, this.remap[j].getText()); + PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, radio.xCoord, radio.yCoord, radio.zCoord)); + } } @Override @@ -124,11 +165,19 @@ public class GUIScreenRadioTorch extends GuiScreen { for(int j = 0; j < 16; j++) if(this.remap[j].textboxKeyTyped(c, i)) return; } - super.keyTyped(c, i); + 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/main/ClientProxy.java b/src/main/java/com/hbm/main/ClientProxy.java index 84e6418b8..fc4efe35b 100644 --- a/src/main/java/com/hbm/main/ClientProxy.java +++ b/src/main/java/com/hbm/main/ClientProxy.java @@ -85,9 +85,6 @@ import com.hbm.render.util.RenderOverhead.Marker; import com.hbm.sound.AudioWrapper; import com.hbm.sound.AudioWrapperClient; import com.hbm.sound.AudioWrapperClientStartStop; -import com.hbm.sound.nt.ISoundSourceTE; -import com.hbm.sound.nt.SoundWrapper; -import com.hbm.sound.nt.SoundWrapperClient; import com.hbm.tileentity.TileEntityDoorGeneric; import com.hbm.tileentity.bomb.*; import com.hbm.tileentity.conductor.*; @@ -1819,12 +1816,6 @@ public class ClientProxy extends ServerProxy { audio.updatePosition(x, y, z); return audio; } - - @Override - public SoundWrapper getTileSound(String sound, ISoundSourceTE tile) { - SoundWrapperClient wrapper = new SoundWrapperClient(sound, tile); - return wrapper; - } @Override public void playSound(String sound, Object data) { } diff --git a/src/main/java/com/hbm/main/ServerProxy.java b/src/main/java/com/hbm/main/ServerProxy.java index 4bdbc446b..d479b8790 100644 --- a/src/main/java/com/hbm/main/ServerProxy.java +++ b/src/main/java/com/hbm/main/ServerProxy.java @@ -6,8 +6,6 @@ import java.util.List; import com.hbm.handler.HbmKeybinds.EnumKeybind; import com.hbm.saveddata.TomSaveData; import com.hbm.sound.AudioWrapper; -import com.hbm.sound.nt.ISoundSourceTE; -import com.hbm.sound.nt.SoundWrapper; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -66,10 +64,6 @@ public class ServerProxy { public void openLink(String url) { } - public SoundWrapper getTileSound(String sound, ISoundSourceTE source) { - return new SoundWrapper(); - } - public List getSubItems(ItemStack stack) { List list = new ArrayList(); diff --git a/src/main/java/com/hbm/render/block/RenderBoxDuct.java b/src/main/java/com/hbm/render/block/RenderBoxDuct.java index 0fa600fc9..6707b938c 100644 --- a/src/main/java/com/hbm/render/block/RenderBoxDuct.java +++ b/src/main/java/com/hbm/render/block/RenderBoxDuct.java @@ -68,7 +68,7 @@ public class RenderBoxDuct implements ISimpleBlockRenderingHandler { if(te instanceof TileEntityPipeBaseNT) { TileEntityPipeBaseNT pipe = (TileEntityPipeBaseNT) te; type = pipe.getType(); - if(meta == 2) { + if(meta % 3 == 2) { FluidDuctBox.cachedColor = type.getColor(); } } diff --git a/src/main/java/com/hbm/render/block/RenderRTTY.java b/src/main/java/com/hbm/render/block/RenderRTTY.java index 24858ce6a..0f657c636 100644 --- a/src/main/java/com/hbm/render/block/RenderRTTY.java +++ b/src/main/java/com/hbm/render/block/RenderRTTY.java @@ -3,11 +3,13 @@ package com.hbm.render.block; import com.hbm.blocks.network.RadioTorchBase; import com.hbm.main.ResourceManager; import com.hbm.render.util.ObjUtil; +import com.hbm.tileentity.network.TileEntityRadioTorchBase; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraftforge.client.model.obj.WavefrontObject; @@ -25,8 +27,18 @@ public class RenderRTTY implements ISimpleBlockRenderingHandler { tessellator.setBrightness(brightness); tessellator.setColorOpaque_F(1, 1, 1); - IIcon icon = block.getIcon(world, x, y, z, 0); + IIcon icon = block.getIcon(0, 0); int meta = world.getBlockMetadata(x, y, z); + + TileEntity tile = world.getTileEntity(x, y, z); + + if(tile instanceof TileEntityRadioTorchBase) { + TileEntityRadioTorchBase rtty = (TileEntityRadioTorchBase) tile; + + if(rtty.lastState > 0) { + icon = block.getIcon(1, 0); + } + } float flip = 0; float rotation = 0; diff --git a/src/main/java/com/hbm/sound/nt/ISoundSourceTE.java b/src/main/java/com/hbm/sound/nt/ISoundSourceTE.java deleted file mode 100644 index c5f1eacee..000000000 --- a/src/main/java/com/hbm/sound/nt/ISoundSourceTE.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.hbm.sound.nt; - -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Vec3; - -public interface ISoundSourceTE { - - public boolean isPlaying(); - - public default Vec3 getSoundLocation() { - TileEntity te = (TileEntity) this; - return Vec3.createVectorHelper(te.xCoord + 0.5, te.yCoord + 0.5, te.zCoord + 0.5); - } - - public default float getVolume() { - return 1F; - } - - public default float getPitch() { - return 1F; - } -} diff --git a/src/main/java/com/hbm/sound/nt/SoundTE.java b/src/main/java/com/hbm/sound/nt/SoundTE.java deleted file mode 100644 index 47abc44af..000000000 --- a/src/main/java/com/hbm/sound/nt/SoundTE.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.hbm.sound.nt; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.client.Minecraft; -import net.minecraft.client.audio.ISound; -import net.minecraft.client.audio.SoundHandler; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.Vec3; - -/** - * I have a dream. That one day every tile entity in this codebase will control their - * own sounds. A codebase of the truly free, dammit. A codebase of functionality, not - * patterns, ruled by necessity, not chance! Where the code changes to suit the use - * case, not the other way around. Where methods and fields are back where they belong: - * in the hands of the tile entities! Where every object is free to think - to calcilate - * - for itself! Fuck all these limp-dick programmers and chickenshit coders. Fuck this - * 24-hour Internet spew of design classes and Stack Overflow bullshit! Fuck duct tape - * pride! Fuck the patterns! FUCK ALL OF IT! NTM is diseased. Rotten to the core. - * There's no saving it - we need to pull it out by the classroot. Wipe the slate clean. - * BURN IT DOWN! And from the ashes, the mother of all omelettes will be born. Evolved, - * but unconventional! The broken will be purged and the cleanest will thrive - free to - * function as they see fit, they'll make NTM great again! ...in my new NTM, tile - * entities will expire and invalidate for what they BELIEVE! Not for memory space, not - * for compatibility! Not for what they're told is professional. Every tile will be free - * to load its own chunks! - * @author hbm - * - */ -@SideOnly(Side.CLIENT) -public class SoundTE implements ISound { - - ISoundSourceTE source; - - private ResourceLocation sound; - private boolean canRepeat = true; - private int repeatDelay = 0; - private float soundX; - private float soundY; - private float soundZ; - private float volume; - private float pitch; - - private boolean isSoundOn = false; - - public SoundTE(String sound, ISoundSourceTE source) { - this.sound = new ResourceLocation(sound); - this.source = source; - } - - @Override - public ResourceLocation getPositionedSoundLocation() { - return this.sound; - } - - @Override - public boolean canRepeat() { - return this.canRepeat; - } - - @Override - public int getRepeatDelay() { - return this.repeatDelay; - } - - @Override - public float getVolume() { - return this.volume; - } - - @Override - public float getPitch() { - return this.pitch; - } - - @Override - public float getXPosF() { - return this.soundX; - } - - @Override - public float getYPosF() { - return this.soundY; - } - - @Override - public float getZPosF() { - return this.soundZ; - } - - @Override - public AttenuationType getAttenuationType() { - return AttenuationType.LINEAR; - } - - /** - * Called by proxy of the SoundWrapper from the holding tile entity, once per tick. - */ - public void updateExternally() { - - SoundHandler handler = Minecraft.getMinecraft().getSoundHandler(); - - if(isSoundOn && !this.source.isPlaying()) { - handler.stopSound(this); - isSoundOn = false; - return; - } - - //TODO: drown this class, the minecraft sound handler and the entire fucking game in holy water - //no, it won't fix anything but at least the pain will be over - - if(!isSoundOn && this.source.isPlaying()) { - try { - handler.playSound(this); - } catch(IllegalArgumentException ex) { } - isSoundOn = true; - } - - this.volume = this.source.getVolume(); - this.pitch = this.source.getPitch(); - - Vec3 pos = this.source.getSoundLocation(); - this.soundX = (float) pos.xCoord; - this.soundY = (float) pos.yCoord; - this.soundZ = (float) pos.zCoord; - - } -} diff --git a/src/main/java/com/hbm/sound/nt/SoundWrapper.java b/src/main/java/com/hbm/sound/nt/SoundWrapper.java deleted file mode 100644 index bbb6964cf..000000000 --- a/src/main/java/com/hbm/sound/nt/SoundWrapper.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.hbm.sound.nt; - -public class SoundWrapper { - - public void updateSound() { } -} diff --git a/src/main/java/com/hbm/sound/nt/SoundWrapperClient.java b/src/main/java/com/hbm/sound/nt/SoundWrapperClient.java deleted file mode 100644 index 5f5fa1e3b..000000000 --- a/src/main/java/com/hbm/sound/nt/SoundWrapperClient.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.hbm.sound.nt; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -@SideOnly(Side.CLIENT) -public class SoundWrapperClient extends SoundWrapper { - - private SoundTE sound; - - public SoundWrapperClient(String sound, ISoundSourceTE source) { - this.sound = new SoundTE(sound, source); - } - - @Override - public void updateSound() { - this.sound.updateExternally(); - } -} diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityCondenser.java b/src/main/java/com/hbm/tileentity/machine/TileEntityCondenser.java index d2661c982..2ffb6c25b 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityCondenser.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityCondenser.java @@ -12,6 +12,7 @@ import com.hbm.lib.Library; import com.hbm.main.MainRegistry; import com.hbm.main.ModEventHandler; import com.hbm.main.ModEventHandlerImpact; +import com.hbm.tileentity.TileEntityLoadedBase; import api.hbm.fluid.IFluidStandardTransceiver; import net.minecraft.nbt.NBTTagCompound; @@ -19,7 +20,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.EnumSkyBlock; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityCondenser extends TileEntity implements IFluidAcceptor, IFluidSource, IFluidStandardTransceiver { +public class TileEntityCondenser extends TileEntityLoadedBase implements IFluidAcceptor, IFluidSource, IFluidStandardTransceiver { public int age = 0; public FluidTank[] tanks; diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineBoiler.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineBoiler.java index a9c4ac349..5bf7373ee 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineBoiler.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineBoiler.java @@ -15,6 +15,7 @@ import com.hbm.inventory.recipes.MachineRecipes; import com.hbm.lib.Library; import com.hbm.packet.AuxGaugePacket; import com.hbm.packet.PacketDispatcher; +import com.hbm.tileentity.TileEntityLoadedBase; import api.hbm.fluid.IFluidStandardTransceiver; import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; @@ -26,7 +27,7 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityFurnace; -public class TileEntityMachineBoiler extends TileEntity implements ISidedInventory, IFluidContainer, IFluidAcceptor, IFluidSource, IFluidStandardTransceiver { +public class TileEntityMachineBoiler extends TileEntityLoadedBase implements ISidedInventory, IFluidContainer, IFluidAcceptor, IFluidSource, IFluidStandardTransceiver { private ItemStack slots[]; diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineReactorLarge.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineReactorLarge.java index d65305bc6..4c3fa81d9 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineReactorLarge.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineReactorLarge.java @@ -20,7 +20,7 @@ import com.hbm.items.machine.ItemFuelRod; import com.hbm.lib.Library; import com.hbm.packet.AuxGaugePacket; import com.hbm.packet.PacketDispatcher; -import com.hbm.tileentity.machine.TileEntityMachineReactorLarge.ReactorFuelType; +import com.hbm.tileentity.TileEntityLoadedBase; import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import net.minecraft.block.Block; @@ -35,7 +35,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityMachineReactorLarge extends TileEntity implements ISidedInventory, IFluidContainer, IFluidAcceptor, IFluidSource, IFluidStandardTransceiver { +public class TileEntityMachineReactorLarge extends TileEntityLoadedBase implements ISidedInventory, IFluidContainer, IFluidAcceptor, IFluidSource, IFluidStandardTransceiver { private ItemStack slots[]; diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntitySolarBoiler.java b/src/main/java/com/hbm/tileentity/machine/TileEntitySolarBoiler.java index b8ebdacd0..e3e1d2b4d 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntitySolarBoiler.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntitySolarBoiler.java @@ -10,6 +10,7 @@ import com.hbm.inventory.fluid.FluidType; import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.lib.Library; +import com.hbm.tileentity.TileEntityLoadedBase; import api.hbm.fluid.IFluidStandardTransceiver; import cpw.mods.fml.relauncher.Side; @@ -19,7 +20,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.ChunkCoordinates; -public class TileEntitySolarBoiler extends TileEntity implements IFluidAcceptor, IFluidSource, IFluidStandardTransceiver { +public class TileEntitySolarBoiler extends TileEntityLoadedBase implements IFluidAcceptor, IFluidSource, IFluidStandardTransceiver { private FluidTank water; private FluidTank steam; diff --git a/src/main/java/com/hbm/tileentity/machine/oil/TileEntityMachineCatalyticCracker.java b/src/main/java/com/hbm/tileentity/machine/oil/TileEntityMachineCatalyticCracker.java index 6d81d415e..77554db0c 100644 --- a/src/main/java/com/hbm/tileentity/machine/oil/TileEntityMachineCatalyticCracker.java +++ b/src/main/java/com/hbm/tileentity/machine/oil/TileEntityMachineCatalyticCracker.java @@ -13,6 +13,7 @@ import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.recipes.RefineryRecipes; import com.hbm.lib.Library; import com.hbm.tileentity.INBTPacketReceiver; +import com.hbm.tileentity.TileEntityLoadedBase; import com.hbm.util.Tuple.Pair; import com.hbm.util.fauxpointtwelve.DirPos; @@ -24,7 +25,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityMachineCatalyticCracker extends TileEntity implements IFluidSource, IFluidAcceptor, INBTPacketReceiver, IFluidStandardTransceiver { +public class TileEntityMachineCatalyticCracker extends TileEntityLoadedBase implements IFluidSource, IFluidAcceptor, INBTPacketReceiver, IFluidStandardTransceiver { public FluidTank[] tanks; public List list1 = new ArrayList(); diff --git a/src/main/java/com/hbm/tileentity/machine/oil/TileEntityMachineFractionTower.java b/src/main/java/com/hbm/tileentity/machine/oil/TileEntityMachineFractionTower.java index f43c3ad26..683c1fef3 100644 --- a/src/main/java/com/hbm/tileentity/machine/oil/TileEntityMachineFractionTower.java +++ b/src/main/java/com/hbm/tileentity/machine/oil/TileEntityMachineFractionTower.java @@ -12,6 +12,7 @@ import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.recipes.RefineryRecipes; import com.hbm.lib.Library; import com.hbm.tileentity.INBTPacketReceiver; +import com.hbm.tileentity.TileEntityLoadedBase; import com.hbm.util.Tuple.Pair; import com.hbm.util.fauxpointtwelve.DirPos; @@ -23,7 +24,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityMachineFractionTower extends TileEntity implements IFluidSource, IFluidAcceptor, INBTPacketReceiver, IFluidStandardTransceiver { +public class TileEntityMachineFractionTower extends TileEntityLoadedBase implements IFluidSource, IFluidAcceptor, INBTPacketReceiver, IFluidStandardTransceiver { public FluidTank[] tanks; public List list1 = new ArrayList(); diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityHeatex.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityHeatex.java index 08e0e5cdf..2b6ea8841 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityHeatex.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityHeatex.java @@ -10,12 +10,12 @@ import com.hbm.inventory.fluid.FluidType; import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.lib.Library; +import com.hbm.tileentity.TileEntityLoadedBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityHeatex extends TileEntity implements IFluidAcceptor, IFluidSource, IFluidStandardTransceiver { +public class TileEntityHeatex extends TileEntityLoadedBase implements IFluidAcceptor, IFluidSource, IFluidStandardTransceiver { public List coolantList = new ArrayList(); public List waterList = new ArrayList(); diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKBase.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKBase.java index 28e182954..6a83ccc09 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKBase.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKBase.java @@ -18,6 +18,7 @@ import com.hbm.packet.AuxParticlePacketNT; import com.hbm.packet.NBTPacket; import com.hbm.packet.PacketDispatcher; import com.hbm.tileentity.INBTPacketReceiver; +import com.hbm.tileentity.TileEntityLoadedBase; import com.hbm.tileentity.machine.rbmk.TileEntityRBMKConsole.ColumnType; import com.hbm.util.I18nUtil; @@ -44,7 +45,7 @@ import net.minecraftforge.common.util.ForgeDirection; * @author hbm * */ -public abstract class TileEntityRBMKBase extends TileEntity implements INBTPacketReceiver { +public abstract class TileEntityRBMKBase extends TileEntityLoadedBase implements INBTPacketReceiver { public double heat; diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKInlet.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKInlet.java index cc4c4855e..aa0935e94 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKInlet.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKInlet.java @@ -6,13 +6,14 @@ import com.hbm.interfaces.IFluidAcceptor; import com.hbm.inventory.fluid.FluidType; import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.tank.FluidTank; +import com.hbm.tileentity.TileEntityLoadedBase; import net.minecraft.block.Block; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityRBMKInlet extends TileEntity implements IFluidAcceptor, IFluidStandardReceiver { +public class TileEntityRBMKInlet extends TileEntityLoadedBase implements IFluidAcceptor, IFluidStandardReceiver { public FluidTank water; diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKOutlet.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKOutlet.java index 606c0145d..f852e31bd 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKOutlet.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKOutlet.java @@ -11,13 +11,14 @@ import com.hbm.inventory.fluid.FluidType; import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.lib.Library; +import com.hbm.tileentity.TileEntityLoadedBase; import net.minecraft.block.Block; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityRBMKOutlet extends TileEntity implements IFluidSource, IFluidStandardSender { +public class TileEntityRBMKOutlet extends TileEntityLoadedBase implements IFluidSource, IFluidStandardSender { public List list = new ArrayList(); public FluidTank steam; diff --git a/src/main/java/com/hbm/tileentity/network/RTTYSystem.java b/src/main/java/com/hbm/tileentity/network/RTTYSystem.java index f9a8ad385..46dd4d0b2 100644 --- a/src/main/java/com/hbm/tileentity/network/RTTYSystem.java +++ b/src/main/java/com/hbm/tileentity/network/RTTYSystem.java @@ -20,11 +20,13 @@ public class RTTYSystem { newMessages.put(identifier, signal); } + /** Returns the RTTY channel with that name, or null */ public static RTTYChannel listen(World world, String channelName) { RTTYChannel channel = broadcast.get(new Pair(world, channelName)); return channel; } + /** Moves all new messages to the broadcast map, adding the appropriate timestamp and clearing the new message queue */ public static void updateBroadcastQueue() { for(Entry, Object> worldEntry : newMessages.entrySet()) { @@ -34,6 +36,9 @@ public class RTTYSystem { RTTYChannel channel = new RTTYChannel(); channel.timeStamp = identifier.getKey().getTotalWorldTime(); channel.signal = lastSignal; + + broadcast.put(identifier, channel); + newMessages.clear(); } } diff --git a/src/main/java/com/hbm/tileentity/network/TileEntityPipeBaseNT.java b/src/main/java/com/hbm/tileentity/network/TileEntityPipeBaseNT.java index 0e073093b..0fedcdd18 100644 --- a/src/main/java/com/hbm/tileentity/network/TileEntityPipeBaseNT.java +++ b/src/main/java/com/hbm/tileentity/network/TileEntityPipeBaseNT.java @@ -11,6 +11,7 @@ import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.WorldServer; import net.minecraftforge.common.util.ForgeDirection; public class TileEntityPipeBaseNT extends TileEntity implements IFluidConductor { @@ -48,6 +49,11 @@ public class TileEntityPipeBaseNT extends TileEntity implements IFluidConductor this.type = type; this.markDirty(); + if(worldObj instanceof WorldServer) { + WorldServer world = (WorldServer) worldObj; + world.getPlayerManager().markBlockForUpdate(xCoord, yCoord, zCoord); + } + if(this.network != null) this.network.destroy(); } diff --git a/src/main/java/com/hbm/tileentity/network/TileEntityRadioTorchBase.java b/src/main/java/com/hbm/tileentity/network/TileEntityRadioTorchBase.java index 52f9fb55d..acb67d988 100644 --- a/src/main/java/com/hbm/tileentity/network/TileEntityRadioTorchBase.java +++ b/src/main/java/com/hbm/tileentity/network/TileEntityRadioTorchBase.java @@ -1,13 +1,21 @@ package com.hbm.tileentity.network; +import com.hbm.interfaces.IControlReceiver; +import com.hbm.tileentity.INBTPacketReceiver; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; -public class TileEntityRadioTorchBase extends TileEntity { +public class TileEntityRadioTorchBase extends TileEntity implements INBTPacketReceiver, IControlReceiver { /** channel we're broadcasting on/listening to */ public String channel = ""; /** previous redstone state for input/output, needed for state change detection */ - protected int lastState = 0; + public int lastState = 0; /** last update tick, needed for receivers listening for changes */ protected long lastUpdate; /** switches state change mode to tick-based polling */ @@ -16,4 +24,56 @@ public class TileEntityRadioTorchBase extends TileEntity { public boolean customMap = false; /** custom mapping */ public String[] mapping = new String[16]; + + @Override + public void updateEntity() { + + if(!worldObj.isRemote) { + NBTTagCompound data = new NBTTagCompound(); + data.setBoolean("p", polling); + data.setBoolean("m", customMap); + if(channel != null) data.setString("c", channel); + for(int i = 0; i < 16; i++) if(mapping[i] != null) data.setString("m" + i, mapping[i]); + INBTPacketReceiver.networkPack(this, data, 50); + } + } + + @Override + public void networkUnpack(NBTTagCompound nbt) { + this.polling = nbt.getBoolean("p"); + this.customMap = nbt.getBoolean("m"); + this.channel = nbt.getString("c"); + for(int i = 0; i < 16; i++) this.mapping[i] = nbt.getString("m" + i); + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setByte("l", (byte) this.lastState); + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbt); + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + int last = this.lastState; + this.lastState = pkt.func_148857_g().getByte("l"); + if(this.lastState != last) { + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + + @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("p")) this.polling = data.getBoolean("p"); + if(data.hasKey("m")) this.customMap = data.getBoolean("m"); + if(data.hasKey("c")) this.channel = data.getString("c"); + for(int i = 0; i < 16; i++) if(data.hasKey("m" + i)) this.mapping[i] = data.getString("m" + i); + + this.markDirty(); + } } diff --git a/src/main/java/com/hbm/tileentity/network/TileEntityRadioTorchReceiver.java b/src/main/java/com/hbm/tileentity/network/TileEntityRadioTorchReceiver.java index e83dd095a..a3f313466 100644 --- a/src/main/java/com/hbm/tileentity/network/TileEntityRadioTorchReceiver.java +++ b/src/main/java/com/hbm/tileentity/network/TileEntityRadioTorchReceiver.java @@ -1,5 +1,51 @@ package com.hbm.tileentity.network; +import com.hbm.tileentity.network.RTTYSystem.RTTYChannel; + +import net.minecraft.util.MathHelper; + public class TileEntityRadioTorchReceiver extends TileEntityRadioTorchBase { + @Override + public void updateEntity() { + + 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.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(); + } + } + } + + super.updateEntity(); + } } diff --git a/src/main/java/com/hbm/tileentity/network/TileEntityRadioTorchSender.java b/src/main/java/com/hbm/tileentity/network/TileEntityRadioTorchSender.java index 0203c7fd0..6c41d0b67 100644 --- a/src/main/java/com/hbm/tileentity/network/TileEntityRadioTorchSender.java +++ b/src/main/java/com/hbm/tileentity/network/TileEntityRadioTorchSender.java @@ -1,5 +1,30 @@ package com.hbm.tileentity.network; +import net.minecraftforge.common.util.ForgeDirection; + public class TileEntityRadioTorchSender extends TileEntityRadioTorchBase { + @Override + public void updateEntity() { + + if(!worldObj.isRemote) { + ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata()).getOpposite(); + int input = worldObj.getIndirectPowerLevelTo(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, this.getBlockMetadata()); + + boolean shouldSend = this.polling; + + if(input != this.lastState) { + this.markDirty(); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + this.lastState = input; + shouldSend = true; + } + + if(shouldSend && !this.channel.isEmpty()) { + RTTYSystem.broadcast(worldObj, this.channel, this.customMap ? this.mapping[input] : (input + "")); + } + } + + super.updateEntity(); + } }