Hi Leute , ich mal wieder....und gleich mit einer Frage zu meinem Problem.
Sounds + Loop mit Forge 1.7.10
Mein Vorhaben ist es, einem Generator zum laufen zu bekommen.
Durch Rechtsklick auf das Objekt mit einem Schlüssel, wird er gestartet...
....hat er kein Benzin...geht er wieder aus....funktioniert.
...hat er Benzin...geht er an und bleibt an...funktioniert.
Kurz darauf kommt der "Idle" Sound.....funktioniert auch.
Wenn ich wieder Rechtsklicke geht er aus....funktioniert auch..
Was nicht funktioniert ist , wenn ich den Generator laufen lasse und offline gehe.....wieder on komme....steht zwar alles auf true, jedoch der "Idle" Sound ist nicht zu hören.
Nur wenn ich ihn ausschalte und wieder einschalte ist er wieder da, aber nur solange ich online bin....
Weiß von euch jemand einen Rat? ich verzweifle so langsam ....
Tutorials über SoundHandler finde ich nur sehr wenige bis garkeine.....
mein Block (Auszug):
mein TileEntity:
Handler:
Proxys:
Common:
Client:
IProxy:
Sounds + Loop mit Forge 1.7.10
Mein Vorhaben ist es, einem Generator zum laufen zu bekommen.
Durch Rechtsklick auf das Objekt mit einem Schlüssel, wird er gestartet...
....hat er kein Benzin...geht er wieder aus....funktioniert.
...hat er Benzin...geht er an und bleibt an...funktioniert.
Kurz darauf kommt der "Idle" Sound.....funktioniert auch.
Wenn ich wieder Rechtsklicke geht er aus....funktioniert auch..
Was nicht funktioniert ist , wenn ich den Generator laufen lasse und offline gehe.....wieder on komme....steht zwar alles auf true, jedoch der "Idle" Sound ist nicht zu hören.
Nur wenn ich ihn ausschalte und wieder einschalte ist er wieder da, aber nur solange ich online bin....
Weiß von euch jemand einen Rat? ich verzweifle so langsam ....
Tutorials über SoundHandler finde ich nur sehr wenige bis garkeine.....
mein Block (Auszug):
Code:
@Override
public void keyRightClick(World world, int x, int y, int z)
{
TileEntityMachineGeneratorG100 tileE = (TileEntityMachineGeneratorG100) world.getTileEntity(x, y, z);
if(!world.isRemote && world.getTileEntity(x, y, z) != null)
{
boolean machineStart = ((TileEntityMachineGeneratorG100)tileE).isActivateMachineStart();
((TileEntityMachineGeneratorG100)tileE).setActivateMachineStart(!machineStart);
}
}
mein TileEntity:
Code:
public class TileEntityMachineGeneratorG100 extends TileEntity implements IInventory, ISidedInventory
{
public boolean machineStart = false;
public boolean machineActive = false;
public int fuelLevelPetrol = 0;
public int fuelLevelPetrolMax = 1000;
private String machineGeneratorLoop = "cmm:machine_generator_loop";
private boolean isPlaying = false;
private boolean shouldStart = false;
private boolean shouldStop = false;
private float soundVolume = 1.0F;
@Override
public void updateEntity()
{
updateFuelEngine();
if(this.machineStart && this.fuelLevelPetrol > 0)
{
this.machineActive = true;
}
else if(!this.machineStart && this.machineActive)
{
this.machineActive = false;
}
if(this.machineActive)
{
if(!this.isPlaying && this.shouldStart)
{
this.shouldStart = false;
this.shouldStop = false;
this.isPlaying = true;
CMM.proxy.soundLooping(worldObj.getTileEntity(xCoord, yCoord, zCoord), machineGeneratorLoop);
}
}
}
public Packet getDescriptionPacket()
{
NBTTagCompound tag = new NBTTagCompound();
writeToNBT(tag);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1 ,tag);
}
public void onDataPacket(NetworkManager manager, S35PacketUpdateTileEntity packet)
{
readFromNBT(packet.func_148857_g());
}
public void writeToNBT(NBTTagCompound tag)
{
super.writeToNBT(tag);
tag.setBoolean("machineStart", machineStart);
tag.setBoolean("machineActive", machineActive);
tag.setInteger("fuelLevelPetrol", fuelLevelPetrol);
tag.setInteger("fuelLevelPetrolMax", fuelLevelPetrolMax);
tag.setBoolean("shouldStart", shouldStart);
tag.setBoolean("isPlaying", isPlaying);
tag.setBoolean("shouldStop", shouldStop);
tag.setFloat("soundVolume", soundVolume);
}
public void readFromNBT(NBTTagCompound tag)
{
super.readFromNBT(tag);
machineStart = tag.getBoolean("machineStart");
machineActive = tag.getBoolean("machineActive");
fuelLevelPetrol = tag.getInteger("fuelLevelPetrol");
fuelLevelPetrolMax = tag.getInteger("fuelLevelPetrolMax");
shouldStart = tag.getBoolean("shouldStart");
isPlaying = tag.getBoolean("isPlaying");
shouldStop = tag.getBoolean("shouldStop");
soundVolume = tag.getFloat("soundVolume");
}
public boolean isActivateMachineStart()
{
return this.machineStart;
}
public void setActivateMachineStart(boolean machineStartActivated)
{
if(this.machineStart != machineStartActivated)
{
if(!this.machineStart && this.fuelLevelPetrol <= 0)
{
this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, "cmm:machine_generator_start_fail", 2.0F, 1.0F);
this.machineStart = false;
CMM.CMMNet.sendToAll(new PacketMachineGenerators(xCoord, yCoord, zCoord, false, false));
}
else if(!this.machineStart && this.fuelLevelPetrol > 0)
{
this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, "cmm:machine_generator_start", 2.0F, 1.0F);
this.machineStart = true;
this.machineActive = true;
this.setShouldStart(true);
CMM.CMMNet.sendToAll(new PacketMachineGenerators(xCoord, yCoord, zCoord, true, true));
}
else if(this.machineStart)
{
this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, "cmm:machine_generator_stop", 2.0F, 1.0F);
this.machineStart = false;
this.machineActive = false;
this.setShouldStop(true);
CMM.CMMNet.sendToAll(new PacketMachineGenerators(xCoord, yCoord, zCoord, false, false));
}
}
}
public boolean isShouldStop()
{
return shouldStop;
}
public boolean isPlaying()
{
return isPlaying;
}
public void setShouldStart(boolean shouldStart)
{
this.shouldStart = shouldStart;
}
public void setShouldStop(boolean shouldStop)
{
if(isPlaying)
{
isPlaying = false;
this.shouldStop = shouldStop;
}
}
}
Code:
public class AudioHandler extends MovingSound
{
private final TileEntity tileE;
private TileEntityMachineGeneratorG100 tileEMachineGeneratorG100;
public AudioHandler(TileEntity tileE, String soundName)
{
super(new ResourceLocation(CMM.modid + ":" + soundName));
this.tileE = tileE;
this.repeat = true;
this.volume = 1.0F;
this.xPosF = tileE.xCoord;
this.yPosF = tileE.yCoord;
this.zPosF = tileE.zCoord;
this.tileEMachineGeneratorG100 = (TileEntityMachineGeneratorG100) tileE;
}
@Override
public void update()
{
if(tileEMachineGeneratorG100.isShouldStop())
{
this.donePlaying = true;
}
}
@Override
public boolean isDonePlaying()
{
return this.donePlaying;
}
}
Common:
Code:
public class CommonProxy
{
public void registerRenderer() {}
public void soundLooping(TileEntity tileE, String soundName) {}
}
Code:
public class ClientProxy extends CommonProxy
{
@Override
public void registerRenderer()
{
ClientRegistry.registerTileEntity(TileEntityMachineGeneratorG100.class,CMM.modid + ":" + Names.FUELENGINE_ENERGY_GENERATOR_G100, new TileEntityMachineGeneratorG100Renderer());
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(RegisterCMMMachines.blockMachineGeneratorG100), ItemMachineGeneratorG100Renderer.instance);
}
@Override
public void soundLooping(TileEntity tileE, String soundName)
{
AudioHandler audioHandler = new AudioHandler(tileE , soundName);
Minecraft.getMinecraft().getSoundHandler().playSound(audioHandler);
}
}
Code:
public interface IProxy
{
public abstract void soundLooping(TileEntity tileE, String soundName);
}