Skip to content

Commit

Permalink
Fixed it all!
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreykog committed Dec 16, 2013
1 parent 8b97415 commit 63adc48
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/main/java/jkmau5/modjam/radiomod/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/main/java/jkmau5/modjam/radiomod/RadioMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/jkmau5/modjam/radiomod/block/BlockRadio.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/jkmau5/modjam/radiomod/client/ProxyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ public void init(){
MinecraftForgeClient.registerItemRenderer(RadioMod.instance.blockAntenna.blockID, new ItemRendererAntenna());

MinecraftForge.EVENT_BUS.register(new SoundLoader());

Constants.initiateTitles();
}
}
4 changes: 4 additions & 0 deletions src/main/java/jkmau5/modjam/radiomod/gui/GuiOpener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/jkmau5/modjam/radiomod/gui/GuiPlaylist.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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));
Expand All @@ -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);

Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}
20 changes: 18 additions & 2 deletions src/main/java/jkmau5/modjam/radiomod/network/PacketPlaySound.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class PacketPlaySound extends PacketBase {

private String name;
private int x, y, z;
private boolean stop;

public PacketPlaySound(){
}
Expand All @@ -19,18 +20,33 @@ 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);
}

@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());
}
}
}
5 changes: 2 additions & 3 deletions src/main/java/jkmau5/modjam/radiomod/radio/RadioNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
Expand All @@ -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());
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/assets/radiomod/lang/en_US.lang
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 63adc48

Please sign in to comment.