Skip to content

Commit

Permalink
Many, many bugfixes, a lot!
Browse files Browse the repository at this point in the history
  • Loading branch information
Dynious committed Jan 13, 2014
1 parent 401aad7 commit fd24adb
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 53 deletions.
16 changes: 12 additions & 4 deletions java/com/dynious/soundscool/client/gui/GuiSoundPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void drawScreen(int p_571_1_, int p_571_2_, float p_571_3_)
String uploaded = hasSound? "Downloaded": "Not downloaded";
this.getFontRenderer().drawString(uploaded, getWidth()/2 + + 100 - (this.getFontRenderer().getStringWidth(uploaded)/2), 60, hasSound? 0x00FF00: 0xFF0000);

String category = NetworkHandler.uploadedSounds.get(tile.getSelectedIndex()).getCategory();
String category = NetworkHandler.getServerSound(sound.getSoundName()).getCategory();
this.getFontRenderer().drawString(category, getWidth()/2 + 100 - (this.getFontRenderer().getStringWidth(category)/2), 90, 0xFFFFFF);

if (sound.getSoundLocation() != null)
Expand Down Expand Up @@ -104,14 +104,22 @@ public FontRenderer getFontRenderer()
@Override
public void selectSoundIndex(int selected)
{
tile.selectSoundIndex(selected);
onSelectedSoundChanged();
if (selected >= 0 && selected < NetworkHandler.uploadedSounds.size())
{
tile.selectSound(NetworkHandler.uploadedSounds.get(selected).getSoundName());
onSelectedSoundChanged();
}
}

@Override
public boolean soundIndexSelected(int var1)
{
return tile.getSelectedIndex() == var1;
Sound sound = tile.getSelectedSound();
if (sound != null)
{
return NetworkHandler.uploadedSounds.indexOf(NetworkHandler.getServerSound(sound.getSoundName())) == var1;
}
return false;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion java/com/dynious/soundscool/client/gui/GuiSounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void selectSoundIndex(int selected)
{
this.selected = selected;

if (selected >= 0 && selected <= SoundHandler.getSounds().size())
if (selected >= 0 && selected < SoundHandler.getSounds().size())
{
this.selectedSound = SoundHandler.getSounds().get(selected);
}
Expand Down
6 changes: 5 additions & 1 deletion java/com/dynious/soundscool/handler/SoundHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.dynious.soundscool.network.packet.client.CheckPresencePacket;
import com.dynious.soundscool.sound.Sound;
import com.google.common.io.Files;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -79,7 +80,10 @@ public static void removeSound(Sound sound)
sound.getSoundLocation().deleteOnExit();
}
sounds.remove(sound);
NetworkHandler.uploadedSounds.remove(NetworkHandler.getServerSound(sound.getSoundName()));
if (FMLCommonHandler.instance().getEffectiveSide().isClient())
{
NetworkHandler.uploadedSounds.remove(NetworkHandler.getServerSound(sound.getSoundName()));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dynious.soundscool.network.packet;

import com.dynious.soundscool.handler.DelayedPlayHandler;
import com.dynious.soundscool.handler.NetworkHandler;
import com.dynious.soundscool.handler.SoundHandler;
import com.dynious.soundscool.helper.NetworkHelper;
Expand Down Expand Up @@ -40,6 +41,7 @@ public void readBytes(ByteBuf bytes)

NetworkHelper.createFileFromByteArr(NetworkHandler.soundUploaded(soundName), category, soundName);
SoundHandler.findSounds();
DelayedPlayHandler.onSoundReceived(soundName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void readBytes(ByteBuf bytes)
y = bytes.readInt();
z = bytes.readInt();
SoundsCool.proxy.getChannel().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT);
SoundsCool.proxy.getChannel().attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(NetworkRegistry.INSTANCE.new TargetPoint(dimensionId, x, y, z, 64));
SoundsCool.proxy.getChannel().attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(new NetworkRegistry.TargetPoint(dimensionId, x, y, z, 64));
SoundsCool.proxy.getChannel().writeOutbound(new ServerPlaySoundPacket(soundName, x, y, z));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void readBytes(ByteBuf bytes)

Sound sound = SoundHandler.getSound(soundName);
SoundHandler.removeSound(sound);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class SoundPlayerSelectPacket implements IPacket
{
int dimensionId;
int x, y, z;
int selected;
String soundName;
public SoundPlayerSelectPacket()
{
}
Expand All @@ -22,7 +22,7 @@ public SoundPlayerSelectPacket(TileSoundPlayer tile)
this.x = tile.field_145851_c;
this.y = tile.field_145848_d;
this.z = tile.field_145849_e;
this.selected = tile.getSelectedIndex();
this.soundName = tile.getSelectedSound().getSoundName();
}

@Override
Expand All @@ -33,12 +33,21 @@ public void readBytes(ByteBuf bytes)
y = bytes.readInt();
z = bytes.readInt();
World world = DimensionManager.getWorld(dimensionId);

int soundNameLength = bytes.readInt();
char[] soundNameCars = new char[soundNameLength];
for (int i = 0; i < soundNameLength; i++)
{
soundNameCars[i] = bytes.readChar();
}
soundName = String.valueOf(soundNameCars);

if (world != null)
{
TileEntity tile = world.func_147438_o(x, y, z);
if (tile != null && tile instanceof TileSoundPlayer)
{
((TileSoundPlayer)tile).selectSoundIndex(bytes.readInt());
((TileSoundPlayer)tile).selectSound(soundName);
}
}
}
Expand All @@ -50,6 +59,11 @@ public void writeBytes(ByteBuf bytes)
bytes.writeInt(x);
bytes.writeInt(y);
bytes.writeInt(z);
bytes.writeInt(selected);

bytes.writeInt(soundName.length());
for (char c : soundName.toCharArray())
{
bytes.writeChar(c);
}
}
}
72 changes: 30 additions & 42 deletions java/com/dynious/soundscool/tileentity/TileSoundPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class TileSoundPlayer extends TileEntity
{
private boolean isPowered = false;
private Sound selectedSound;
private int selected = -1;

public void setPowered(boolean powered)
{
Expand All @@ -33,68 +32,51 @@ else if (isPowered && !powered)
}
}

public void selectSoundIndex(int selected)
public void selectSound(String soundName)
{
this.selected = selected;
if (this.func_145831_w().isRemote)
{
SoundsCool.proxy.getChannel().writeOutbound(new SoundPlayerSelectPacket(this));

if (selected >= 0 && selected <= NetworkHandler.uploadedSounds.size())
Sound sound = SoundHandler.getSound(soundName);
if (sound != null)
{
Sound sound = SoundHandler.getSound(NetworkHandler.uploadedSounds.get(selected).getSoundName());
if (sound != null)
{
this.selectedSound = sound;
}
else
{
this.selectedSound = NetworkHandler.uploadedSounds.get(selected);
}
this.selectedSound = sound;
}
else
{
this.selectedSound = null;
this.selectedSound = NetworkHandler.getServerSound(soundName);
}

SoundsCool.proxy.getChannel().writeOutbound(new SoundPlayerSelectPacket(this));
}
else
{
if (selected >= 0 && selected <= SoundHandler.getSounds().size())
{
this.selectedSound = SoundHandler.getSounds().get(selected);
}
else
{
this.selectedSound = null;
}
this.selectedSound = SoundHandler.getSound(soundName);
}
}

public int getSelectedIndex()
{
return this.selected;
}

public Sound getSelectedSound()
{
if (selected != -1 && selectedSound == null)
if (selectedSound != null && SoundHandler.getSound(selectedSound.getSoundName()) == null)
{
selectSoundIndex(selected);
selectedSound = null;
}
return selectedSound;
}

public void playCurrentSound()
{
if (selected != -1 && selectedSound == null)
{
selectSoundIndex(selected);
}
if (selectedSound != null)
{
SoundsCool.proxy.getChannel().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT);
SoundsCool.proxy.getChannel().attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(new NetworkRegistry.TargetPoint(func_145831_w().provider.dimensionId, field_145851_c, field_145848_d, field_145849_e, 64));
SoundsCool.proxy.getChannel().writeOutbound(new ServerPlaySoundPacket(selectedSound.getSoundName(), field_145851_c, field_145848_d, field_145849_e));
if (SoundHandler.getSound(selectedSound.getSoundName()) != null)
{
SoundsCool.proxy.getChannel().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT);
SoundsCool.proxy.getChannel().attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(new NetworkRegistry.TargetPoint(func_145831_w().provider.dimensionId, field_145851_c, field_145848_d, field_145849_e, 64));
SoundsCool.proxy.getChannel().writeOutbound(new ServerPlaySoundPacket(selectedSound.getSoundName(), field_145851_c, field_145848_d, field_145849_e));
}
else
{
selectedSound = null;
}
}
}

Expand All @@ -103,29 +85,35 @@ public void playCurrentSound()
public void func_145839_a(NBTTagCompound compound)
{
super.func_145839_a(compound);
selected = compound.getInteger("selected");
selectedSound = SoundHandler.getSound(compound.getString("selectedSound"));
}

//writeToNBT
@Override
public void func_145841_b(NBTTagCompound compound)
{
super.func_145841_b(compound);
compound.setInteger("selected", selected);
if (selectedSound != null)
{
compound.setString("selectedSound", selectedSound.getSoundName());
}
}

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
{
selected = pkt.func_148857_g().getInteger("selected");
selectedSound = SoundHandler.getSound(pkt.func_148857_g().getString("selected"));
}

//getDescriptionPacket()
@Override
public Packet func_145844_m()
{
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("selected", selected);
if (selectedSound != null)
{
compound.setString("selectedSound", selectedSound.getSoundName());
}
return new S35PacketUpdateTileEntity(field_145851_c, field_145848_d, field_145849_e, 1, compound);
}
}

0 comments on commit fd24adb

Please sign in to comment.