Skip to content

Commit

Permalink
I fixed the speaker, I swear!
Browse files Browse the repository at this point in the history
  • Loading branch information
austinv11 committed Jan 4, 2015
1 parent 7b43f03 commit 49f4fcf
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

import com.austinv11.peripheralsplusplus.PeripheralsPlusPlus;
import com.austinv11.peripheralsplusplus.reference.Reference;
import com.austinv11.peripheralsplusplus.utils.Logger;
import com.austinv11.peripheralsplusplus.utils.TranslateUtils;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
@@ -11,8 +12,6 @@
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;

import java.util.ArrayList;

@@ -21,7 +20,7 @@ public class AudioPacket implements IMessage {
public String lang;
public String text;
public int x,y,z;
public World world;
//public World world;
public TurtleSide side;

public AudioPacket() {}
@@ -32,7 +31,7 @@ public AudioPacket(String lang, String text, int x, int y, int z, int world, Tur
this.x = x;
this.y = y;
this.z = z;
this.world = MinecraftServer.getServer().worldServerForDimension(world);
//this.world = MinecraftServer.getServer().worldServerForDimension(world);
this.side = side;
}

@@ -44,7 +43,7 @@ public void fromBytes(ByteBuf buf) {
x = tag.getInteger("x");
y = tag.getInteger("y");
z = tag.getInteger("z");
world = Minecraft.getMinecraft().theWorld;
//world = Minecraft.getMinecraft().theWorld;
side = tag.getString("side").equals("null") ? null : TurtleSide.valueOf(tag.getString("side"));
}

@@ -88,7 +87,7 @@ public void run(){
else
playSplitAudio();
work = false;
PeripheralsPlusPlus.NETWORK.sendToServer(new AudioResponsePacket(message.text, message.lang, message.x, message.y, message.z, message.world, message.side));
PeripheralsPlusPlus.NETWORK.sendToServer(new AudioResponsePacket(message.text, message.lang, message.x, message.y, message.z, Minecraft.getMinecraft().theWorld, message.side));
} catch (Exception e) {
e.printStackTrace();
}
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ public static class AudioResponsePacketHandler implements IMessageHandler<AudioR
@Override
public IMessage onMessage(AudioResponsePacket message, MessageContext ctx) {
if (message.side == null)
((TileEntitySpeaker)message.world.getTileEntity(message.x, message.y, message.z)).onSpeechCompletion(message.text, message.lang);
((TileEntitySpeaker) message.world.getTileEntity(message.x, message.y, message.z)).onSpeechCompletion(message.text, message.lang);
else
try {
ITurtleAccess turtle = ReflectionHelper.getTurtle(message.world.getTileEntity(message.x, message.y, message.z));
Original file line number Diff line number Diff line change
@@ -31,12 +31,15 @@ public class TileEntitySpeaker extends TileEntity implements IPeripheral {
private int eventSubticker = 0;
private HashMap<IComputerAccess, Boolean> computers = new HashMap<IComputerAccess,Boolean>();
private String lastMessage;
private Object[] packetInfo = new Object[4];

public TileEntitySpeaker() {
super();
packetInfo[0] = null;
}

public TileEntitySpeaker(ITurtleAccess turtle, TurtleSide side) {
this();
this.turtle = turtle;
this.side = side;
}
@@ -69,6 +72,10 @@ public void updateEntity() {
eventSubticker--;
if (eventSubticker == 0 && eventTicker != 0)
eventTicker = 0;
if (packetInfo[0] != null) {
PeripheralsPlusPlus.NETWORK.sendToAllAround(new AudioPacket((String)packetInfo[1], (String)packetInfo[2], xCoord, yCoord, zCoord, id, side), new NetworkRegistry.TargetPoint(id, xCoord, yCoord, zCoord, (Double)packetInfo[3]));
packetInfo[0] = null;
}
}

@Override
@@ -115,7 +122,10 @@ public Object[] callMethod(IComputerAccess computer, ILuaContext context, int me
range = Config.sayRange;
if (arguments.length > 1)
range = (Double) arguments[1];
PeripheralsPlusPlus.NETWORK.sendToAllAround(new AudioPacket(lang, (String) arguments[0], xCoord, yCoord, zCoord, id, side), new NetworkRegistry.TargetPoint(id, xCoord, yCoord, zCoord, range));
packetInfo[0] = "something";
packetInfo[1] = lang;
packetInfo[2] = arguments[0];
packetInfo[3] = range;
lastMessage = (String)arguments[0];
return new Object[]{lastMessage, lang};
// }catch (Exception e) {

0 comments on commit 49f4fcf

Please sign in to comment.