Sound system is mostly done, I'll probably record new versions of the sounds in a few weeks (to remove frequency changes within a segment)
This commit is contained in:
parent
b12501a86c
commit
3f08c47a73
|
@ -24,6 +24,7 @@ import malte0811.industrialWires.containers.ContainerPanelCreator;
|
|||
import malte0811.industrialWires.containers.ContainerRSPanelConn;
|
||||
import malte0811.industrialWires.containers.ContainerRenameKey;
|
||||
import malte0811.industrialWires.converter.MechEnergy;
|
||||
import net.minecraft.client.audio.ISound;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -34,6 +35,8 @@ import net.minecraft.util.math.Vec3d;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.network.IGuiHandler;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class CommonProxy implements IGuiHandler {
|
||||
public void preInit() {
|
||||
}
|
||||
|
@ -83,6 +86,6 @@ public abstract class CommonProxy implements IGuiHandler {
|
|||
|
||||
public void playMechMBBang(TileEntityMechMB te, float volume) {}
|
||||
|
||||
public void playMechMBTurning(TileEntityMechMB te, MechEnergy energy) {}
|
||||
public void stopAllSounds(BlockPos pos) {}
|
||||
public void updateMechMBTurningSound(TileEntityMechMB te, MechEnergy energy) {}
|
||||
public void stopAllSoundsExcept(BlockPos pos, Set<ISound> excluded) {}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
package malte0811.industrialWires.blocks;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -67,13 +68,13 @@ public abstract class TileEntityIWBase extends TileEntity {
|
|||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
IndustrialWires.proxy.stopAllSounds(pos);
|
||||
IndustrialWires.proxy.stopAllSoundsExcept(pos, ImmutableSet.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload() {
|
||||
super.onChunkUnload();
|
||||
IndustrialWires.proxy.stopAllSounds(pos);
|
||||
IndustrialWires.proxy.stopAllSoundsExcept(pos, ImmutableSet.of());
|
||||
}
|
||||
|
||||
public abstract void writeNBT(NBTTagCompound out, boolean updatePacket);
|
||||
|
|
|
@ -87,11 +87,20 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
|
|||
private boolean firstTick = true;
|
||||
// To allow changing the MB structure later on without resulting in dupes/conversion
|
||||
private int structureVersion = 0;
|
||||
private int soundTimingOffset = 0;
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
ApiUtils.checkForNeedlessTicking(this);
|
||||
if (isLogicDummy() || mechanical == null) {
|
||||
return;
|
||||
}
|
||||
if (world.isRemote) {
|
||||
angle += energyState.getSpeed() * TICK_ANGLE_PER_SPEED;
|
||||
angle %= 360;
|
||||
if (energyState.clientUpdate()||firstTick) {
|
||||
IndustrialWires.proxy.updateMechMBTurningSound(this, energyState);
|
||||
}
|
||||
}
|
||||
if (firstTick) {
|
||||
//TODO make safe for when IC2 isn't installed
|
||||
if (!world.isRemote && IndustrialWires.hasIC2) {
|
||||
|
@ -99,14 +108,7 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
|
|||
}
|
||||
firstTick = false;
|
||||
}
|
||||
if (world.isRemote && mechanical != null) {
|
||||
angle += energyState.getSpeed() * TICK_ANGLE_PER_SPEED;
|
||||
angle %= 360;
|
||||
if (energyState.getSpeed()>1 && soundTimingOffset==world.getTotalWorldTime()%TURN_SOUND_LENGTH) {
|
||||
IndustrialWires.proxy.playMechMBTurning(this, energyState);
|
||||
}
|
||||
}
|
||||
if (world.isRemote || isLogicDummy() || mechanical == null) {
|
||||
if (world.isRemote) {
|
||||
return;
|
||||
}
|
||||
if (shouldInitWorld) {
|
||||
|
@ -340,8 +342,7 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
|
|||
|
||||
@Override
|
||||
public void onSync(NBTTagCompound nbt) {
|
||||
energyState.setSpeed(nbt.getDouble(SPEED));
|
||||
soundTimingOffset = (int) (world.getTotalWorldTime()%TURN_SOUND_LENGTH);
|
||||
energyState.setTargetSpeed(nbt.getDouble(SPEED));
|
||||
}
|
||||
|
||||
private AxisAlignedBB rBB;
|
||||
|
|
|
@ -24,6 +24,7 @@ import blusunrize.lib.manual.ManualInstance;
|
|||
import blusunrize.lib.manual.ManualPages;
|
||||
import blusunrize.lib.manual.ManualPages.PositionedItemStack;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import malte0811.industrialWires.CommonProxy;
|
||||
import malte0811.industrialWires.IWConfig;
|
||||
import malte0811.industrialWires.IWPotions;
|
||||
|
@ -338,7 +339,7 @@ public class ClientProxy extends CommonProxy {
|
|||
|
||||
@Override
|
||||
public void playJacobsLadderSound(TileEntityJacobsLadder te, int phase, Vec3d soundPos) {
|
||||
stopAllSounds(te.getPos());
|
||||
stopAllSoundsExcept(te.getPos(), ImmutableSet.of());
|
||||
ResourceLocation event;
|
||||
switch (phase) {
|
||||
case 0:
|
||||
|
@ -353,7 +354,8 @@ public class ClientProxy extends CommonProxy {
|
|||
default:
|
||||
return;
|
||||
}
|
||||
PositionedSoundRecord sound = new PositionedSoundRecord(event, SoundCategory.BLOCKS, te.size.soundVolume, 1, false, 0, ISound.AttenuationType.LINEAR, (float) soundPos.x, (float) soundPos.y, (float) soundPos.z);
|
||||
PositionedSoundRecord sound = new PositionedSoundRecord(event, SoundCategory.BLOCKS, te.size.soundVolume, 1,
|
||||
false, 0, ISound.AttenuationType.LINEAR, (float) soundPos.x, (float) soundPos.y, (float) soundPos.z);
|
||||
ClientUtils.mc().getSoundHandler().playSound(sound);
|
||||
addSound(te.getPos(), sound);
|
||||
}
|
||||
|
@ -368,24 +370,33 @@ public class ClientProxy extends CommonProxy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void playMechMBTurning(TileEntityMechMB te, MechEnergy energy) {
|
||||
stopAllSounds(te.getPos());
|
||||
float lambda = MathHelper.clamp((float) energy.getSpeed()/20-.5F, 0, 1);
|
||||
float totalVolume = (float) (energy.weight/50e3*Math.sqrt(energy.getSpeed()));
|
||||
if (lambda>0) {
|
||||
PositionedSoundRecord sound = new PositionedSoundRecord(turnFast, SoundCategory.BLOCKS, lambda*totalVolume, 1,
|
||||
false, 0, ISound.AttenuationType.LINEAR, te.getPos().getX(), te.getPos().getY(),
|
||||
te.getPos().getZ());
|
||||
ClientUtils.mc().getSoundHandler().playSound(sound);
|
||||
addSound(te.getPos(), sound);
|
||||
}
|
||||
if (lambda<1) {
|
||||
PositionedSoundRecord sound = new PositionedSoundRecord(turnSlow, SoundCategory.BLOCKS, (1-lambda)*totalVolume, 1,
|
||||
false, 0, ISound.AttenuationType.LINEAR, te.getPos().getX(), te.getPos().getY(),
|
||||
te.getPos().getZ());
|
||||
ClientUtils.mc().getSoundHandler().playSound(sound);
|
||||
addSound(te.getPos(), sound);
|
||||
public void updateMechMBTurningSound(TileEntityMechMB te, MechEnergy energy) {
|
||||
final double MIN_SPEED = 5;
|
||||
Set<ISound> added = new HashSet<>();
|
||||
if (energy.getSpeed() > MIN_SPEED) {
|
||||
boolean adjusting = energy.isAdjusting();
|
||||
double speedToUse = energy.getSpeed()-MIN_SPEED;//Volume should be zero by the time the sound stops
|
||||
float lambda = MathHelper.clamp((float) speedToUse / 20 - .5F, 0, 1);
|
||||
float totalVolume = (float) (energy.weight / 50e3 * Math.sqrt(speedToUse));
|
||||
float pitch = (float) Math.min(Math.sqrt(speedToUse), 3);
|
||||
if (lambda > 0) {
|
||||
PositionedSoundRecord sound = new PositionedSoundRecord(turnFast, SoundCategory.BLOCKS, lambda * totalVolume, pitch,
|
||||
!adjusting, 0, ISound.AttenuationType.LINEAR, te.getPos().getX(), te.getPos().getY(),
|
||||
te.getPos().getZ());
|
||||
ClientUtils.mc().getSoundHandler().playSound(sound);
|
||||
addSound(te.getPos(), sound);
|
||||
added.add(sound);
|
||||
}
|
||||
if (lambda < 1) {
|
||||
PositionedSoundRecord sound = new PositionedSoundRecord(turnSlow, SoundCategory.BLOCKS, (1 - lambda) * totalVolume, pitch,
|
||||
!adjusting, 0, ISound.AttenuationType.LINEAR, te.getPos().getX(), te.getPos().getY(),
|
||||
te.getPos().getZ());
|
||||
ClientUtils.mc().getSoundHandler().playSound(sound);
|
||||
addSound(te.getPos(), sound);
|
||||
added.add(sound);
|
||||
}
|
||||
}
|
||||
stopAllSoundsExcept(te.getPos(), added);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -413,13 +424,21 @@ public class ClientProxy extends CommonProxy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void stopAllSounds(BlockPos pos) {
|
||||
public void stopAllSoundsExcept(BlockPos pos, Set<ISound> excluded) {
|
||||
if (playingSounds.containsKey(pos)) {
|
||||
SoundHandler manager = Minecraft.getMinecraft().getSoundHandler();
|
||||
for (ISound sound:playingSounds.get(pos)) {
|
||||
manager.stopSound(sound);
|
||||
List<ISound> sounds = playingSounds.get(pos);
|
||||
List<ISound> toRemove = new ArrayList<>(sounds.size()-excluded.size());
|
||||
for (ISound sound:sounds) {
|
||||
if (!excluded.contains(sound)) {
|
||||
manager.stopSound(sound);
|
||||
toRemove.add(sound);
|
||||
}
|
||||
}
|
||||
sounds.removeAll(toRemove);
|
||||
if (sounds.isEmpty()) {
|
||||
playingSounds.remove(pos);
|
||||
}
|
||||
playingSounds.remove(pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,15 +16,21 @@
|
|||
package malte0811.industrialWires.converter;
|
||||
|
||||
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public final class MechEnergy {
|
||||
private double speed = 0;
|
||||
public final double weight;
|
||||
|
||||
public MechEnergy(double weight, double speed) {
|
||||
this.weight = weight;
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public double getEnergy() {
|
||||
return .5*weight*speed*speed;
|
||||
return .5 * weight * speed * speed;
|
||||
}
|
||||
|
||||
public double getSpeed() {
|
||||
|
@ -32,32 +38,58 @@ public final class MechEnergy {
|
|||
}
|
||||
|
||||
public void addEnergy(double energy) {
|
||||
if (energy<=0) {
|
||||
if (energy <= 0) {
|
||||
return;
|
||||
}
|
||||
double targetEnergy = getEnergy()+energy;
|
||||
speed = Math.sqrt(2*targetEnergy/weight);
|
||||
//IndustrialWires.logger.info("Added {}", energy);
|
||||
double targetEnergy = getEnergy() + energy;
|
||||
speed = Math.sqrt(2 * targetEnergy / weight);
|
||||
}
|
||||
|
||||
public void extractEnergy(double energy) {
|
||||
if (energy<=0) {
|
||||
if (energy <= 0) {
|
||||
return;
|
||||
}
|
||||
double oldEnergy = getEnergy();
|
||||
energy = Math.min(energy, oldEnergy);
|
||||
speed = Math.sqrt(2*(oldEnergy-energy)/weight);
|
||||
//IndustrialWires.logger.info("Extracted {}", energy);
|
||||
speed = Math.sqrt(2 * (oldEnergy - energy) / weight);
|
||||
}
|
||||
|
||||
public void decaySpeed(double decay) {
|
||||
speed *= decay;
|
||||
if (speed<.1)
|
||||
if (speed < .1)
|
||||
speed = 0;
|
||||
}
|
||||
|
||||
private static final int TICKS_FOR_ADJUSTMENT = 30;
|
||||
private double targetSpeed;
|
||||
private double oldSpeed = -1;
|
||||
private int ticksTillReached;
|
||||
|
||||
//ONLY USE FOR SYNCING
|
||||
public void setSpeed(double speed) {
|
||||
this.speed = speed;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void setTargetSpeed(double speed) {
|
||||
targetSpeed = speed;
|
||||
oldSpeed = getSpeed();
|
||||
IndustrialWires.logger.info(targetSpeed+" from "+oldSpeed);
|
||||
ticksTillReached = TICKS_FOR_ADJUSTMENT;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean clientUpdate() {
|
||||
if (ticksTillReached >= 0) {
|
||||
speed = ((TICKS_FOR_ADJUSTMENT - ticksTillReached) * targetSpeed +
|
||||
ticksTillReached * oldSpeed) / TICKS_FOR_ADJUSTMENT;
|
||||
ticksTillReached--;
|
||||
return true;
|
||||
} else {
|
||||
oldSpeed = -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean isAdjusting()
|
||||
{
|
||||
return ticksTillReached>=0;
|
||||
}
|
||||
}
|
|
@ -73,8 +73,7 @@
|
|||
"industrialwires:mech_mb/turn_fast_003",
|
||||
"industrialwires:mech_mb/turn_fast_004",
|
||||
"industrialwires:mech_mb/turn_fast_005",
|
||||
"industrialwires:mech_mb/turn_fast_006",
|
||||
"industrialwires:mech_mb/turn_fast_007"
|
||||
"industrialwires:mech_mb/turn_fast_006"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue