diff --git a/src/main/java/jkmau5/modjam/radiomod/Constants.java b/src/main/java/jkmau5/modjam/radiomod/Constants.java index 00ccf23..9fb63cf 100644 --- a/src/main/java/jkmau5/modjam/radiomod/Constants.java +++ b/src/main/java/jkmau5/modjam/radiomod/Constants.java @@ -25,7 +25,7 @@ public static void initiateTitles(){ ItemRecord record = (ItemRecord) itemStack.getItem(); musicTitles.put(record.recordName, new int[]{itemStack.itemID, itemStack.getItemDamage()}); realMusicTitles.put(record.recordName, record.getRecordTitle()); - normalMusicTitles.put(record.getRecordTitle(), record.recordName); + normalMusicTitles.put(record.getItemDisplayName(itemStack), record.recordName); } } diff --git a/src/main/java/jkmau5/modjam/radiomod/RadioMod.java b/src/main/java/jkmau5/modjam/radiomod/RadioMod.java index f7383dc..04a3561 100644 --- a/src/main/java/jkmau5/modjam/radiomod/RadioMod.java +++ b/src/main/java/jkmau5/modjam/radiomod/RadioMod.java @@ -26,6 +26,7 @@ import jkmau5.modjam.radiomod.tile.TileEntityPlaylist; import jkmau5.modjam.radiomod.tile.TileEntityRadio; import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.ItemStack; import java.util.Random; @@ -46,7 +47,12 @@ public class RadioMod { public static RadioNetworkHandler radioNetworkHandler; - public static final CreativeTabs tabRadioMod = new CreativeTabs("RadioMod"); + public static final CreativeTabs tabRadioMod = new CreativeTabs("RadioMod") { + @Override + public ItemStack getIconItemStack(){ + return new ItemStack(RadioMod.instance.blockAntenna); + } + }; @SidedProxy(modId = Constants.MODID, clientSide = "jkmau5.modjam.radiomod.client.ProxyClient", serverSide = "jkmau5.modjam.radiomod.server.ProxyCommon") public static ProxyCommon proxy; @@ -93,12 +99,11 @@ public void init(FMLInitializationEvent event){ LanguageRegistry.addName(itemMediaPlayer, "Media Player"); LanguageRegistry.addName(blockRadio, "Radio Block"); LanguageRegistry.addName(blockPlaylist, "Playlist Block"); + LanguageRegistry.addName(this.blockAntenna, "Antenna"); proxy.init(); TickRegistry.registerTickHandler(new RadioTickHandler(), Side.SERVER); //TODO: remove? - - Constants.initiateTitles(); } @Mod.EventHandler diff --git a/src/main/java/jkmau5/modjam/radiomod/block/BlockBroadcaster.java b/src/main/java/jkmau5/modjam/radiomod/block/BlockBroadcaster.java index 0a7938b..315559b 100644 --- a/src/main/java/jkmau5/modjam/radiomod/block/BlockBroadcaster.java +++ b/src/main/java/jkmau5/modjam/radiomod/block/BlockBroadcaster.java @@ -27,7 +27,7 @@ public class BlockBroadcaster extends Block { public BlockBroadcaster(int par1){ super(par1, Material.iron); this.setCreativeTab(RadioMod.tabRadioMod); - this.setUnlocalizedName("radiomod.BlockBroadcaster"); + this.setUnlocalizedName("radioMod.blockBroadcaster"); this.maxY = 0.75f; } diff --git a/src/main/java/jkmau5/modjam/radiomod/block/BlockPlaylist.java b/src/main/java/jkmau5/modjam/radiomod/block/BlockPlaylist.java index 6cff194..3a9a09b 100644 --- a/src/main/java/jkmau5/modjam/radiomod/block/BlockPlaylist.java +++ b/src/main/java/jkmau5/modjam/radiomod/block/BlockPlaylist.java @@ -20,11 +20,12 @@ public class BlockPlaylist extends Block { private Icon topIcon[]; private Icon sidesIcon; + private Icon bottomIcon; public BlockPlaylist(int par1){ super(par1, Material.iron); this.setCreativeTab(RadioMod.tabRadioMod); - this.setUnlocalizedName("radiomod.BlockPlaylist"); + this.setUnlocalizedName("radioMod.blockPlaylist"); this.maxY = 0.75; } @@ -53,11 +54,14 @@ public void registerIcons(IconRegister register){ this.topIcon[2] = register.registerIcon("RadioMod:playlist_180"); this.topIcon[3] = register.registerIcon("RadioMod:playlist_270"); this.sidesIcon = register.registerIcon("RadioMod:side_small"); + this.bottomIcon = register.registerIcon("RadioMod:side"); } @Override public Icon getIcon(int side, int meta){ switch(side){ + case 0: + return this.bottomIcon; case 1: return this.topIcon[meta]; default: diff --git a/src/main/java/jkmau5/modjam/radiomod/block/BlockRadio.java b/src/main/java/jkmau5/modjam/radiomod/block/BlockRadio.java index e8fdb1f..6bc7281 100644 --- a/src/main/java/jkmau5/modjam/radiomod/block/BlockRadio.java +++ b/src/main/java/jkmau5/modjam/radiomod/block/BlockRadio.java @@ -8,6 +8,7 @@ import jkmau5.modjam.radiomod.gui.EnumGui; import jkmau5.modjam.radiomod.gui.GuiOpener; import jkmau5.modjam.radiomod.network.PacketMediaPlayerData; +import jkmau5.modjam.radiomod.network.PacketPlaySound; import jkmau5.modjam.radiomod.tile.TileEntityRadio; import net.minecraft.block.Block; import net.minecraft.block.material.Material; @@ -33,7 +34,7 @@ public class BlockRadio extends Block { public BlockRadio(int par1){ super(par1, Material.iron); this.setCreativeTab(RadioMod.tabRadioMod); - this.setUnlocalizedName("radiomod.BlockRadio"); + this.setUnlocalizedName("radioMod.blockRadio"); this.setHardness(0.8f); this.setResistance(3f); } @@ -83,6 +84,12 @@ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase e world.setBlockMetadataWithNotify(x, y, z, meta, 2); } + @Override + public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int par5){ + super.onBlockDestroyedByPlayer(world, x, y, z, par5); + PacketDispatcher.sendPacketToAllAround(x, y, z, 256, world.provider.dimensionId, new PacketPlaySound(null, x, y, z, true).getPacket()); + } + @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float par7, float par8, float par9){ TileEntity tileEntity = world.getBlockTileEntity(x, y, z); diff --git a/src/main/java/jkmau5/modjam/radiomod/client/ProxyClient.java b/src/main/java/jkmau5/modjam/radiomod/client/ProxyClient.java index 0f9a9be..fa6fc57 100644 --- a/src/main/java/jkmau5/modjam/radiomod/client/ProxyClient.java +++ b/src/main/java/jkmau5/modjam/radiomod/client/ProxyClient.java @@ -29,5 +29,7 @@ public void init(){ MinecraftForgeClient.registerItemRenderer(RadioMod.instance.blockAntenna.blockID, new ItemRendererAntenna()); MinecraftForge.EVENT_BUS.register(new SoundLoader()); + + Constants.initiateTitles(); } } diff --git a/src/main/java/jkmau5/modjam/radiomod/gui/GuiOpener.java b/src/main/java/jkmau5/modjam/radiomod/gui/GuiOpener.java index 80d8ef2..b35c7d4 100644 --- a/src/main/java/jkmau5/modjam/radiomod/gui/GuiOpener.java +++ b/src/main/java/jkmau5/modjam/radiomod/gui/GuiOpener.java @@ -2,6 +2,8 @@ import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.common.network.Player; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import jkmau5.modjam.radiomod.network.PacketOpenGui; import jkmau5.modjam.radiomod.tile.TileEntityBroadcaster; import jkmau5.modjam.radiomod.tile.TileEntityPlaylist; @@ -13,12 +15,14 @@ public class GuiOpener { + @SideOnly(Side.CLIENT) public static void openGuiCallback(EnumGui gui){ if(gui == EnumGui.MEDIA_PLAYER){ Minecraft.getMinecraft().displayGuiScreen(new GuiMediaPlayer()); } } + @SideOnly(Side.CLIENT) public static void openGuiCallback(EnumGui gui, int x, int y, int z){ if(gui == EnumGui.BROADCASTER_BLOCK){ World world = Minecraft.getMinecraft().thePlayer.worldObj; diff --git a/src/main/java/jkmau5/modjam/radiomod/gui/GuiPlaylist.java b/src/main/java/jkmau5/modjam/radiomod/gui/GuiPlaylist.java index 976e719..aad7510 100644 --- a/src/main/java/jkmau5/modjam/radiomod/gui/GuiPlaylist.java +++ b/src/main/java/jkmau5/modjam/radiomod/gui/GuiPlaylist.java @@ -42,14 +42,14 @@ public void initGui(){ buttonList.add(new GuiButton(0, this.width / 2, this.height / 8, 100, 20, "Play")); - this.actualHeight = height; + actualHeight = height; initTitles(); } @Override protected void actionPerformed(GuiButton button){ if(button.id == 0 && !this.selectedIndex.isEmpty()){ - PacketDispatcher.sendPacketToServer(new PacketPlayBroadcastedSound(this.selectedIndex, this.playlist.network.getID()).getPacket()); + PacketDispatcher.sendPacketToServer(new PacketPlayBroadcastedSound(this.selectedIndex, playlist.xCoord, playlist.yCoord, playlist.zCoord, playlist.worldObj.provider.dimensionId).getPacket()); } } @@ -91,7 +91,7 @@ public boolean doesGuiPauseGame(){ @Override public void drawScreen(int mouseX, int mouseY, float partialTick){ int x = (this.width - this.xSize) / 2; - int y = (this.actualHeight - this.ySize) / 2; + int y = (actualHeight - this.ySize) / 2; if(playlist != null && playlist.getTitles() != null){ this.scrollY = Math.min(this.scrollY, 0); this.scrollY = Math.max(this.scrollY, 47 - (playlist.getTitles().size() * 10 + 2)); @@ -104,7 +104,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTick){ this.ySize = 116; if(playlist != null && playlist.getTitles() != null && !playlist.getTitles().isEmpty()){ GL11.glPushMatrix(); - int yS = (this.actualHeight / 5); + int yS = (actualHeight / 5); Gui.drawRect(x - 1, y - 1, x + this.xSize + 1, y + yS + 1, 0xFFAAAAAA); Gui.drawRect(x, y, x + this.xSize, y + yS, 0xFF000000); @@ -138,7 +138,7 @@ private int getYStartForTitle(){ } private void removeIfClickingRemove(int xMouse, int yMouse){ - if(selectedIndex == "") return; + if(selectedIndex.isEmpty()) return; int realX = (this.width - this.xSize) / 2; if(xMouse >= realX + this.xSize - 16 && xMouse < realX + this.xSize - 6){ int y = getYStartForTitle(); @@ -153,8 +153,8 @@ protected void mouseClicked(int x, int y, int button){ super.mouseClicked(x, y, button); if(button == 0){ int realX = (this.width - this.xSize) / 2; - int realY = (this.actualHeight - this.ySize) / 2; - int yS = this.actualHeight / 5; + int realY = (actualHeight - this.ySize) / 2; + int yS = actualHeight / 5; if(x > realX && x < realX + this.xSize && y > realY && y < realY + yS){ removeIfClickingRemove(x, y - scrollY); selectedIndex = getIndexId(y - scrollY); diff --git a/src/main/java/jkmau5/modjam/radiomod/item/ItemIngredient.java b/src/main/java/jkmau5/modjam/radiomod/item/ItemIngredient.java index 094c45b..d2c8e77 100644 --- a/src/main/java/jkmau5/modjam/radiomod/item/ItemIngredient.java +++ b/src/main/java/jkmau5/modjam/radiomod/item/ItemIngredient.java @@ -21,7 +21,7 @@ public ItemIngredient(int id){ super(id); this.setHasSubtypes(true); this.setMaxDamage(0); - this.setUnlocalizedName("ingredient"); + this.setUnlocalizedName("radioMod.ingredient"); this.setCreativeTab(RadioMod.tabRadioMod); } diff --git a/src/main/java/jkmau5/modjam/radiomod/item/ItemMediaPlayer.java b/src/main/java/jkmau5/modjam/radiomod/item/ItemMediaPlayer.java index 25577d2..5ff60c4 100644 --- a/src/main/java/jkmau5/modjam/radiomod/item/ItemMediaPlayer.java +++ b/src/main/java/jkmau5/modjam/radiomod/item/ItemMediaPlayer.java @@ -18,6 +18,7 @@ public class ItemMediaPlayer extends Item { public ItemMediaPlayer(int par1){ super(par1); //setCreativeTab(RadioMod.tabRadioMod); + this.setUnlocalizedName("radioMod.mediaPlayer"); this.setTextureName("RadioMod:mediaplayer"); } diff --git a/src/main/java/jkmau5/modjam/radiomod/network/PacketPlayBroadcastedSound.java b/src/main/java/jkmau5/modjam/radiomod/network/PacketPlayBroadcastedSound.java index d301f92..798ffab 100644 --- a/src/main/java/jkmau5/modjam/radiomod/network/PacketPlayBroadcastedSound.java +++ b/src/main/java/jkmau5/modjam/radiomod/network/PacketPlayBroadcastedSound.java @@ -1,7 +1,9 @@ package jkmau5.modjam.radiomod.network; -import jkmau5.modjam.radiomod.RadioMod; -import jkmau5.modjam.radiomod.radio.RadioNetwork; +import jkmau5.modjam.radiomod.Constants; +import jkmau5.modjam.radiomod.tile.TileEntityRadioNetwork; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.DimensionManager; import java.io.DataInput; import java.io.DataOutput; @@ -15,28 +17,36 @@ public class PacketPlayBroadcastedSound extends PacketBase { public String soundName; - public int networkID; + public int x, y, z, dimid; public PacketPlayBroadcastedSound(){ } - public PacketPlayBroadcastedSound(String soundName, int networkID){ + public PacketPlayBroadcastedSound(String soundName, int x, int y, int z, int dimid){ this.soundName = soundName; - this.networkID = networkID; + this.x = x; + this.y = y; + this.z = z; } @Override public void writePacket(DataOutput output) throws IOException{ - output.writeInt(this.networkID); - output.writeUTF(this.soundName); + output.writeInt(this.x); + output.writeInt(this.y); + output.writeInt(this.z); + output.writeInt(this.dimid); + output.writeUTF(Constants.getNormalRecordTitle(this.soundName)); } @Override public void readPacket(DataInput input) throws IOException{ - this.networkID = input.readInt(); + this.x = input.readInt(); + this.y = input.readInt(); + this.z = input.readInt(); + this.dimid = input.readInt(); this.soundName = input.readUTF(); - RadioNetwork network = RadioMod.radioNetworkHandler.getNetworkFromID(this.networkID); - if(network == null) return; - network.playSound(this.soundName); + TileEntity tile = DimensionManager.getWorld(this.dimid).getBlockTileEntity(x, y, z); + if(tile == null || !(tile instanceof TileEntityRadioNetwork)) return; + ((TileEntityRadioNetwork) tile).network.playSound(this.soundName); } } diff --git a/src/main/java/jkmau5/modjam/radiomod/network/PacketPlaySound.java b/src/main/java/jkmau5/modjam/radiomod/network/PacketPlaySound.java index 8e7a39b..71f6fd5 100644 --- a/src/main/java/jkmau5/modjam/radiomod/network/PacketPlaySound.java +++ b/src/main/java/jkmau5/modjam/radiomod/network/PacketPlaySound.java @@ -10,6 +10,7 @@ public class PacketPlaySound extends PacketBase { private String name; private int x, y, z; + private boolean stop; public PacketPlaySound(){ } @@ -19,11 +20,21 @@ public PacketPlaySound(String name, int x, int y, int z){ this.x = x; this.y = y; this.z = z; + this.stop = false; + } + + public PacketPlaySound(String name, int x, int y, int z, boolean stop){ + this.name = name; + this.x = x; + this.y = y; + this.z = z; + this.stop = stop; } @Override public void writePacket(DataOutput output) throws IOException{ - output.writeUTF(this.name); + output.writeBoolean(this.stop); + if(!this.stop) output.writeUTF(this.name); output.writeInt(this.x); output.writeInt(this.y); output.writeInt(this.z); @@ -31,6 +42,11 @@ public void writePacket(DataOutput output) throws IOException{ @Override public void readPacket(DataInput input) throws IOException{ - Minecraft.getMinecraft().renderGlobal.playRecord(input.readUTF(), input.readInt(), input.readInt(), input.readInt()); + boolean stop = input.readBoolean(); + if(stop){ + Minecraft.getMinecraft().renderGlobal.playRecord(null, input.readInt(), input.readInt(), input.readInt()); + }else{ + Minecraft.getMinecraft().renderGlobal.playRecord(input.readUTF(), input.readInt(), input.readInt(), input.readInt()); + } } } diff --git a/src/main/java/jkmau5/modjam/radiomod/radio/RadioNetwork.java b/src/main/java/jkmau5/modjam/radiomod/radio/RadioNetwork.java index 1fc0cad..a8cdc2e 100644 --- a/src/main/java/jkmau5/modjam/radiomod/radio/RadioNetwork.java +++ b/src/main/java/jkmau5/modjam/radiomod/radio/RadioNetwork.java @@ -2,7 +2,6 @@ import com.google.common.collect.Lists; import jkmau5.modjam.radiomod.Config; -import jkmau5.modjam.radiomod.Constants; import jkmau5.modjam.radiomod.tile.TileEntityAntenna; import jkmau5.modjam.radiomod.tile.TileEntityBroadcaster; import jkmau5.modjam.radiomod.tile.TileEntityRadioNetwork; @@ -108,8 +107,8 @@ public boolean areCoordsInRange(World world, int x, int y, int z){ } public void playSound(String soundName){ - soundName = Constants.getNormalRecordTitle(soundName); - if(soundName.equals("INVALID")) return; + //soundName = Constants.getNormalRecordTitle(soundName); + //if(soundName.equals("INVALID")) return; for(IRadioListener listener : this.listeners){ listener.playSong(soundName); } diff --git a/src/main/java/jkmau5/modjam/radiomod/tile/TileEntityRadio.java b/src/main/java/jkmau5/modjam/radiomod/tile/TileEntityRadio.java index c6caed2..088dac0 100644 --- a/src/main/java/jkmau5/modjam/radiomod/tile/TileEntityRadio.java +++ b/src/main/java/jkmau5/modjam/radiomod/tile/TileEntityRadio.java @@ -100,7 +100,6 @@ public void writeGuiData(NBTTagCompound tag){ @Override public void playSong(String name){ PacketDispatcher.sendPacketToAllAround(this.xCoord, this.yCoord, this.zCoord, 256, this.worldObj.provider.dimensionId, new PacketPlaySound(name, this.xCoord, this.yCoord, this.zCoord).getPacket()); - //this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, name, 1, 1); } @Override diff --git a/src/main/java/jkmau5/modjam/radiomod/tile/TileEntityRadioNetwork.java b/src/main/java/jkmau5/modjam/radiomod/tile/TileEntityRadioNetwork.java index f0324be..dce6baa 100644 --- a/src/main/java/jkmau5/modjam/radiomod/tile/TileEntityRadioNetwork.java +++ b/src/main/java/jkmau5/modjam/radiomod/tile/TileEntityRadioNetwork.java @@ -1,5 +1,6 @@ package jkmau5.modjam.radiomod.tile; +import cpw.mods.fml.common.FMLCommonHandler; import jkmau5.modjam.radiomod.RadioMod; import jkmau5.modjam.radiomod.radio.RadioNetwork; import net.minecraft.nbt.NBTTagCompound; @@ -21,7 +22,7 @@ public int getDistanceToCoords(int x, int y, int z){ @Override public void readFromNBT(NBTTagCompound tag){ super.readFromNBT(tag); - if(tag.hasKey("networkID")){ + if(FMLCommonHandler.instance().getEffectiveSide().isServer() && tag.hasKey("networkID")){ this.network = RadioMod.radioNetworkHandler.getNetworkFromID(tag.getInteger("networkID")); this.network.add(this); } @@ -30,7 +31,7 @@ public void readFromNBT(NBTTagCompound tag){ @Override public void writeToNBT(NBTTagCompound tag){ super.writeToNBT(tag); - if(this.network != null){ + if(FMLCommonHandler.instance().getEffectiveSide().isServer() && this.network != null){ tag.setInteger("networkID", this.network.getID()); } } diff --git a/src/main/resources/assets/radiomod/lang/en_US.lang b/src/main/resources/assets/radiomod/lang/en_US.lang index 6681e48..7b37c7e 100644 --- a/src/main/resources/assets/radiomod/lang/en_US.lang +++ b/src/main/resources/assets/radiomod/lang/en_US.lang @@ -1 +1,12 @@ itemGroup.RadioMod=RadioMod +item.radioMod.ingredient.rawantennarod.name=Raw Antenna Rod +item.radioMod.ingredient.antennarod.name=Antenna Rod +item.radioMod.ingredient.antennafoot.name=Antenna Foot +item.radioMod.ingredient.bitantennafoot.name=Big Antenna Foot +item.radioMod.ingredient.antennaonfoot.name=Antenna On Foot +item.radioMod.linkCard.name=Link Card +item.radioMod.mediaPlayer.name=Media Player +tile.radioMod.blockBroadcaster.name=Broadcaster +tile.radioMod.blockRadio.name=Radio +tile.radioMod.blockPlaylist.name=Playlist Block +tile.radioMod.blockAntenna.name=Antenna