mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-27 23:45:55 +00:00
Add machine sounds base, add sound and change particles for stirling gen
This commit is contained in:
1 parent
9a840010a1
commit
88b303b509
6 files changed
+138
-6
No files matched your search
@@ -13,12 +13,15 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.event.terraingen.BiomeEvent.GetGrassColor;
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.TileEntityEio;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
@@ -66,6 +69,9 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
|
||||
protected boolean notifyNeighbours = false;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private MachineSound sound;
|
||||
|
||||
public AbstractMachineEntity(SlotDefinition slotDefinition, Type powerType) {
|
||||
this.slotDefinition = slotDefinition;
|
||||
facing = 3;
|
||||
@@ -194,6 +200,33 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
|
||||
public abstract float getProgress();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ResourceLocation getSound() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean hasSound() {
|
||||
return getSound() != null;
|
||||
}
|
||||
|
||||
public float getVolume() {
|
||||
return 0.75f;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private void updateSound() {
|
||||
if(isActive() && !isInvalid()) {
|
||||
if(sound == null) {
|
||||
sound = new MachineSound(getSound(), xCoord + 0.5f, yCoord + 0.5f, zCoord + 0.5f, getVolume());
|
||||
FMLClientHandler.instance().getClient().getSoundHandler().playSound(sound);
|
||||
}
|
||||
} else if(sound != null) {
|
||||
sound.endPlaying();
|
||||
sound = null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getProgressScaled(int scale) {
|
||||
int result = (int) (getProgress() * scale);
|
||||
return result;
|
||||
@@ -302,10 +335,16 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
}
|
||||
}
|
||||
|
||||
if(forceClientUpdate) {
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
forceClientUpdate = false;
|
||||
if(hasSound()) {
|
||||
updateSound();
|
||||
}
|
||||
|
||||
if(worldObj.isRemote && isActive())
|
||||
|
||||
if(forceClientUpdate) {
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
forceClientUpdate = false;
|
||||
}
|
||||
return;
|
||||
|
||||
} // else is server, do all logic only on the server
|
||||
@@ -474,6 +513,12 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
// ---- Tile Entity
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
updateSound();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readCustomNBT(NBTTagCompound nbtRoot) {
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package crazypants.enderio.machine;
|
||||
|
||||
import net.minecraft.client.audio.ITickableSound;
|
||||
import net.minecraft.client.audio.PositionedSound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class MachineSound extends PositionedSound implements ITickableSound{
|
||||
|
||||
private boolean donePlaying;
|
||||
|
||||
public MachineSound(ResourceLocation sound, float x, float y, float z, float volume) {
|
||||
super(sound);
|
||||
this.xPosF = x;
|
||||
this.yPosF = y;
|
||||
this.zPosF = z;
|
||||
this.volume = volume;
|
||||
this.repeat = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDonePlaying() {
|
||||
return donePlaying;
|
||||
}
|
||||
|
||||
public void endPlaying() {
|
||||
donePlaying = true;
|
||||
}
|
||||
|
||||
public void startPlaying() {
|
||||
donePlaying = false;
|
||||
}
|
||||
}
|
||||
+33
-2
@@ -1,8 +1,14 @@
|
||||
package crazypants.enderio.machine.generator.stirling;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.sun.org.apache.xml.internal.resolver.readers.XCatalogReader;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.machine.AbstractMachineBlock;
|
||||
@@ -11,9 +17,9 @@ import crazypants.enderio.network.PacketHandler;
|
||||
public class BlockStirlingGenerator extends AbstractMachineBlock<TileEntityStirlingGenerator> {
|
||||
|
||||
public static BlockStirlingGenerator create() {
|
||||
|
||||
|
||||
PacketHandler.INSTANCE.registerMessage(PacketBurnTime.class, PacketBurnTime.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
|
||||
|
||||
BlockStirlingGenerator gen = new BlockStirlingGenerator();
|
||||
gen.init();
|
||||
return gen;
|
||||
@@ -46,5 +52,30 @@ public class BlockStirlingGenerator extends AbstractMachineBlock<TileEntityStirl
|
||||
return "enderio:stirlingGenFrontOff";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void randomDisplayTick(World world, int x, int y, int z, Random rand) {
|
||||
TileEntityStirlingGenerator te = (TileEntityStirlingGenerator) world.getTileEntity(x, y, z);
|
||||
if(te != null && te.isActive()) {
|
||||
ForgeDirection front = ForgeDirection.values()[te.facing];
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
double px = x + 0.5 + front.offsetX * 0.6;
|
||||
double pz = z + 0.5 + front.offsetZ * 0.6;
|
||||
double v = 0.05;
|
||||
double vx = 0;
|
||||
double vz = 0;
|
||||
|
||||
if(front == ForgeDirection.NORTH || front == ForgeDirection.SOUTH) {
|
||||
px += world.rand.nextFloat() * 0.9 - 0.45;
|
||||
vz += front == ForgeDirection.NORTH ? -v : v;
|
||||
} else {
|
||||
pz += world.rand.nextFloat() * 0.9 - 0.45;
|
||||
vx += front == ForgeDirection.WEST ? -v : v;
|
||||
}
|
||||
|
||||
world.spawnParticle("smoke", px, y + 0.1, pz, vx, 0, vz);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -1,13 +1,17 @@
|
||||
package crazypants.enderio.machine.generator.stirling;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.power.IPowerEmitter;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.machine.AbstractMachineEntity;
|
||||
import crazypants.enderio.machine.IoMode;
|
||||
@@ -27,9 +31,12 @@ public class TileEntityStirlingGenerator extends AbstractMachineEntity implement
|
||||
|
||||
private PowerDistributor powerDis;
|
||||
|
||||
private static final ResourceLocation sound = new ResourceLocation(EnderIO.MODID + ":generator.stirling");
|
||||
|
||||
public TileEntityStirlingGenerator() {
|
||||
super(new SlotDefinition(1, 0), Type.ENGINE);
|
||||
configurePowerHandler();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,6 +107,12 @@ public class TileEntityStirlingGenerator extends AbstractMachineEntity implement
|
||||
return (float) burnTime / (float) totalBurnTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ResourceLocation getSound() {
|
||||
return sound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readCustomNBT(NBTTagCompound nbtRoot) {
|
||||
super.readCustomNBT(nbtRoot);
|
||||
|
||||
Reference in new issue
Block a user