Mech MB sound, take 1

This commit is contained in:
malte0811 2018-04-22 22:14:08 +02:00
parent 1959b93f5b
commit b12501a86c
28 changed files with 254 additions and 136 deletions

View file

@ -16,12 +16,14 @@ package malte0811.industrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanelCreator;
import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn;
import malte0811.industrialWires.blocks.converter.TileEntityMechMB;
import malte0811.industrialWires.blocks.hv.TileEntityJacobsLadder;
import malte0811.industrialWires.blocks.hv.TileEntityMarx;
import malte0811.industrialWires.containers.ContainerPanelComponent;
import malte0811.industrialWires.containers.ContainerPanelCreator;
import malte0811.industrialWires.containers.ContainerRSPanelConn;
import malte0811.industrialWires.containers.ContainerRenameKey;
import malte0811.industrialWires.converter.MechEnergy;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
@ -32,7 +34,7 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;
public class CommonProxy implements IGuiHandler {
public abstract class CommonProxy implements IGuiHandler {
public void preInit() {
}
@ -78,4 +80,9 @@ public class CommonProxy implements IGuiHandler {
}
public void playMarxBang(TileEntityMarx tileEntityMarx, Vec3d vec3d, float energy) {}
public void playMechMBBang(TileEntityMechMB te, float volume) {}
public void playMechMBTurning(TileEntityMechMB te, MechEnergy energy) {}
public void stopAllSounds(BlockPos pos) {}
}

View file

@ -165,7 +165,7 @@ public class IndustrialWires {
GameRegistry.registerTileEntity(TileEntityMechIEtoIC.class, MODID + ":mechIeToIc");
}
}
GameRegistry.registerTileEntity(TileEntityMultiblockConverter.class, MODID + ":mechMB");
GameRegistry.registerTileEntity(TileEntityMechMB.class, MODID + ":mechMB");
GameRegistry.registerTileEntity(TileEntityJacobsLadder.class, MODID + ":jacobsLadder");
GameRegistry.registerTileEntity(TileEntityMarx.class, MODID + ":marx_generator");
GameRegistry.registerTileEntity(TileEntityPanel.class, MODID + ":control_panel");

View file

@ -14,6 +14,7 @@
*/
package malte0811.industrialWires.blocks;
import malte0811.industrialWires.IndustrialWires;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
@ -63,6 +64,18 @@ public abstract class TileEntityIWBase extends TileEntity {
world.addBlockEvent(pos, state.getBlock(), 255, 0);
}
@Override
public void invalidate() {
super.invalidate();
IndustrialWires.proxy.stopAllSounds(pos);
}
@Override
public void onChunkUnload() {
super.onChunkUnload();
IndustrialWires.proxy.stopAllSounds(pos);
}
public abstract void writeNBT(NBTTagCompound out, boolean updatePacket);
public abstract void readNBT(NBTTagCompound in, boolean updatePacket);

View file

@ -51,7 +51,7 @@ public class BlockMechanicalMB extends BlockIWMultiblock implements IMetaEnum {
@Nullable
@Override
public TileEntity createTileEntity(@Nonnull World world, @Nonnull IBlockState state) {
return new TileEntityMultiblockConverter();
return new TileEntityMechMB();
}
@Override

View file

@ -66,11 +66,12 @@ import static malte0811.industrialWires.util.NBTKeys.*;
@net.minecraftforge.fml.common.Optional.Interface(iface = "ic2.api.energy.tile.IEnergySource", modid = "ic2"),
@Optional.Interface(iface = "ic2.api.energy.tile.IEnergySink", modid = "ic2")
})
public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implements ITickable, ISyncReceiver,
public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickable, ISyncReceiver,
IEnergySource, IEnergySink, IPlayerInteraction, IRedstoneOutput, IBlockBoundsDirectional {
private static final double DECAY_BASE = Math.exp(Math.log(.8)/(2*60*60*20));
public static final double TICK_ANGLE_PER_SPEED = 180/20/Math.PI;
private static final double DECAY_BASE = Math.exp(Math.log(.8) / (2 * 60 * 60 * 20));
public static final double TICK_ANGLE_PER_SPEED = 180 / 20 / Math.PI;
private static final double SYNC_THRESHOLD = .95;
private static final int TURN_SOUND_LENGTH = 7;
public MechMBPart[] mechanical = null;
private int[] offsets = null;
@ -86,22 +87,26 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
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 (firstTick) {
//TODO make safe for when IC2 isn't installed
if (!world.isRemote&& IndustrialWires.hasIC2) {
if (!world.isRemote && IndustrialWires.hasIC2) {
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
}
firstTick = false;
}
if (world.isRemote&&mechanical!=null) {
angle += energyState.getSpeed()*TICK_ANGLE_PER_SPEED;
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 || isLogicDummy() || mechanical == null) {
return;
}
if (shouldInitWorld) {
@ -113,25 +118,25 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
}
}
// Mechanical
for (MechMBPart part:mechanical) {
for (MechMBPart part : mechanical) {
part.createMEnergy(energyState);
}
double requestSum = 0;
IdentityHashMap<MechMBPart, Double> individualRequests = new IdentityHashMap<>();
for (MechMBPart part:mechanical) {
for (MechMBPart part : mechanical) {
double eForPart = part.requestMEnergy(energyState);
requestSum += eForPart;
individualRequests.put(part, eForPart);
}
double availableEnergy = energyState.getEnergy()/5;//prevent energy transmission without movement
double factor = Math.min(availableEnergy/requestSum, 1);
double availableEnergy = energyState.getEnergy() / 5;//prevent energy transmission without movement
double factor = Math.min(availableEnergy / requestSum, 1);
energyState.extractEnergy(Math.min(requestSum, availableEnergy));
for (MechMBPart part:mechanical) {
part.insertMEnergy(factor*individualRequests.get(part));
for (MechMBPart part : mechanical) {
part.insertMEnergy(factor * individualRequests.get(part));
}
Set<MechMBPart> failed = new HashSet<>();
for (MechMBPart part:mechanical) {
if (energyState.getSpeed()>part.getMaxSpeed()) {
for (MechMBPart part : mechanical) {
if (energyState.getSpeed() > part.getMaxSpeed()) {
failed.add(part);
}
}
@ -141,7 +146,7 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
}
//Electrical
for (int[] section:electricalStartEnd) {
for (int[] section : electricalStartEnd) {
final int sectionLength = section[1] - section[0];
double[] available = new double[sectionLength];
Waveform[] availableWf = new Waveform[sectionLength];
@ -157,7 +162,7 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
double availableLocal = electricalComp.getAvailableEEnergy();
available[i - section[0]] = availableLocal;
availableWaveforms.add(localWf);
if (availableLocal>0) {
if (availableLocal > 0) {
hasEnergy = true;
}
}
@ -182,20 +187,20 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
maxId = i;
}
}
if (maxId<0) {
if (maxId < 0) {
double[] availablePerWf = new double[availableWaveforms.size()];
for (int i = 0;i<availableWf.length;i++) {
for (int i = 0; i < availableWf.length; i++) {
if (availableWf[i].isEnergyWaveform()) {
availablePerWf[availableWfList.indexOf(availableWf[i])] += available[i];
}
}
for (int i = 0;i<availablePerWf.length;i++) {
if (availablePerWf[i]>0&&(maxId<0||availablePerWf[maxId]<availablePerWf[i])) {
for (int i = 0; i < availablePerWf.length; i++) {
if (availablePerWf[i] > 0 && (maxId < 0 || availablePerWf[maxId] < availablePerWf[i])) {
maxId = i;
}
}
}
if (maxId>=0) {
if (maxId >= 0) {
transferElectric(section, available, availableWf, availableWfList.get(maxId), requested[maxId], false);
}
}
@ -204,7 +209,7 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
//General
energyState.decaySpeed(decay);
markDirty();
if (lastSyncedSpeed<energyState.getSpeed()*SYNC_THRESHOLD||lastSyncedSpeed>energyState.getSpeed()/SYNC_THRESHOLD) {
if (lastSyncedSpeed < energyState.getSpeed() * SYNC_THRESHOLD || lastSyncedSpeed > energyState.getSpeed() / SYNC_THRESHOLD) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setDouble(SPEED, energyState.getSpeed());
IndustrialWires.packetHandler.sendToDimension(new MessageTileSyncIW(this, nbt), world.provider.getDimension());
@ -237,29 +242,29 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
electric.insertEEnergy(ins, waveform, energyState);
electric.extractEEnergy(extr);
}
totalTransf += Math.abs(ins-extr);
totalTransf += Math.abs(ins - extr);
}
return totalTransf;
}
@Override
public void writeNBT(NBTTagCompound out, boolean updatePacket) {
super.writeNBT(out, updatePacket);
if (mechanical!=null) {
public void writeNBT(NBTTagCompound out, boolean updatePacket) {
super.writeNBT(out, updatePacket);
if (mechanical != null) {
NBTTagList mechParts = new NBTTagList();
for (MechMBPart part:mechanical) {
for (MechMBPart part : mechanical) {
mechParts.appendTag(MechMBPart.toNBT(part));
}
out.setTag(PARTS, mechParts);
out.setDouble(SPEED, energyState.getSpeed());
}
out.setInteger(VERSION, structureVersion);
}
}
@Override
public void readNBT(NBTTagCompound in, boolean updatePacket) {
super.readNBT(in, updatePacket);
if (in.hasKey(PARTS, Constants.NBT.TAG_LIST)) {
@Override
public void readNBT(NBTTagCompound in, boolean updatePacket) {
super.readNBT(in, updatePacket);
if (in.hasKey(PARTS, Constants.NBT.TAG_LIST)) {
NBTTagList mechParts = in.getTagList(PARTS, Constants.NBT.TAG_COMPOUND);
MechMBPart[] mech = new MechMBPart[mechParts.tagCount()];
int offset = 1;
@ -269,7 +274,7 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
offset += mech[i].getLength();
}
setMechanical(mech, in.getDouble(SPEED));
if (world==null) {
if (world == null) {
shouldInitWorld = true;
}
}
@ -289,14 +294,14 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
offsets[i] = offset;
weight += mechanical[i].getInertia();
offset += mechanical[i].getLength();
if (lastEStart<0&&mechanical[i] instanceof IMBPartElectric) {
if (lastEStart < 0 && mechanical[i] instanceof IMBPartElectric) {
lastEStart = i;
} else if (lastEStart>=0&&!(mechanical[i] instanceof IMBPartElectric)) {
} else if (lastEStart >= 0 && !(mechanical[i] instanceof IMBPartElectric)) {
electrical.add(new int[]{lastEStart, i});
lastEStart = -1;
}
}
if (lastEStart>=0) {
if (lastEStart >= 0) {
electrical.add(new int[]{lastEStart, mechanical.length});
}
electricalStartEnd = electrical.toArray(new int[electrical.size()][]);
@ -304,13 +309,13 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
energyState = new MechEnergy(weight, speed);
}
private int getPart(int offset, TileEntityMultiblockConverter master) {
if (offset==0) {
private int getPart(int offset, TileEntityMechMB master) {
if (offset == 0) {
return -1;
}
int pos = 1;
MechMBPart[] mechMaster = master.mechanical;
if (mechMaster!=null) {
if (mechMaster != null) {
for (int i = 0, mechanical1Length = mechMaster.length; i < mechanical1Length; i++) {
MechMBPart part = mechMaster[i];
if (pos >= offset) {
@ -322,27 +327,29 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
return -1;
}
@Nonnull
@Override
protected BlockPos getOrigin() {
return pos;//Irrelevant, since this uses a custome disassembly method
}
@Nonnull
@Override
protected BlockPos getOrigin() {
return pos;//Irrelevant, since this uses a custom disassembly method
}
@Override
public IBlockState getOriginalBlock() {
return Blocks.AIR.getDefaultState();//Mostly irrelevant, since this uses a custom disassembly method
}
@Override
public IBlockState getOriginalBlock() {
return Blocks.AIR.getDefaultState();// TODO implement for pick block
}
@Override
public void onSync(NBTTagCompound nbt) {
energyState.setSpeed(nbt.getDouble(SPEED));
soundTimingOffset = (int) (world.getTotalWorldTime()%TURN_SOUND_LENGTH);
}
private AxisAlignedBB rBB;
@Nonnull
@Override
public AxisAlignedBB getRenderBoundingBox() {
if (rBB==null) {
if (rBB == null) {
if (isLogicDummy()) {
rBB = new AxisAlignedBB(pos, pos);
} else {
@ -356,13 +363,13 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
@Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
Vec3i offsetDirectional = getOffsetDir();
TileEntityMultiblockConverter master = masterOr(this, this);
TileEntityMechMB master = masterOr(this, this);
int id = getPart(offsetDirectional.getZ(), master);
if (id<0) {
if (id < 0) {
return false;
}
MechMBPart part = master.mechanical[id];
BlockPos offsetPart = new BlockPos(offsetDirectional.getX(), offsetDirectional.getY(), offsetDirectional.getZ()-master.offsets[id]);
BlockPos offsetPart = new BlockPos(offsetDirectional.getX(), offsetDirectional.getY(), offsetDirectional.getZ() - master.offsets[id]);
return part.hasCapability(capability, part.world.realToTransformed(facing), offsetPart);
}
@ -370,13 +377,13 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
Vec3i offsetDirectional = getOffsetDir();
TileEntityMultiblockConverter master = masterOr(this, this);
TileEntityMechMB master = masterOr(this, this);
int id = getPart(offsetDirectional.getZ(), master);
if (id<0) {
if (id < 0) {
return null;
}
MechMBPart part = master.mechanical[id];
BlockPos offsetPart = new BlockPos(offsetDirectional.getX(), offsetDirectional.getY(), offsetDirectional.getZ()-master.offsets[id]);
BlockPos offsetPart = new BlockPos(offsetDirectional.getX(), offsetDirectional.getY(), offsetDirectional.getZ() - master.offsets[id]);
return part.getCapability(capability, part.world.realToTransformed(facing), offsetPart);
}
@ -385,7 +392,7 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
final double MIN_BREAK = .1;
final double MIN_BREAK_BROKEN = .5;
if (formed) {
TileEntityMultiblockConverter master = master(this);
TileEntityMechMB master = master(this);
if (master != null) {
int partId = master.getPart(offset.getX(), master);
MechMBPart broken = null;
@ -404,26 +411,28 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
}
private void disassemble(Set<MechMBPart> failed) {
if (!world.isRemote&&formed) {
if (world.isRemote)
IndustrialWires.proxy.playMechMBBang(this, failed.size()*2);//TODO this doesn't run client-side
if (!world.isRemote && formed) {
formed = false;
world.setBlockState(pos,
blockMetalDecoration0.getDefaultState().withProperty(blockMetalDecoration0.property, HEAVY_ENGINEERING));
world.setBlockState(pos.down(),
blockMetalDecoration0.getDefaultState().withProperty(blockMetalDecoration0.property, HEAVY_ENGINEERING));
for (MechMBPart mech:mechanical) {
for (MechMBPart mech : mechanical) {
mech.disassemble(failed.contains(mech), energyState);
short pattern = mech.getFormPattern();
for (int i = 0;i<9;i++) {
if (((pattern>>i)&1)!=0) {
BlockPos pos = new BlockPos(i%3-1, i/3-1, 0);
if (mech.world.getBlockState(pos).getBlock()==IndustrialWires.mechanicalMB) {
for (int i = 0; i < 9; i++) {
if (((pattern >> i) & 1) != 0) {
BlockPos pos = new BlockPos(i % 3 - 1, i / 3 - 1, 0);
if (mech.world.getBlockState(pos).getBlock() == IndustrialWires.mechanicalMB) {
mech.world.setBlockState(pos, Blocks.AIR.getDefaultState());
}
}
}
}
BlockPos otherEnd = offset(pos, facing.getOpposite(), mirrored, 0,
offsets[offsets.length-1]+mechanical[mechanical.length-1].getLength(), 0);
offsets[offsets.length - 1] + mechanical[mechanical.length - 1].getLength(), 0);
world.setBlockState(otherEnd,
blockMetalDecoration0.getDefaultState().withProperty(blockMetalDecoration0.property, HEAVY_ENGINEERING));
world.setBlockState(otherEnd.down(),
@ -432,69 +441,69 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
}
private EUCapability.IC2EnergyHandler getIC2Cap() {
return ENERGY_IC2!=null?getCapability(ENERGY_IC2, null):null;
return ENERGY_IC2 != null ? getCapability(ENERGY_IC2, null) : null;
}
@Override
public boolean emitsEnergyTo(IEnergyAcceptor output, EnumFacing side) {
if (ENERGY_IC2==null)
if (ENERGY_IC2 == null)
return false;
Vec3i offsetDirectional = getOffsetDir();
TileEntityMultiblockConverter master = masterOr(this, this);
TileEntityMechMB master = masterOr(this, this);
int id = getPart(offsetDirectional.getZ(), master);
if (id<0) {
if (id < 0) {
return false;
}
MechMBPart part = master.mechanical[id];
BlockPos offsetPart = new BlockPos(offsetDirectional.getX(), offsetDirectional.getY(), offsetDirectional.getZ()-master.offsets[id]);
EUCapability.IC2EnergyHandler cap = part.getCapability(ENERGY_IC2, part.world.realToTransformed(side), offsetPart);
return cap!=null;
BlockPos offsetPart = new BlockPos(offsetDirectional.getX(), offsetDirectional.getY(), offsetDirectional.getZ() - master.offsets[id]);
EUCapability.IC2EnergyHandler cap = part.getCapability(ENERGY_IC2, part.world.realToTransformed(side), offsetPart);
return cap != null;
}
@Override
public double getDemandedEnergy() {
EUCapability.IC2EnergyHandler cap = getIC2Cap();
return cap!=null?cap.getDemandedEnergy():0;
return cap != null ? cap.getDemandedEnergy() : 0;
}
@Override
public int getSinkTier() {
EUCapability.IC2EnergyHandler cap = getIC2Cap();
return cap!=null?cap.getEnergyTier():0;
return cap != null ? cap.getEnergyTier() : 0;
}
@Override
public double injectEnergy(EnumFacing enumFacing, double amount, double voltage) {
EUCapability.IC2EnergyHandler cap = getIC2Cap();
return cap!=null?cap.injectEnergy(enumFacing, amount, voltage):0;
return cap != null ? cap.injectEnergy(enumFacing, amount, voltage) : 0;
}
@Override
public boolean acceptsEnergyFrom(IEnergyEmitter input, EnumFacing side) {
if (ENERGY_IC2==null)
if (ENERGY_IC2 == null)
return false;
Vec3i offsetDirectional = getOffsetDir();
TileEntityMultiblockConverter master = masterOr(this, this);
TileEntityMechMB master = masterOr(this, this);
int id = getPart(offsetDirectional.getZ(), master);
if (id<0) {
if (id < 0) {
return false;
}
MechMBPart part = master.mechanical[id];
BlockPos offsetPart = new BlockPos(offsetDirectional.getX(), offsetDirectional.getY(), offsetDirectional.getZ()-master.offsets[id]);
EUCapability.IC2EnergyHandler cap = part.getCapability(ENERGY_IC2, part.world.realToTransformed(side), offsetPart);
return cap!=null;
BlockPos offsetPart = new BlockPos(offsetDirectional.getX(), offsetDirectional.getY(), offsetDirectional.getZ() - master.offsets[id]);
EUCapability.IC2EnergyHandler cap = part.getCapability(ENERGY_IC2, part.world.realToTransformed(side), offsetPart);
return cap != null;
}
@Override
public double getOfferedEnergy() {
EUCapability.IC2EnergyHandler cap = getIC2Cap();
return cap!=null?cap.getOfferedEnergy():0;
return cap != null ? cap.getOfferedEnergy() : 0;
}
@Override
public void drawEnergy(double amount) {
EUCapability.IC2EnergyHandler cap = getIC2Cap();
if (cap!=null) {
if (cap != null) {
cap.drawEnergy(amount);
}
}
@ -502,7 +511,7 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
@Override
public int getSourceTier() {
EUCapability.IC2EnergyHandler cap = getIC2Cap();
return cap!=null?cap.getEnergyTier():0;
return cap != null ? cap.getEnergyTier() : 0;
}
@ -525,10 +534,10 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
@Override
public boolean interact(@Nonnull EnumFacing side, @Nonnull EntityPlayer player, @Nonnull EnumHand hand,
@Nonnull ItemStack heldItem, float hitX, float hitY, float hitZ) {
TileEntityMultiblockConverter master = masterOr(this, this);
TileEntityMechMB master = masterOr(this, this);
int id = getPart(getOffsetDir().getZ(), master);
if (id>=0&&master.mechanical[id] instanceof IPlayerInteraction) {
return ((IPlayerInteraction)master.mechanical[id]).interact(side, player, hand, heldItem, hitX, hitY, hitZ);
if (id >= 0 && master.mechanical[id] instanceof IPlayerInteraction) {
return ((IPlayerInteraction) master.mechanical[id]).interact(side, player, hand, heldItem, hitX, hitY, hitZ);
}
return false;
}
@ -540,11 +549,11 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
@Override
public int getStrongRSOutput(@Nonnull IBlockState state, @Nonnull EnumFacing side) {
TileEntityMultiblockConverter master = masterOr(this, this);
TileEntityMechMB master = masterOr(this, this);
int id = getPart(getOffsetDir().getZ(), master);
if (id>=0&&master.mechanical[id] instanceof IRedstoneOutput) {
if (id >= 0 && master.mechanical[id] instanceof IRedstoneOutput) {
MechMBPart part = master.mechanical[id];
return ((IRedstoneOutput)part).getStrongRSOutput(state,
return ((IRedstoneOutput) part).getStrongRSOutput(state,
part.world.realToTransformed(side));
}
return 0;
@ -552,11 +561,11 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
@Override
public boolean canConnectRedstone(@Nonnull IBlockState state, @Nonnull EnumFacing side) {
TileEntityMultiblockConverter master = masterOr(this, this);
TileEntityMechMB master = masterOr(this, this);
int id = getPart(getOffsetDir().getZ(), master);
if (id>=0&&master.mechanical[id] instanceof IRedstoneOutput) {
if (id >= 0 && master.mechanical[id] instanceof IRedstoneOutput) {
MechMBPart part = master.mechanical[id];
return ((IRedstoneOutput)part).canConnectRedstone(state,
return ((IRedstoneOutput) part).canConnectRedstone(state,
part.world.realToTransformed(side));
}
return false;
@ -565,27 +574,27 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
@Override
public AxisAlignedBB getBoundingBoxNoRot() {
Vec3i offset = getOffsetDir();
TileEntityMultiblockConverter master = masterOr(this, this);
TileEntityMechMB master = masterOr(this, this);
int comp = getPart(offset.getZ(), master);
if (comp<0) {
if (offset.getZ()==0) {
return new AxisAlignedBB(0, 0, .25, 1, 1, 1+offset.getY()*.25);
if (comp < 0) {
if (offset.getZ() == 0) {
return new AxisAlignedBB(0, 0, .25, 1, 1, 1 + offset.getY() * .25);
} else {
return new AxisAlignedBB(0, 0, -offset.getY()*.25, 1, 1, .75);
return new AxisAlignedBB(0, 0, -offset.getY() * .25, 1, 1, .75);
}
}
MechMBPart part = master.mechanical[comp];
BlockPos offsetPart = new BlockPos(offset.getX(), offset.getY(), offset.getZ()-master.offsets[comp]);
BlockPos offsetPart = new BlockPos(offset.getX(), offset.getY(), offset.getZ() - master.offsets[comp]);
return part.getBoundingBox(offsetPart);
}
private AxisAlignedBB aabb = null;
@Override
public AxisAlignedBB getBoundingBox() {
if (aabb==null)
{
if (aabb == null) {
aabb = IBlockBoundsDirectional.super.getBoundingBox();
}
return aabb;
}
}
}

View file

@ -31,7 +31,7 @@ import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanelCreator;
import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn;
import malte0811.industrialWires.blocks.converter.TileEntityMultiblockConverter;
import malte0811.industrialWires.blocks.converter.TileEntityMechMB;
import malte0811.industrialWires.blocks.hv.TileEntityJacobsLadder;
import malte0811.industrialWires.blocks.hv.TileEntityMarx;
import malte0811.industrialWires.client.gui.GuiPanelComponent;
@ -42,6 +42,7 @@ import malte0811.industrialWires.client.manual.TextSplitter;
import malte0811.industrialWires.client.panelmodel.PanelModelLoader;
import malte0811.industrialWires.client.render.*;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.converter.MechEnergy;
import malte0811.industrialWires.crafting.IC2TRHelper;
import malte0811.industrialWires.entities.EntityBrokenPart;
import malte0811.industrialWires.hv.MarxOreHandler;
@ -53,6 +54,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.MovingSound;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.audio.SoundHandler;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.resources.IReloadableResourceManager;
@ -65,6 +67,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.client.ClientCommandHandler;
@ -75,10 +78,7 @@ import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.WeakHashMap;
import java.util.*;
@SideOnly(Side.CLIENT)
public class ClientProxy extends CommonProxy {
@ -128,7 +128,7 @@ public class ClientProxy extends CommonProxy {
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityJacobsLadder.class, new TileRenderJacobsLadder());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMarx.class, new TileRenderMarx());
TileRenderMBConverter tesr = new TileRenderMBConverter();
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMultiblockConverter.class, tesr);
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMechMB.class, tesr);
((IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager()).registerReloadListener(tesr);
RenderingRegistry.registerEntityRenderingHandler(EntityBrokenPart.class, EntityRenderBrokenPart::new);
@ -326,19 +326,19 @@ public class ClientProxy extends CommonProxy {
return Minecraft.getMinecraft().world;
}
private WeakHashMap<BlockPos, ISound> playingSounds = new WeakHashMap<>();
private Map<BlockPos, List<ISound>> playingSounds = new HashMap<>();
private static ResourceLocation jacobsStart = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_start");//~470 ms ~=9 ticks
private static ResourceLocation jacobsMiddle = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_middle");
private static ResourceLocation jacobsEnd = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_end");//~210 ms ~= 4 ticks
private static ResourceLocation marxBang = new ResourceLocation(IndustrialWires.MODID, "marx_bang");
private static ResourceLocation marxPop = new ResourceLocation(IndustrialWires.MODID, "marx_pop");
private static ResourceLocation mmbBang = new ResourceLocation(IndustrialWires.MODID, "mech_mb_breaking");
private static ResourceLocation turnFast = new ResourceLocation(IndustrialWires.MODID, "mech_mb_fast");
private static ResourceLocation turnSlow = new ResourceLocation(IndustrialWires.MODID, "mech_mb_slow");
@Override
public void playJacobsLadderSound(TileEntityJacobsLadder te, int phase, Vec3d soundPos) {
if (playingSounds.containsKey(te.getPos())) {
Minecraft.getMinecraft().getSoundHandler().stopSound(playingSounds.get(te.getPos()));
playingSounds.remove(te.getPos());
}
stopAllSounds(te.getPos());
ResourceLocation event;
switch (phase) {
case 0:
@ -355,7 +355,37 @@ public class ClientProxy extends CommonProxy {
}
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);
playingSounds.put(te.getPos(), sound);
addSound(te.getPos(), sound);
}
@Override
public void playMechMBBang(TileEntityMechMB te, float volume) {
PositionedSoundRecord sound = new PositionedSoundRecord(mmbBang, SoundCategory.BLOCKS, volume, 1,
false, 0, ISound.AttenuationType.LINEAR, te.getPos().getX(), te.getPos().getY(),
te.getPos().getZ());
ClientUtils.mc().getSoundHandler().playSound(sound);
//This won't be added to the list since it's short and will play while the TE is being destroyed
}
@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);
}
}
@Override
@ -365,9 +395,32 @@ public class ClientProxy extends CommonProxy {
energy = -energy;
soundLoc = marxPop;
}
PositionedSoundRecord sound = new PositionedSoundRecord(soundLoc, SoundCategory.BLOCKS, 5*energy, 1, false, 0, ISound.AttenuationType.LINEAR, (float) pos.x, (float) pos.y, (float) pos.z);
PositionedSoundRecord sound = new PositionedSoundRecord(soundLoc, SoundCategory.BLOCKS, 5*energy, 1,
false, 0, ISound.AttenuationType.LINEAR, (float) pos.x, (float) pos.y, (float) pos.z);
ClientUtils.mc().getSoundHandler().playSound(sound);
playingSounds.put(te.getPos(), sound);
addSound(te.getPos(), sound);
}
private void addSound(BlockPos pos, ISound sound) {
List<ISound> allForPos = playingSounds.get(pos);
if (allForPos==null) {
allForPos = new ArrayList<>();
}
allForPos.add(sound);
if (allForPos.size()==1) {
playingSounds.put(pos, allForPos);
}
}
@Override
public void stopAllSounds(BlockPos pos) {
if (playingSounds.containsKey(pos)) {
SoundHandler manager = Minecraft.getMinecraft().getSoundHandler();
for (ISound sound:playingSounds.get(pos)) {
manager.stopSound(sound);
}
playingSounds.remove(pos);
}
}
@Override

View file

@ -18,7 +18,7 @@ package malte0811.industrialWires.client.render;
import blusunrize.immersiveengineering.api.IEApi;
import blusunrize.immersiveengineering.client.ClientUtils;
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import malte0811.industrialWires.blocks.converter.TileEntityMultiblockConverter;
import malte0811.industrialWires.blocks.converter.TileEntityMechMB;
import malte0811.industrialWires.client.ClientUtilsIW;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.converter.MechMBPart;
@ -42,17 +42,17 @@ import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import java.util.*;
import static malte0811.industrialWires.blocks.converter.TileEntityMultiblockConverter.TICK_ANGLE_PER_SPEED;
import static malte0811.industrialWires.blocks.converter.TileEntityMechMB.TICK_ANGLE_PER_SPEED;
import static malte0811.industrialWires.converter.MechMBPart.SHAFT_KEY;
public class TileRenderMBConverter extends TileEntitySpecialRenderer<TileEntityMultiblockConverter> implements IResourceManagerReloadListener {
public class TileRenderMBConverter extends TileEntitySpecialRenderer<TileEntityMechMB> implements IResourceManagerReloadListener {
public static final Map<ResourceLocation, IBakedModel> BASE_MODELS = new HashMap<>();
public static final Set<TileEntityMultiblockConverter> TES_WITH_MODELS = Collections.newSetFromMap(new WeakHashMap<>());
public static final Set<TileEntityMechMB> TES_WITH_MODELS = Collections.newSetFromMap(new WeakHashMap<>());
static {
IEApi.renderCacheClearers.add(TileRenderMBConverter::clearCache);
}
@Override
public void render(TileEntityMultiblockConverter te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
public void render(TileEntityMechMB te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
if (te.mechanical != null) {
if (te.rotatingModel == null) {
generateModel(te);
@ -83,12 +83,12 @@ public class TileRenderMBConverter extends TileEntitySpecialRenderer<TileEntityM
}
private static void clearCache() {
for (TileEntityMultiblockConverter te : TES_WITH_MODELS)
for (TileEntityMechMB te : TES_WITH_MODELS)
te.rotatingModel = null;
TES_WITH_MODELS.clear();
}
private void generateModel(TileEntityMultiblockConverter te) {
private void generateModel(TileEntityMechMB te) {
te.rotatingModel = new ArrayList<>();
int offset = 1;
for (MechMBPart part : te.mechanical) {

View file

@ -21,7 +21,7 @@ import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
import malte0811.industrialWires.blocks.converter.TileEntityMultiblockConverter;
import malte0811.industrialWires.blocks.converter.TileEntityMechMB;
import malte0811.industrialWires.client.render.TileRenderMBConverter;
import malte0811.industrialWires.util.LocalSidedWorld;
import malte0811.industrialWires.util.MiscUtils;
@ -184,7 +184,7 @@ public abstract class MechMBPart {
}
public void form(LocalSidedWorld w, Consumer<TileEntityMultiblockConverter> initializer) {
public void form(LocalSidedWorld w, Consumer<TileEntityMechMB> initializer) {
world = w;
BlockPos.PooledMutableBlockPos pos = BlockPos.PooledMutableBlockPos.retain();
short pattern = getFormPattern();
@ -195,8 +195,8 @@ public abstract class MechMBPart {
pos.setPos(x, y, 0);
w.setBlockState(pos, IndustrialWires.mechanicalMB.getStateFromMeta((i==4?getType():NO_MODEL).ordinal()));
TileEntity te = w.getTileEntity(pos);
if (te instanceof TileEntityMultiblockConverter) {
initializer.accept((TileEntityMultiblockConverter) te);
if (te instanceof TileEntityMechMB) {
initializer.accept((TileEntityMechMB) te);
}
}
i++;

View file

@ -19,7 +19,7 @@ import blusunrize.immersiveengineering.api.MultiblockHandler;
import blusunrize.immersiveengineering.api.crafting.IngredientStack;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
import malte0811.industrialWires.blocks.converter.TileEntityMultiblockConverter;
import malte0811.industrialWires.blocks.converter.TileEntityMechMB;
import malte0811.industrialWires.util.LocalSidedWorld;
import malte0811.industrialWires.util.MiscUtils;
import net.minecraft.block.state.IBlockState;
@ -59,18 +59,18 @@ public class MultiblockConverter implements MultiblockHandler.IMultiblock {
}
private void formEnd(LocalSidedWorld w, BlockPos.PooledMutableBlockPos p, MechanicalMBBlockType type,
BiConsumer<TileEntityMultiblockConverter, Boolean> init) {
BiConsumer<TileEntityMechMB, Boolean> init) {
p.setPos(0, 0, 0);
w.setBlockState(p, IndustrialWires.mechanicalMB.getStateFromMeta(type.ordinal()));
TileEntity te = w.getTileEntity(p);
if (te instanceof TileEntityMultiblockConverter) {
init.accept((TileEntityMultiblockConverter) te, true);
if (te instanceof TileEntityMechMB) {
init.accept((TileEntityMechMB) te, true);
}
p.setPos(0, -1, 0);
w.setBlockState(p, IndustrialWires.mechanicalMB.getStateFromMeta(NO_MODEL.ordinal()));
te = w.getTileEntity(p);
if (te instanceof TileEntityMultiblockConverter) {
init.accept((TileEntityMultiblockConverter) te, false);
if (te instanceof TileEntityMechMB) {
init.accept((TileEntityMechMB) te, false);
}
}
@ -129,7 +129,7 @@ public class MultiblockConverter implements MultiblockHandler.IMultiblock {
te.formed = true;
});
lastLength = 1;
Consumer<TileEntityMultiblockConverter> init = (te) -> {
Consumer<TileEntityMechMB> init = (te) -> {
te.offset = te.getPos().subtract(pos);
te.facing = side;
te.formed = true;

View file

@ -40,5 +40,41 @@
"sounds": [
"industrialwires:marx_pop"
]
},
"mech_mb_breaking": {
"category": "block",
"subtitle": "industrialwires.subtitle.mech_mb_breaking",
"sounds": [
"industrialwires:mech_mb/breaking"
]
},
"mech_mb_slow": {
"category": "block",
"subtitle": "industrialwires.subtitle.mech_mb_turning",
"sounds": [
"industrialwires:mech_mb/turn_slow_000",
"industrialwires:mech_mb/turn_slow_001",
"industrialwires:mech_mb/turn_slow_002",
"industrialwires:mech_mb/turn_slow_003",
"industrialwires:mech_mb/turn_slow_004",
"industrialwires:mech_mb/turn_slow_005",
"industrialwires:mech_mb/turn_slow_006",
"industrialwires:mech_mb/turn_slow_007",
"industrialwires:mech_mb/turn_slow_008"
]
},
"mech_mb_fast": {
"category": "block",
"subtitle": "industrialwires.subtitle.mech_mb_turning",
"sounds": [
"industrialwires:mech_mb/turn_fast_000",
"industrialwires:mech_mb/turn_fast_001",
"industrialwires:mech_mb/turn_fast_002",
"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"
]
}
}