From ec6cd544d23a6702bcb47ff856d2c2dcc91ad781 Mon Sep 17 00:00:00 2001 From: BallOfEnergy <66693744+BallOfEnergy1@users.noreply.github.com> Date: Sat, 4 Jan 2025 01:04:57 -0600 Subject: [PATCH] An absolute ton of cleanup. --- .../com/hbm/commands/CommandPacketInfo.java | 2 +- .../missile/EntityMissileAntiBallistic.java | 53 +++-- .../entity/missile/EntityMissileCustom.java | 25 ++- .../projectile/EntityArtilleryRocket.java | 65 +++--- .../entity/projectile/EntityWaterSplash.java | 10 +- .../com/hbm/handler/EntityEffectHandler.java | 7 +- .../ChunkRadiationHandlerSimple.java | 103 +++++---- .../handler/threading/PacketThreading.java | 29 ++- src/main/java/com/hbm/main/ClientProxy.java | 132 +++++------ src/main/java/com/hbm/main/ServerProxy.java | 2 - .../java/com/hbm/packet/PacketDispatcher.java | 14 +- .../packet/toclient/AuxElectricityPacket.java | 67 ------ .../hbm/packet/toclient/AuxGaugePacket.java | 96 -------- .../packet/toclient/AuxParticlePacket.java | 60 ----- .../hbm/packet/toclient/ExtPropPacket.java | 35 ++- .../packet/toclient/LoopedSoundPacket.java | 122 ----------- .../com/hbm/sound/SoundLoopAssembler.java | 38 ---- .../com/hbm/sound/SoundLoopBroadcaster.java | 52 ----- .../com/hbm/sound/SoundLoopCentrifuge.java | 54 ----- .../java/com/hbm/sound/SoundLoopTurbofan.java | 39 ---- .../hbm/tileentity/TileEntityMachineBase.java | 8 - .../bomb/TileEntityCompactLauncher.java | 10 +- .../tileentity/bomb/TileEntityLaunchPad.java | 44 ++-- .../bomb/TileEntityLaunchPadLarge.java | 78 ++++--- .../bomb/TileEntityLaunchPadRusted.java | 57 +++-- .../bomb/TileEntityLaunchTable.java | 10 +- .../machine/TileEntityBlastDoor.java | 108 ++++----- .../machine/TileEntityBroadcaster.java | 74 +++++-- .../machine/TileEntityMachineArcFurnace.java | 127 ++++++----- .../machine/TileEntityMachineGasCent.java | 206 ++++++++++-------- .../machine/TileEntityMachineRTG.java | 62 +++--- .../machine/TileEntityMachineShredder.java | 150 +++++++------ 32 files changed, 789 insertions(+), 1150 deletions(-) delete mode 100644 src/main/java/com/hbm/packet/toclient/AuxElectricityPacket.java delete mode 100644 src/main/java/com/hbm/packet/toclient/AuxGaugePacket.java delete mode 100644 src/main/java/com/hbm/packet/toclient/AuxParticlePacket.java delete mode 100644 src/main/java/com/hbm/packet/toclient/LoopedSoundPacket.java delete mode 100644 src/main/java/com/hbm/sound/SoundLoopAssembler.java delete mode 100644 src/main/java/com/hbm/sound/SoundLoopBroadcaster.java delete mode 100644 src/main/java/com/hbm/sound/SoundLoopCentrifuge.java delete mode 100644 src/main/java/com/hbm/sound/SoundLoopTurbofan.java diff --git a/src/main/java/com/hbm/commands/CommandPacketInfo.java b/src/main/java/com/hbm/commands/CommandPacketInfo.java index 4432e595f..1affa486c 100644 --- a/src/main/java/com/hbm/commands/CommandPacketInfo.java +++ b/src/main/java/com/hbm/commands/CommandPacketInfo.java @@ -80,7 +80,7 @@ public class CommandPacketInfo extends CommandBase { if (totalCnt != 0) sender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "% Remaining to process: " + BobMathUtil.roundDecimal(((double) PacketThreading.threadPool.getQueue().size() / totalCnt) * 100, 2) + "%")); - sender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "Time spent waiting on thread(s) last tick: " + BobMathUtil.roundDecimal(TimeUnit.NANOSECONDS.convert(PacketThreading.nanoTimeWaited, TimeUnit.MILLISECONDS), 4) + "ms")); + sender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "Time spent waiting on thread(s) last tick: " + BobMathUtil.roundDecimal(TimeUnit.MILLISECONDS.convert(PacketThreading.nanoTimeWaited, TimeUnit.NANOSECONDS), 4) + "ms")); return; } } diff --git a/src/main/java/com/hbm/entity/missile/EntityMissileAntiBallistic.java b/src/main/java/com/hbm/entity/missile/EntityMissileAntiBallistic.java index 3dbb048d8..296844b84 100644 --- a/src/main/java/com/hbm/entity/missile/EntityMissileAntiBallistic.java +++ b/src/main/java/com/hbm/entity/missile/EntityMissileAntiBallistic.java @@ -30,7 +30,7 @@ public class EntityMissileAntiBallistic extends EntityThrowableInterp implements public Entity tracking; public double velocity; protected int activationTimer; - + public static double baseSpeed = 1.5D; public EntityMissileAntiBallistic(World world) { @@ -60,21 +60,21 @@ public class EntityMissileAntiBallistic extends EntityThrowableInterp implements super.onUpdate(); if(!worldObj.isRemote) { - + if(velocity < 6) velocity += 0.1; - + if(activationTimer < 40) { activationTimer++; motionY = baseSpeed; } else { Entity prevTracking = this.tracking; - + if(this.tracking == null || this.tracking.isDead) this.targetMissile(); - + if(prevTracking == null && this.tracking != null) { ExplosionLarge.spawnShock(worldObj, posX, posY, posZ, 24, 3F); } - + if(this.tracking != null) { this.aimAtTarget(); } else { @@ -83,15 +83,20 @@ public class EntityMissileAntiBallistic extends EntityThrowableInterp implements } loadNeighboringChunks((int) Math.floor(posX / 16), (int) Math.floor(posZ / 16)); - + if(this.posY > 2000 && (this.tracking == null || this.tracking.isDead)) this.setDead(); - + } else { - + Vec3 vec = Vec3.createVectorHelper(motionX, motionY, motionZ).normalize(); - MainRegistry.proxy.particleControl(posX - vec.xCoord, posY - vec.yCoord, posZ - vec.zCoord, 2); + NBTTagCompound data = new NBTTagCompound(); + data.setString("type", "ABMContrail"); + data.setDouble("posX", posX - vec.xCoord); + data.setDouble("posY", posY - vec.yCoord); + data.setDouble("posZ", posZ - vec.zCoord); + MainRegistry.proxy.effectNT(data); } - + float f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI); for(this.rotationPitch = (float) (Math.atan2(this.motionY, f2) * 180.0D / Math.PI) - 90; this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F); @@ -102,33 +107,33 @@ public class EntityMissileAntiBallistic extends EntityThrowableInterp implements /** Detects and caches nearby EntityMissileBaseNT */ protected void targetMissile() { - + Entity closest = null; double dist = 1_000; - + for(Entity e : TileEntityMachineRadarNT.matchingEntities) { if(e.dimension != this.dimension) continue; if(!(e instanceof EntityMissileBaseNT)) continue; //can only lock onto missiles if(e instanceof EntityMissileStealth) continue; //cannot lack onto missiles with stealth coating - + Vec3 vec = Vec3.createVectorHelper(e.posX - posX, e.posY - posY, e.posZ - posZ); - + if(vec.lengthVector() < dist) { closest = e; } } - + this.tracking = closest; } - + /** Predictive targeting system */ protected void aimAtTarget() { - + Vec3 delta = Vec3.createVectorHelper(tracking.posX - posX, tracking.posY - posY, tracking.posZ - posZ); double intercept = delta.lengthVector() / (this.baseSpeed * this.velocity); Vec3 predicted = Vec3.createVectorHelper(tracking.posX + (tracking.posX - tracking.lastTickPosX) * intercept, tracking.posY + (tracking.posY - tracking.lastTickPosY) * intercept, tracking.posZ + (tracking.posZ - tracking.lastTickPosZ) * intercept); Vec3 motion = Vec3.createVectorHelper(predicted.xCoord - posX, predicted.yCoord - posY, predicted.zCoord - posZ).normalize(); - + if(delta.lengthVector() < 10 && activationTimer >= 40) { this.setDead(); ExplosionLarge.explode(worldObj, posX, posY, posZ, 15F, true, false, false); @@ -168,13 +173,13 @@ public class EntityMissileAntiBallistic extends EntityThrowableInterp implements super.readEntityFromNBT(nbt); this.velocity = nbt.getDouble("veloc"); } - + @Override public void writeEntityToNBT(NBTTagCompound nbt) { super.writeEntityToNBT(nbt); nbt.setDouble("veloc", this.velocity); } - + @Override public void init(Ticket ticket) { if(!worldObj.isRemote) { @@ -197,7 +202,7 @@ public class EntityMissileAntiBallistic extends EntityThrowableInterp implements public void loadNeighboringChunks(int newChunkX, int newChunkZ) { if(!worldObj.isRemote && loaderTicket != null) { - + clearChunkLoader(); loadedChunks.clear(); @@ -208,13 +213,13 @@ public class EntityMissileAntiBallistic extends EntityThrowableInterp implements } } } - + @Override public void setDead() { super.setDead(); this.clearChunkLoader(); } - + public void clearChunkLoader() { if(!worldObj.isRemote && loaderTicket != null) { for(ChunkCoordIntPair chunk : loadedChunks) { diff --git a/src/main/java/com/hbm/entity/missile/EntityMissileCustom.java b/src/main/java/com/hbm/entity/missile/EntityMissileCustom.java index 3b171440f..0b6a51cf8 100644 --- a/src/main/java/com/hbm/entity/missile/EntityMissileCustom.java +++ b/src/main/java/com/hbm/entity/missile/EntityMissileCustom.java @@ -78,7 +78,7 @@ public class EntityMissileCustom extends EntityMissileBaseNT implements IChunkLo ExplosionLarge.spawnShrapnelShower(worldObj, posX, posY, posZ, motionX, motionY, motionZ, 15, 0.075); } } - + @Override public void onUpdate() { @@ -87,11 +87,11 @@ public class EntityMissileCustom extends EntityMissileBaseNT implements IChunkLo if(type != null && type.updateCustom != null) { type.updateCustom.accept(this); } - + if(!worldObj.isRemote) { if(this.hasPropulsion()) this.fuel -= this.consumption; } - + super.onUpdate(); } @@ -131,7 +131,7 @@ public class EntityMissileCustom extends EntityMissileBaseNT implements IChunkLo nbt.setInteger("fins", this.dataWatcher.getWatchableObjectInt(11)); nbt.setInteger("thruster", this.dataWatcher.getWatchableObjectInt(12)); } - + @Override protected void spawnContrail() { @@ -148,7 +148,16 @@ public class EntityMissileCustom extends EntityMissileBaseNT implements IChunkLo case XENON: break; } - if(!smoke.isEmpty()) for(int i = 0; i < velocity; i++) MainRegistry.proxy.spawnParticle(posX - v.xCoord * i, posY - v.yCoord * i, posZ - v.zCoord * i, smoke, null); + if(!smoke.isEmpty()) { + for (int i = 0; i < velocity; i++) { + NBTTagCompound data = new NBTTagCompound(); + data.setDouble("posX", posX - v.xCoord * i); + data.setDouble("posY", posY - v.yCoord * i); + data.setDouble("posZ", posZ - v.zCoord * i); + data.setString("type", smoke); + MainRegistry.proxy.effectNT(data); + } + } } @Override @@ -158,7 +167,7 @@ public class EntityMissileCustom extends EntityMissileBaseNT implements IChunkLo WarheadType type = (WarheadType) part.attributes[0]; float strength = (Float) part.attributes[1]; - + if(type.impactCustom != null) { type.impactCustom.accept(this); return; @@ -244,7 +253,7 @@ public class EntityMissileCustom extends EntityMissileBaseNT implements IChunkLo if(top == PartSize.SIZE_15 && bottom == PartSize.SIZE_15) return "radar.target.custom15"; if(top == PartSize.SIZE_15 && bottom == PartSize.SIZE_20) return "radar.target.custom1520"; if(top == PartSize.SIZE_20 && bottom == PartSize.SIZE_20) return "radar.target.custom20"; - + return "radar.target.custom"; } @@ -260,7 +269,7 @@ public class EntityMissileCustom extends EntityMissileBaseNT implements IChunkLo if(top == PartSize.SIZE_15 && bottom == PartSize.SIZE_15) return IRadarDetectableNT.TIER15; if(top == PartSize.SIZE_15 && bottom == PartSize.SIZE_20) return IRadarDetectableNT.TIER15_20; if(top == PartSize.SIZE_20 && bottom == PartSize.SIZE_20) return IRadarDetectableNT.TIER20; - + return IRadarDetectableNT.TIER1; } diff --git a/src/main/java/com/hbm/entity/projectile/EntityArtilleryRocket.java b/src/main/java/com/hbm/entity/projectile/EntityArtilleryRocket.java index 1a04f5a2f..45cc42fb4 100644 --- a/src/main/java/com/hbm/entity/projectile/EntityArtilleryRocket.java +++ b/src/main/java/com/hbm/entity/projectile/EntityArtilleryRocket.java @@ -28,14 +28,14 @@ import net.minecraftforge.common.ForgeChunkManager.Type; public class EntityArtilleryRocket extends EntityThrowableInterp implements IChunkLoader, IRadarDetectable { private Ticket loaderTicket; - + //TODO: find satisfying solution for when an entity is unloaded and reloaded, possibly a custom entity lookup using persistent UUIDs public Entity targetEntity = null; public Vec3 lastTargetPos; - + public IRocketTargetingBehavior targeting; public IRocketSteeringBehavior steering; - + public EntityArtilleryRocket(World world) { super(world); this.ignoreFrustumCheck = true; @@ -49,18 +49,18 @@ public class EntityArtilleryRocket extends EntityThrowableInterp implements IChu init(ForgeChunkManager.requestTicket(MainRegistry.instance, worldObj, Type.ENTITY)); this.dataWatcher.addObject(10, new Integer(0)); } - + @Override @SideOnly(Side.CLIENT) public boolean isInRangeToRenderDist(double distance) { return true; } - + public EntityArtilleryRocket setType(int type) { this.dataWatcher.updateObject(10, type); return this; } - + public HIMARSRocket getType() { try { return ItemAmmoHIMARS.itemTypes[this.dataWatcher.getWatchableObjectInt(10)]; @@ -68,35 +68,35 @@ public class EntityArtilleryRocket extends EntityThrowableInterp implements IChu return ItemAmmoHIMARS.itemTypes[0]; } } - + public EntityArtilleryRocket setTarget(Entity target) { this.targetEntity = target; setTarget(target.posX, target.posY - target.yOffset + target.height / 2D, target.posZ); return this; } - + public EntityArtilleryRocket setTarget(double x, double y, double z) { this.lastTargetPos = Vec3.createVectorHelper(x, y, z); return this; } - + public Vec3 getLastTarget() { return this.lastTargetPos; } - + @Override public void onUpdate() { - + if(worldObj.isRemote) { this.lastTickPosX = this.posX; this.lastTickPosY = this.posY; this.lastTickPosZ = this.posZ; } - + super.onUpdate(); - + if(!worldObj.isRemote) { - + /*if(this.targetEntity == null) { Vec3 delta = Vec3.createVectorHelper(this.lastTargetPos.xCoord - this.posX, this.lastTargetPos.yCoord - this.posY, this.lastTargetPos.zCoord - this.posZ); if(delta.lengthVector() <= 15D) { @@ -104,26 +104,35 @@ public class EntityArtilleryRocket extends EntityThrowableInterp implements IChu this.steering = null; } }*/ - + if(this.targeting != null && this.targetEntity != null) this.targeting.recalculateTargetPosition(this, this.targetEntity); if(this.steering != null) this.steering.adjustCourse(this, 25D, 15D); - + loadNeighboringChunks((int)Math.floor(posX / 16D), (int)Math.floor(posZ / 16D)); this.getType().onUpdate(this); } else { - + Vec3 v = Vec3.createVectorHelper(lastTickPosX - posX, lastTickPosY - posY, lastTickPosZ - posZ); double velocity = v.lengthVector(); v = v.normalize(); - + int offset = 6; - if(velocity > 1) for(int i = offset; i < velocity + offset; i++) MainRegistry.proxy.spawnParticle(posX + v.xCoord * i, posY + v.yCoord * i, posZ + v.zCoord * i, "exKerosene", null); + if(velocity > 1) { + for (int i = offset; i < velocity + offset; i++) { + NBTTagCompound data = new NBTTagCompound(); + data.setDouble("posX", posX + v.xCoord * i); + data.setDouble("posY", posY + v.yCoord * i); + data.setDouble("posZ", posZ + v.zCoord * i); + data.setString("type", "exKerosene"); + MainRegistry.proxy.effectNT(data); + } + } } } @Override protected void onImpact(MovingObjectPosition mop) { - + if(!worldObj.isRemote) { this.getType().onImpact(this, mop); } @@ -145,7 +154,7 @@ public class EntityArtilleryRocket extends EntityThrowableInterp implements IChu public void loadNeighboringChunks(int newChunkX, int newChunkZ) { if(!worldObj.isRemote && loaderTicket != null) { - + clearChunkLoader(); loadedChunks.clear(); @@ -157,12 +166,12 @@ public class EntityArtilleryRocket extends EntityThrowableInterp implements IChu } } } - + public void killAndClear() { this.setDead(); this.clearChunkLoader(); } - + public void clearChunkLoader() { if(!worldObj.isRemote && loaderTicket != null) { for(ChunkCoordIntPair chunk : loadedChunks) { @@ -174,15 +183,15 @@ public class EntityArtilleryRocket extends EntityThrowableInterp implements IChu @Override public void writeEntityToNBT(NBTTagCompound nbt) { super.writeEntityToNBT(nbt); - + if(this.lastTargetPos == null) { this.lastTargetPos = Vec3.createVectorHelper(posX, posY, posZ); } - + nbt.setDouble("targetX", this.lastTargetPos.xCoord); nbt.setDouble("targetY", this.lastTargetPos.yCoord); nbt.setDouble("targetZ", this.lastTargetPos.zCoord); - + nbt.setInteger("type", this.dataWatcher.getWatchableObjectInt(10)); } @@ -191,7 +200,7 @@ public class EntityArtilleryRocket extends EntityThrowableInterp implements IChu super.readEntityFromNBT(nbt); this.lastTargetPos = Vec3.createVectorHelper(nbt.getDouble("targetX"), nbt.getDouble("targetY"), nbt.getDouble("targetZ")); - + this.dataWatcher.updateObject(10, nbt.getInteger("type")); } @@ -209,7 +218,7 @@ public class EntityArtilleryRocket extends EntityThrowableInterp implements IChu public RadarTargetType getTargetType() { return RadarTargetType.ARTILLERY; } - + @Override public int approachNum() { return 0; // diff --git a/src/main/java/com/hbm/entity/projectile/EntityWaterSplash.java b/src/main/java/com/hbm/entity/projectile/EntityWaterSplash.java index 4eed4570b..49ea4ae20 100644 --- a/src/main/java/com/hbm/entity/projectile/EntityWaterSplash.java +++ b/src/main/java/com/hbm/entity/projectile/EntityWaterSplash.java @@ -24,7 +24,7 @@ public class EntityWaterSplash extends EntityThrowable { public EntityWaterSplash(World p_i1775_1_, double p_i1775_2_, double p_i1775_4_, double p_i1775_6_) { super(p_i1775_1_, p_i1775_2_, p_i1775_4_, p_i1775_6_); } - + @Override public void onUpdate() { super.onUpdate(); @@ -35,8 +35,12 @@ public class EntityWaterSplash extends EntityThrowable { this.setDead(); } } else { - - MainRegistry.proxy.particleControl(posX, posY, posZ, 0); + NBTTagCompound data = new NBTTagCompound(); + data.setString("type", "waterSplash"); + data.setDouble("posX", posX); + data.setDouble("posY", posY); + data.setDouble("posZ", posZ); + MainRegistry.proxy.effectNT(data); } } diff --git a/src/main/java/com/hbm/handler/EntityEffectHandler.java b/src/main/java/com/hbm/handler/EntityEffectHandler.java index d7252bcd1..e32fb95ab 100644 --- a/src/main/java/com/hbm/handler/EntityEffectHandler.java +++ b/src/main/java/com/hbm/handler/EntityEffectHandler.java @@ -16,6 +16,7 @@ import com.hbm.handler.HbmKeybinds.EnumKeybind; import com.hbm.handler.pollution.PollutionHandler; import com.hbm.handler.pollution.PollutionHandler.PollutionType; import com.hbm.handler.radiation.ChunkRadiationManager; +import com.hbm.handler.threading.PacketThreading; import com.hbm.interfaces.IArmorModDash; import com.hbm.items.armor.ArmorFSB; import com.hbm.items.weapon.sedna.factory.ConfettiUtil; @@ -81,7 +82,6 @@ public class EntityEffectHandler { if(entity instanceof EntityPlayerMP) { HbmLivingProps props = HbmLivingProps.getData(entity); HbmPlayerProps pprps = HbmPlayerProps.getData((EntityPlayerMP) entity); - ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer(); if(pprps.shield < pprps.getEffectiveMaxShield() && entity.ticksExisted > pprps.lastDamage + 60) { int tsd = entity.ticksExisted - (pprps.lastDamage + 60); @@ -91,10 +91,7 @@ public class EntityEffectHandler { if(pprps.shield > pprps.getEffectiveMaxShield()) pprps.shield = pprps.getEffectiveMaxShield(); - props.serialize(buf); - pprps.serialize(buf); - PacketDispatcher.wrapper.sendTo(new ExtPropPacket(buf), (EntityPlayerMP) entity); - buf.release(); + PacketThreading.createSendToThreadedPacket(new ExtPropPacket(props, pprps), (EntityPlayerMP) entity); } if(!entity.worldObj.isRemote) { diff --git a/src/main/java/com/hbm/handler/radiation/ChunkRadiationHandlerSimple.java b/src/main/java/com/hbm/handler/radiation/ChunkRadiationHandlerSimple.java index e09d50209..b63c54b56 100644 --- a/src/main/java/com/hbm/handler/radiation/ChunkRadiationHandlerSimple.java +++ b/src/main/java/com/hbm/handler/radiation/ChunkRadiationHandlerSimple.java @@ -5,12 +5,14 @@ import java.util.Map.Entry; import com.hbm.blocks.ModBlocks; import com.hbm.config.RadiationConfig; +import com.hbm.main.MainRegistry; import com.hbm.packet.PacketDispatcher; -import com.hbm.packet.toclient.AuxParticlePacket; +import com.hbm.packet.toclient.AuxParticlePacketNT; import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.MathHelper; import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; @@ -25,31 +27,31 @@ import net.minecraftforge.event.world.WorldEvent; * @author hbm */ public class ChunkRadiationHandlerSimple extends ChunkRadiationHandler { - + private HashMap perWorld = new HashMap(); private static final float maxRad = 100_000F; @Override public float getRadiation(World world, int x, int y, int z) { SimpleRadiationPerWorld radWorld = perWorld.get(world); - + if(radWorld != null) { ChunkCoordIntPair coords = new ChunkCoordIntPair(x >> 4, z >> 4); Float rad = radWorld.radiation.get(coords); return rad == null ? 0F : MathHelper.clamp_float(rad, 0, maxRad); } - + return 0; } @Override public void setRadiation(World world, int x, int y, int z, float rad) { SimpleRadiationPerWorld radWorld = perWorld.get(world); - + if(radWorld != null) { - + if(world.blockExists(x, 0, z)) { - + ChunkCoordIntPair coords = new ChunkCoordIntPair(x >> 4, z >> 4); radWorld.radiation.put(coords, MathHelper.clamp_float(rad, 0, maxRad)); world.getChunkFromBlockCoords(x, z).isModified = true; @@ -69,28 +71,28 @@ public class ChunkRadiationHandlerSimple extends ChunkRadiationHandler { @Override public void updateSystem() { - + for(Entry entry : perWorld.entrySet()) { - + HashMap radiation = entry.getValue().radiation; HashMap buff = new HashMap(radiation); radiation.clear(); World world = entry.getKey(); - + for(Entry chunk : buff.entrySet()) { - + if(chunk.getValue() == 0) continue; - + ChunkCoordIntPair coord = chunk.getKey(); - + for(int i = -1; i <= 1; i++) { for(int j = -1; j<= 1; j++) { - + int type = Math.abs(i) + Math.abs(j); float percent = type == 0 ? 0.6F : type == 1 ? 0.075F : 0.025F; ChunkCoordIntPair newCoord = new ChunkCoordIntPair(coord.chunkXPos + i, coord.chunkZPos + j); - + if(buff.containsKey(newCoord)) { Float val = radiation.get(newCoord); float rad = val == null ? 0 : val; @@ -100,15 +102,20 @@ public class ChunkRadiationHandlerSimple extends ChunkRadiationHandler { } else { radiation.put(newCoord, chunk.getValue() * percent); } - + float rad = radiation.get(newCoord); if(rad > RadiationConfig.fogRad && world != null && world.rand.nextInt(RadiationConfig.fogCh) == 0 && world.getChunkProvider().chunkExists(coord.chunkXPos, coord.chunkZPos)) { - + int x = coord.chunkXPos * 16 + world.rand.nextInt(16); int z = coord.chunkZPos * 16 + world.rand.nextInt(16); int y = world.getHeightValue(x, z) + world.rand.nextInt(5); - - PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacket(x, y, z, 3), new TargetPoint(world.provider.dimensionId, x, y, z, 100)); + + NBTTagCompound data = new NBTTagCompound(); + data.setString("type", "radFog"); + data.setDouble("posX", x); + data.setDouble("posY", y); + data.setDouble("posZ", z); + MainRegistry.proxy.effectNT(data); } } } @@ -119,7 +126,7 @@ public class ChunkRadiationHandlerSimple extends ChunkRadiationHandler { @Override public void clearSystem(World world) { SimpleRadiationPerWorld radWorld = perWorld.get(world); - + if(radWorld != null) { radWorld.radiation.clear(); } @@ -136,15 +143,15 @@ public class ChunkRadiationHandlerSimple extends ChunkRadiationHandler { if(!event.world.isRemote) perWorld.remove(event.world); } - + private static final String NBT_KEY_CHUNK_RADIATION = "hfr_simple_radiation"; @Override public void receiveChunkLoad(ChunkDataEvent.Load event) { - + if(!event.world.isRemote) { SimpleRadiationPerWorld radWorld = perWorld.get(event.world); - + if(radWorld != null) { radWorld.radiation.put(event.getChunk().getChunkCoordIntPair(), event.getData().getFloat(NBT_KEY_CHUNK_RADIATION)); } @@ -153,10 +160,10 @@ public class ChunkRadiationHandlerSimple extends ChunkRadiationHandler { @Override public void receiveChunkSave(ChunkDataEvent.Save event) { - + if(!event.world.isRemote) { SimpleRadiationPerWorld radWorld = perWorld.get(event.world); - + if(radWorld != null) { Float val = radWorld.radiation.get(event.getChunk().getChunkCoordIntPair()); float rad = val == null ? 0F : val; @@ -167,74 +174,74 @@ public class ChunkRadiationHandlerSimple extends ChunkRadiationHandler { @Override public void receiveChunkUnload(ChunkEvent.Unload event) { - + if(!event.world.isRemote) { SimpleRadiationPerWorld radWorld = perWorld.get(event.world); - + if(radWorld != null) { radWorld.radiation.remove(event.getChunk()); } } } - + public static class SimpleRadiationPerWorld { - + public HashMap radiation = new HashMap(); } - + @Override public void handleWorldDestruction() { - + int count = 10; int threshold = 10; int chunks = 5; - + //for all worlds for(Entry per : perWorld.entrySet()) { - + World world = per.getKey(); SimpleRadiationPerWorld list = per.getValue(); - + Object[] entries = list.radiation.entrySet().toArray(); - + if(entries.length == 0) continue; - + //chose this many random chunks for(int c = 0; c < chunks; c++) { - + Entry randEnt = (Entry) entries[world.rand.nextInt(entries.length)]; - + ChunkCoordIntPair coords = randEnt.getKey(); WorldServer serv = (WorldServer) world; ChunkProviderServer provider = (ChunkProviderServer) serv.getChunkProvider(); - + //choose this many random locations within the chunk for(int i = 0; i < count; i++) { - + if(randEnt == null || randEnt.getValue() < threshold) continue; - + if(provider.chunkExists(coords.chunkXPos, coords.chunkZPos)) { - + for(int a = 0; a < 16; a++) { for(int b = 0; b < 16; b++) { - + if(world.rand.nextInt(3) != 0) continue; - + int x = coords.getCenterXPos() - 8 + a; int z = coords.getCenterZPosition() - 8 + b; int y = world.getHeightValue(x, z) - world.rand.nextInt(2); - + if(world.getBlock(x, y, z) == Blocks.grass) { world.setBlock(x, y, z, ModBlocks.waste_earth); - + } else if(world.getBlock(x, y, z) == Blocks.tallgrass) { world.setBlock(x, y, z, Blocks.air); - + } else if(world.getBlock(x, y, z).getMaterial() == Material.leaves && !(world.getBlock(x, y, z) == ModBlocks.waste_leaves)) { - + if(world.rand.nextInt(7) <= 5) { world.setBlock(x, y, z, ModBlocks.waste_leaves); } else { diff --git a/src/main/java/com/hbm/handler/threading/PacketThreading.java b/src/main/java/com/hbm/handler/threading/PacketThreading.java index 438481d52..18c5fda01 100644 --- a/src/main/java/com/hbm/handler/threading/PacketThreading.java +++ b/src/main/java/com/hbm/handler/threading/PacketThreading.java @@ -7,6 +7,7 @@ import com.hbm.packet.PacketDispatcher; import com.hbm.packet.PrecompiledPacket; import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import cpw.mods.fml.common.network.simpleimpl.IMessage; +import net.minecraft.entity.player.EntityPlayerMP; import java.util.ArrayList; import java.util.List; @@ -71,7 +72,6 @@ public class PacketThreading { // `message` can be precompiled or not. if(message instanceof PrecompiledPacket) ((PrecompiledPacket) message).getPreBuf(); // Gets the precompiled buffer, doing nothing if it already exists. - totalCnt++; Runnable task = () -> { @@ -88,6 +88,31 @@ public class PacketThreading { addTask(task); } + /** + * Adds a packet to the thread pool to be processed in the future. This is only compatible with the `sendTo` dispatch operation. + * + * @param message Message to process. + * @param player PlayerMP to send to. + */ + public static void createSendToThreadedPacket(IMessage message, EntityPlayerMP player) { + if(message instanceof PrecompiledPacket) + ((PrecompiledPacket) message).getPreBuf(); + totalCnt++; + + Runnable task = () -> { + try { + lock.lock(); + PacketDispatcher.wrapper.sendTo(message, player); + if (message instanceof PrecompiledPacket) + ((PrecompiledPacket) message).getPreBuf().release(); + } finally { + lock.unlock(); + } + }; + + addTask(task); + } + private static void addTask(Runnable task) { if(isTriggered()) task.run(); @@ -107,7 +132,7 @@ public class PacketThreading { for (Future future : futureList) { nanoTimeWaited = System.nanoTime() - startTime; future.get(50, TimeUnit.MILLISECONDS); // I HATE EVERYTHING - if(TimeUnit.NANOSECONDS.convert(nanoTimeWaited, TimeUnit.MILLISECONDS) > 50) throw new TimeoutException(); // >50ms total time? timeout? yes sir, ooh rah! + if(TimeUnit.MILLISECONDS.convert(nanoTimeWaited, TimeUnit.NANOSECONDS) > 50) throw new TimeoutException(); // >50ms total time? timeout? yes sir, ooh rah! } } } catch (ExecutionException ignored) { diff --git a/src/main/java/com/hbm/main/ClientProxy.java b/src/main/java/com/hbm/main/ClientProxy.java index 351b1376f..592722535 100644 --- a/src/main/java/com/hbm/main/ClientProxy.java +++ b/src/main/java/com/hbm/main/ClientProxy.java @@ -836,80 +836,6 @@ public class ClientProxy extends ServerProxy { MinecraftForgeClient.registerItemRenderer(ModItems.missile_custom, new ItemRenderMissile()); } - @Deprecated - @Override - public void particleControl(double x, double y, double z, int type) { - - - World world = Minecraft.getMinecraft().theWorld; - TextureManager man = Minecraft.getMinecraft().renderEngine; - - switch(type) { - case 0: - - for(int i = 0; i < 10; i++) { - EntityCloudFX smoke = new EntityCloudFX(world, x + world.rand.nextGaussian(), y + world.rand.nextGaussian(), z + world.rand.nextGaussian(), 0.0, 0.0, 0.0); - Minecraft.getMinecraft().effectRenderer.addEffect(smoke); - } - break; - - case 1: - - EntityCloudFX smoke = new EntityCloudFX(world, x, y, z, 0.0, 0.1, 0.0); - Minecraft.getMinecraft().effectRenderer.addEffect(smoke); - break; - - case 2: - - ParticleContrail contrail = new ParticleContrail(man, world, x, y, z); - Minecraft.getMinecraft().effectRenderer.addEffect(contrail); - break; - - case 3: - - ParticleRadiationFog fog = new ParticleRadiationFog(man, world, x, y, z); - Minecraft.getMinecraft().effectRenderer.addEffect(fog); - break; - } - } - - //version 2, now with strings! - @Deprecated - @Override - public void spawnParticle(double x, double y, double z, String type, float args[]) { - - World world = Minecraft.getMinecraft().theWorld; - TextureManager man = Minecraft.getMinecraft().renderEngine; - - if("launchsmoke".equals(type) && args.length == 3) { - ParticleSmokePlume contrail = new ParticleSmokePlume(man, world, x, y, z); - contrail.motionX = args[0]; - contrail.motionY = args[1]; - contrail.motionZ = args[2]; - Minecraft.getMinecraft().effectRenderer.addEffect(contrail); - } - if("exKerosene".equals(type)) { - ParticleContrail contrail = new ParticleContrail(man, world, x, y, z, 0F, 0F, 0F, 1F); - Minecraft.getMinecraft().effectRenderer.addEffect(contrail); - } - if("exSolid".equals(type)) { - ParticleContrail contrail = new ParticleContrail(man, world, x, y, z, 0.3F, 0.2F, 0.05F, 1F); - Minecraft.getMinecraft().effectRenderer.addEffect(contrail); - } - if("exHydrogen".equals(type)) { - ParticleContrail contrail = new ParticleContrail(man, world, x, y, z, 0.7F, 0.7F, 0.7F, 1F); - Minecraft.getMinecraft().effectRenderer.addEffect(contrail); - } - if("exBalefire".equals(type)) { - ParticleContrail contrail = new ParticleContrail(man, world, x, y, z, 0.2F, 0.7F, 0.2F, 1F); - Minecraft.getMinecraft().effectRenderer.addEffect(contrail); - } - if("radSmoke".equals(type)) { - ParticleRadiationFog contrail = new ParticleRadiationFog(man, world, x, y, z); - Minecraft.getMinecraft().effectRenderer.addEffect(contrail); - } - } - //mk3, only use this one @Override public void effectNT(NBTTagCompound data) { @@ -933,6 +859,64 @@ public class ClientProxy extends ServerProxy { return; } + // Old MK1 system ported to MK3: + + if("waterSplash".equals(type)) { + for (int i = 0; i < 10; i++) { + EntityCloudFX smoke = new EntityCloudFX(world, x + world.rand.nextGaussian(), y + world.rand.nextGaussian(), z + world.rand.nextGaussian(), 0.0, 0.0, 0.0); + Minecraft.getMinecraft().effectRenderer.addEffect(smoke); + } + } + + if("cloudFX2".equals(type)) { // i have genuinely no idea what used this + EntityCloudFX smoke = new EntityCloudFX(world, x, y, z, 0.0, 0.1, 0.0); + Minecraft.getMinecraft().effectRenderer.addEffect(smoke); + } + + if("ABMContrail".equals(type)) { + ParticleContrail contrail = new ParticleContrail(man, world, x, y, z); + Minecraft.getMinecraft().effectRenderer.addEffect(contrail); + } + + // End MK1 porting. + + // Old MK2 system ported to MK3: + + if("launchSmoke".equals(type)) { + ParticleSmokePlume contrail = new ParticleSmokePlume(man, world, x, y, z); + contrail.motionX = data.getDouble("moX"); + contrail.motionY = data.getDouble("moY"); + contrail.motionZ = data.getDouble("moZ"); + Minecraft.getMinecraft().effectRenderer.addEffect(contrail); + } + + if("exKerosene".equals(type)) { + ParticleContrail contrail = new ParticleContrail(man, world, x, y, z, 0F, 0F, 0F, 1F); + Minecraft.getMinecraft().effectRenderer.addEffect(contrail); + } + + if("exSolid".equals(type)) { + ParticleContrail contrail = new ParticleContrail(man, world, x, y, z, 0.3F, 0.2F, 0.05F, 1F); + Minecraft.getMinecraft().effectRenderer.addEffect(contrail); + } + + if("exHydrogen".equals(type)) { + ParticleContrail contrail = new ParticleContrail(man, world, x, y, z, 0.7F, 0.7F, 0.7F, 1F); + Minecraft.getMinecraft().effectRenderer.addEffect(contrail); + } + + if("exBalefire".equals(type)) { + ParticleContrail contrail = new ParticleContrail(man, world, x, y, z, 0.2F, 0.7F, 0.2F, 1F); + Minecraft.getMinecraft().effectRenderer.addEffect(contrail); + } + + if("radFog".equals(type)) { + ParticleRadiationFog contrail = new ParticleRadiationFog(man, world, x, y, z); + Minecraft.getMinecraft().effectRenderer.addEffect(contrail); + } + + // End MK2 porting. + if("missileContrail".equals(type)) { if(Vec3.createVectorHelper(player.posX - x, player.posY - y, player.posZ - z).lengthVector() > 350) return; diff --git a/src/main/java/com/hbm/main/ServerProxy.java b/src/main/java/com/hbm/main/ServerProxy.java index 829e46a7a..25f965437 100644 --- a/src/main/java/com/hbm/main/ServerProxy.java +++ b/src/main/java/com/hbm/main/ServerProxy.java @@ -37,8 +37,6 @@ public class ServerProxy { public void registerGunCfg() { } public void handleNHNEICompat() { } - public void particleControl(double x, double y, double z, int type) { } - public void spawnParticle(double x, double y, double z, String type, float[] args) { } public void effectNT(NBTTagCompound data) { } diff --git a/src/main/java/com/hbm/packet/PacketDispatcher.java b/src/main/java/com/hbm/packet/PacketDispatcher.java index 762d5482f..7509d411d 100644 --- a/src/main/java/com/hbm/packet/PacketDispatcher.java +++ b/src/main/java/com/hbm/packet/PacketDispatcher.java @@ -18,12 +18,8 @@ public class PacketDispatcher { public static void registerPackets() { int i = 0; - //Sound packet that keeps client and server separated - wrapper.registerMessage(LoopedSoundPacket.Handler.class, LoopedSoundPacket.class, i++, Side.CLIENT); //Signals server to consume items and create template wrapper.registerMessage(ItemFolderPacket.Handler.class, ItemFolderPacket.class, i++, Side.SERVER); - //Electricity gauge for GUI rendering - wrapper.registerMessage(AuxElectricityPacket.Handler.class, AuxElectricityPacket.class, i++, Side.CLIENT); //Siren packet for looped sounds wrapper.registerMessage(TESirenPacket.Handler.class, TESirenPacket.class, i++, Side.CLIENT); //Signals server to change ItemStacks @@ -44,8 +40,6 @@ public class PacketDispatcher { wrapper.registerMessage(TEFFPacket.Handler.class, TEFFPacket.class, i++, Side.CLIENT); //Sends button information for ItemGunBase wrapper.registerMessage(GunButtonPacket.Handler.class, GunButtonPacket.class, i++, Side.SERVER); - //Packet to send block break particles - wrapper.registerMessage(AuxParticlePacket.Handler.class, AuxParticlePacket.class, i++, Side.CLIENT); //Signals server to buy offer from bobmazon wrapper.registerMessage(ItemBobmazonPacket.Handler.class, ItemBobmazonPacket.class, i++, Side.SERVER); //Packet to send missile multipart information to TEs @@ -76,12 +70,8 @@ public class PacketDispatcher { wrapper.registerMessage(PermaSyncPacket.Handler.class, PermaSyncPacket.class, i++, Side.CLIENT); //Syncs biome information for single positions or entire chunks wrapper.registerMessage(BiomeSyncPacket.Handler.class, BiomeSyncPacket.class, i++, Side.CLIENT); - - //Tile sync - wrapper.registerMessage(AuxGaugePacket.Handler.class, AuxGaugePacket.class, i++, Side.CLIENT); //The horrid one - // fucking DIE - //wrapper.registerMessage(NBTPacket.Handler.class, NBTPacket.class, i++, Side.CLIENT); //The convenient but laggy one - wrapper.registerMessage(BufPacket.Handler.class, BufPacket.class, i++, Side.CLIENT); //The not-so-convenient but not laggy one + //The not-so-convenient but not laggy one + wrapper.registerMessage(BufPacket.Handler.class, BufPacket.class, i++, Side.CLIENT); } } diff --git a/src/main/java/com/hbm/packet/toclient/AuxElectricityPacket.java b/src/main/java/com/hbm/packet/toclient/AuxElectricityPacket.java deleted file mode 100644 index 571f925ce..000000000 --- a/src/main/java/com/hbm/packet/toclient/AuxElectricityPacket.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.hbm.packet.toclient; - -import api.hbm.energymk2.IEnergyHandlerMK2; -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import io.netty.buffer.ByteBuf; -import net.minecraft.client.Minecraft; -import net.minecraft.tileentity.TileEntity; - -@Deprecated //use the NBT packet instead -public class AuxElectricityPacket implements IMessage { - - int x; - int y; - int z; - long charge; - - public AuxElectricityPacket() - { - - } - - public AuxElectricityPacket(int x, int y, int z, long charge) - { - this.x = x; - this.y = y; - this.z = z; - this.charge = charge; - } - - @Override - public void fromBytes(ByteBuf buf) { - x = buf.readInt(); - y = buf.readInt(); - z = buf.readInt(); - charge = buf.readLong(); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(x); - buf.writeInt(y); - buf.writeInt(z); - buf.writeLong(charge); - } - - public static class Handler implements IMessageHandler { - - @Override - @SideOnly(Side.CLIENT) - public IMessage onMessage(AuxElectricityPacket m, MessageContext ctx) { - try { - TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(m.x, m.y, m.z); - - if (te instanceof IEnergyHandlerMK2) { - - IEnergyHandlerMK2 gen = (IEnergyHandlerMK2) te; - gen.setPower(m.charge); - } - } catch (Exception x) { } - return null; - } - } -} diff --git a/src/main/java/com/hbm/packet/toclient/AuxGaugePacket.java b/src/main/java/com/hbm/packet/toclient/AuxGaugePacket.java deleted file mode 100644 index 190a7f4b4..000000000 --- a/src/main/java/com/hbm/packet/toclient/AuxGaugePacket.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.hbm.packet.toclient; - -import com.hbm.interfaces.Spaghetti; -import com.hbm.items.weapon.ItemCustomMissilePart.PartSize; -import com.hbm.tileentity.TileEntityMachineBase; -import com.hbm.tileentity.bomb.TileEntityCompactLauncher; -import com.hbm.tileentity.bomb.TileEntityLaunchTable; -import com.hbm.tileentity.machine.TileEntityMachineArcFurnace; - -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import io.netty.buffer.ByteBuf; -import net.minecraft.client.Minecraft; -import net.minecraft.tileentity.TileEntity; - -@Spaghetti("Changing all machines to use TileEntityMachineBase will reduce the total chaos in this class") -@Deprecated //use the NBT packet instead -public class AuxGaugePacket implements IMessage { - - int x; - int y; - int z; - int value; - int id; - - public AuxGaugePacket() - { - - } - - public AuxGaugePacket(int x, int y, int z, int value, int id) - { - this.x = x; - this.y = y; - this.z = z; - this.value = value; - this.id = id; - } - - @Override - public void fromBytes(ByteBuf buf) { - x = buf.readInt(); - y = buf.readInt(); - z = buf.readInt(); - value = buf.readInt(); - id = buf.readInt(); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(x); - buf.writeInt(y); - buf.writeInt(z); - buf.writeInt(value); - buf.writeInt(id); - } - - public static class Handler implements IMessageHandler { - - @Override - @SideOnly(Side.CLIENT) - public IMessage onMessage(AuxGaugePacket m, MessageContext ctx) { - try { - TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(m.x, m.y, m.z); - if (te instanceof TileEntityMachineArcFurnace) { - TileEntityMachineArcFurnace furn = (TileEntityMachineArcFurnace)te; - - if(m.id == 0) - furn.dualCookTime = m.value; - } - if (te instanceof TileEntityCompactLauncher) { - TileEntityCompactLauncher launcher = (TileEntityCompactLauncher)te; - - launcher.solid = m.value; - } - if (te instanceof TileEntityLaunchTable) { - TileEntityLaunchTable launcher = (TileEntityLaunchTable)te; - - if(m.id == 0) - launcher.solid = m.value; - if(m.id == 1) - launcher.padSize = PartSize.values()[m.value]; - } - - if(te instanceof TileEntityMachineBase) { - ((TileEntityMachineBase)te).processGauge(m.value, m.id); - } - - } catch (Exception x) {} - return null; - } - } -} diff --git a/src/main/java/com/hbm/packet/toclient/AuxParticlePacket.java b/src/main/java/com/hbm/packet/toclient/AuxParticlePacket.java deleted file mode 100644 index 317e121c0..000000000 --- a/src/main/java/com/hbm/packet/toclient/AuxParticlePacket.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.hbm.packet.toclient; - -import com.hbm.main.MainRegistry; - -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; - -public class AuxParticlePacket implements IMessage { - - double x; - double y; - double z; - int type; - - public AuxParticlePacket() - { - - } - - public AuxParticlePacket(double x, double y, double z, int type) - { - this.x = x; - this.y = y; - this.z = z; - this.type = type; - } - - @Override - public void fromBytes(ByteBuf buf) { - x = buf.readDouble(); - y = buf.readDouble(); - z = buf.readDouble(); - type = buf.readInt(); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeDouble(x); - buf.writeDouble(y); - buf.writeDouble(z); - buf.writeInt(type); - } - - public static class Handler implements IMessageHandler { - - @Override - public IMessage onMessage(AuxParticlePacket m, MessageContext ctx) { - - try { - - MainRegistry.proxy.particleControl(m.x, m.y, m.z, m.type); - - } catch(Exception x) { } - - return null; - } - } -} diff --git a/src/main/java/com/hbm/packet/toclient/ExtPropPacket.java b/src/main/java/com/hbm/packet/toclient/ExtPropPacket.java index 70ab279ba..97ac8016a 100644 --- a/src/main/java/com/hbm/packet/toclient/ExtPropPacket.java +++ b/src/main/java/com/hbm/packet/toclient/ExtPropPacket.java @@ -3,44 +3,37 @@ package com.hbm.packet.toclient; import com.hbm.extprop.HbmLivingProps; import com.hbm.extprop.HbmPlayerProps; +import com.hbm.packet.PrecompiledPacket; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; import net.minecraft.client.Minecraft; -import net.minecraft.network.PacketBuffer; -public class ExtPropPacket implements IMessage { +public class ExtPropPacket extends PrecompiledPacket { - ByteBuf buffer; + HbmLivingProps props; + HbmPlayerProps pprps; + ByteBuf buf; public ExtPropPacket() { } - public ExtPropPacket(ByteBuf buf) { - - this.buffer = Unpooled.buffer(); - buffer.writeBytes(buf); + public ExtPropPacket(HbmLivingProps props, HbmPlayerProps pprps) { + this.props = props; + this.pprps = pprps; } @Override public void fromBytes(ByteBuf buf) { - - if (buffer == null) { - buffer = new PacketBuffer(Unpooled.buffer()); - } - buffer.writeBytes(buf); + this.buf = buf; } @Override public void toBytes(ByteBuf buf) { - - if (buffer == null) { - buffer = new PacketBuffer(Unpooled.buffer()); - } - buf.writeBytes(buffer); + props.serialize(buf); + pprps.serialize(buf); } public static class Handler implements IMessageHandler { @@ -55,10 +48,10 @@ public class ExtPropPacket implements IMessage { HbmLivingProps props = HbmLivingProps.getData(Minecraft.getMinecraft().thePlayer); HbmPlayerProps pprps = HbmPlayerProps.getData(Minecraft.getMinecraft().thePlayer); - props.deserialize(m.buffer); - pprps.deserialize(m.buffer); + props.deserialize(m.buf); + pprps.deserialize(m.buf); - m.buffer.release(); + m.buf.release(); return null; } diff --git a/src/main/java/com/hbm/packet/toclient/LoopedSoundPacket.java b/src/main/java/com/hbm/packet/toclient/LoopedSoundPacket.java deleted file mode 100644 index 5533245d1..000000000 --- a/src/main/java/com/hbm/packet/toclient/LoopedSoundPacket.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.hbm.packet.toclient; - -import com.hbm.interfaces.Spaghetti; -import com.hbm.sound.*; -import com.hbm.tileentity.machine.*; - -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import io.netty.buffer.ByteBuf; -import net.minecraft.client.Minecraft; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; - -@Spaghetti("this class should be destroyed") -public class LoopedSoundPacket implements IMessage { - - int x; - int y; - int z; - - public LoopedSoundPacket() - { - - } - - public LoopedSoundPacket(int x, int y, int z) - { - this.x = x; - this.y = y; - this.z = z; - } - - @Override - public void fromBytes(ByteBuf buf) { - x = buf.readInt(); - y = buf.readInt(); - z = buf.readInt(); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(x); - buf.writeInt(y); - buf.writeInt(z); - } - - public static class Handler implements IMessageHandler { - - @Override - //Tamaized, I love you! - @SideOnly(Side.CLIENT) - public IMessage onMessage(LoopedSoundPacket m, MessageContext ctx) { - TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(m.x, m.y, m.z); - - if (te != null && te instanceof TileEntityMachineAssembler) { - - boolean flag = true; - for(int i = 0; i < SoundLoopAssembler.list.size(); i++) { - if(SoundLoopAssembler.list.get(i).getTE() == te && !SoundLoopAssembler.list.get(i).isDonePlaying()) - flag = false; - } - - if(flag && te.getWorldObj().isRemote && ((TileEntityMachineAssembler)te).isProgressing) - Minecraft.getMinecraft().getSoundHandler().playSound(new SoundLoopAssembler(new ResourceLocation("hbm:block.assemblerOperate"), te)); - } - - if (te != null && te instanceof TileEntityMachineTurbofan) { - - boolean flag = true; - for(int i = 0; i < SoundLoopTurbofan.list.size(); i++) { - if(SoundLoopTurbofan.list.get(i).getTE() == te && !SoundLoopTurbofan.list.get(i).isDonePlaying()) - flag = false; - } - - if(flag && te.getWorldObj().isRemote && ((TileEntityMachineTurbofan)te).wasOn) - Minecraft.getMinecraft().getSoundHandler().playSound(new SoundLoopTurbofan(new ResourceLocation("hbm:block.turbofanOperate"), te)); - } - - if (te != null && te instanceof TileEntityBroadcaster) { - - boolean flag = true; - for(int i = 0; i < SoundLoopBroadcaster.list.size(); i++) { - if(SoundLoopBroadcaster.list.get(i).getTE() == te && !SoundLoopBroadcaster.list.get(i).isDonePlaying()) - flag = false; - } - - int j = te.xCoord + te.zCoord + te.yCoord; - - if(flag && te.getWorldObj().isRemote) - Minecraft.getMinecraft().getSoundHandler().playSound(new SoundLoopBroadcaster(new ResourceLocation("hbm:block.broadcast" + (Math.abs(j) % 3 + 1)), te)); - } - - if (te != null && te instanceof TileEntityMachineCentrifuge) { - - boolean flag = true; - for(int i = 0; i < SoundLoopCentrifuge.list.size(); i++) { - if(SoundLoopCentrifuge.list.get(i).getTE() == te && !SoundLoopCentrifuge.list.get(i).isDonePlaying()) - flag = false; - } - - if(flag && te.getWorldObj().isRemote && ((TileEntityMachineCentrifuge)te).isProgressing) - Minecraft.getMinecraft().getSoundHandler().playSound(new SoundLoopCentrifuge(new ResourceLocation("hbm:block.centrifugeOperate"), te)); - } - - if (te != null && te instanceof TileEntityMachineGasCent) { - - boolean flag = true; - for(int i = 0; i < SoundLoopCentrifuge.list.size(); i++) { - if(SoundLoopCentrifuge.list.get(i).getTE() == te && !SoundLoopCentrifuge.list.get(i).isDonePlaying()) - flag = false; - } - - if(flag && te.getWorldObj().isRemote && ((TileEntityMachineGasCent)te).isProgressing) - Minecraft.getMinecraft().getSoundHandler().playSound(new SoundLoopCentrifuge(new ResourceLocation("hbm:block.centrifugeOperate"), te)); - } - return null; - } - } -} diff --git a/src/main/java/com/hbm/sound/SoundLoopAssembler.java b/src/main/java/com/hbm/sound/SoundLoopAssembler.java deleted file mode 100644 index c69ea40c6..000000000 --- a/src/main/java/com/hbm/sound/SoundLoopAssembler.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.hbm.sound; - -import java.util.ArrayList; -import java.util.List; - -import com.hbm.tileentity.machine.TileEntityMachineAssembler; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; - -public class SoundLoopAssembler extends SoundLoopMachine { - - public static List list = new ArrayList(); - - public SoundLoopAssembler(ResourceLocation path, TileEntity te) { - super(path, te); - list.add(this); - } - - @Override - public void update() { - super.update(); - - if(te instanceof TileEntityMachineAssembler) { - TileEntityMachineAssembler drill = (TileEntityMachineAssembler)te; - - if(this.volume != 3) - volume = 3; - - if(!drill.isProgressing) - this.donePlaying = true; - } - } - - public TileEntity getTE() { - return te; - } - -} diff --git a/src/main/java/com/hbm/sound/SoundLoopBroadcaster.java b/src/main/java/com/hbm/sound/SoundLoopBroadcaster.java deleted file mode 100644 index 3b00039a5..000000000 --- a/src/main/java/com/hbm/sound/SoundLoopBroadcaster.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.hbm.sound; - -import java.util.ArrayList; -import java.util.List; - -import com.hbm.tileentity.machine.TileEntityBroadcaster; -import net.minecraft.client.Minecraft; -import net.minecraft.client.audio.ISound; -import net.minecraft.client.entity.EntityClientPlayerMP; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; - -public class SoundLoopBroadcaster extends SoundLoopMachine { - - public static List list = new ArrayList(); - public float intendedVolume = 25.0F; - - public SoundLoopBroadcaster(ResourceLocation path, TileEntity te) { - super(path, te); - list.add(this); - this.field_147666_i = ISound.AttenuationType.NONE; - } - - @Override - public void update() { - super.update(); - - EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer; - float f = 0; - - if(player != null) { - f = (float)Math.sqrt(Math.pow(xPosF - player.posX, 2) + Math.pow(yPosF - player.posY, 2) + Math.pow(zPosF - player.posZ, 2)); - volume = func(f, intendedVolume); - - if(!(player.worldObj.getTileEntity((int)xPosF, (int)yPosF, (int)zPosF) instanceof TileEntityBroadcaster)) { - this.donePlaying = true; - volume = 0; - } - } else { - volume = intendedVolume; - } - } - - public TileEntity getTE() { - return te; - } - - public float func(float f, float v) { - return (f / v) * -2 + 2; - } - -} diff --git a/src/main/java/com/hbm/sound/SoundLoopCentrifuge.java b/src/main/java/com/hbm/sound/SoundLoopCentrifuge.java deleted file mode 100644 index 2989ddf9c..000000000 --- a/src/main/java/com/hbm/sound/SoundLoopCentrifuge.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.hbm.sound; - -import java.util.ArrayList; -import java.util.List; - -import com.hbm.tileentity.machine.TileEntityMachineCentrifuge; -import com.hbm.tileentity.machine.TileEntityMachineGasCent; -import net.minecraft.client.Minecraft; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; - -public class SoundLoopCentrifuge extends SoundLoopMachine { - - public static List list = new ArrayList(); - - public SoundLoopCentrifuge(ResourceLocation path, TileEntity te) { - super(path, te); - list.add(this); - } - - @Override - public void update() { - super.update(); - - if(te instanceof TileEntityMachineCentrifuge) { - TileEntityMachineCentrifuge plant = (TileEntityMachineCentrifuge)te; - - if(this.volume != 1) - volume = 1; - - if(!plant.isProgressing) - this.donePlaying = true; - } - - if(te instanceof TileEntityMachineGasCent) { - TileEntityMachineGasCent plant = (TileEntityMachineGasCent)te; - - if(this.volume != 1) - volume = 1; - - if(!plant.isProgressing) - this.donePlaying = true; - } - - if(!Minecraft.getMinecraft().getSoundHandler().isSoundPlaying(this)) { - stop(); - } - } - - public TileEntity getTE() { - return te; - } - -} diff --git a/src/main/java/com/hbm/sound/SoundLoopTurbofan.java b/src/main/java/com/hbm/sound/SoundLoopTurbofan.java deleted file mode 100644 index 4b08d0471..000000000 --- a/src/main/java/com/hbm/sound/SoundLoopTurbofan.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.hbm.sound; - -import java.util.ArrayList; -import java.util.List; - -import com.hbm.tileentity.machine.TileEntityMachineTurbofan; - -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; - -public class SoundLoopTurbofan extends SoundLoopMachine { - - public static List list = new ArrayList(); - - public SoundLoopTurbofan(ResourceLocation path, TileEntity te) { - super(path, te); - list.add(this); - } - - @Override - public void update() { - super.update(); - - if(te instanceof TileEntityMachineTurbofan) { - TileEntityMachineTurbofan drill = (TileEntityMachineTurbofan)te; - - if(this.volume != 10) - volume = 10; - - if(!drill.wasOn) - this.donePlaying = true; - } - } - - public TileEntity getTE() { - return te; - } - -} diff --git a/src/main/java/com/hbm/tileentity/TileEntityMachineBase.java b/src/main/java/com/hbm/tileentity/TileEntityMachineBase.java index 7fecf29d5..e38bf2f63 100644 --- a/src/main/java/com/hbm/tileentity/TileEntityMachineBase.java +++ b/src/main/java/com/hbm/tileentity/TileEntityMachineBase.java @@ -1,10 +1,7 @@ package com.hbm.tileentity; -import com.hbm.packet.PacketDispatcher; -import com.hbm.packet.toclient.AuxGaugePacket; import com.hbm.util.fauxpointtwelve.DirPos; -import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; @@ -147,11 +144,6 @@ public abstract class TileEntityMachineBase extends TileEntityLoadedBase impleme @Override public abstract void updateEntity(); - @Deprecated public void updateGauge(int val, int id, int range) { - if(!worldObj.isRemote) PacketDispatcher.wrapper.sendToAllAround(new AuxGaugePacket(xCoord, yCoord, zCoord, val, id), new TargetPoint(this.worldObj.provider.dimensionId, xCoord, yCoord, zCoord, range)); - } - @Deprecated public void processGauge(int val, int id) { } - @Deprecated public void handleButtonPacket(int value, int meta) { } diff --git a/src/main/java/com/hbm/tileentity/bomb/TileEntityCompactLauncher.java b/src/main/java/com/hbm/tileentity/bomb/TileEntityCompactLauncher.java index d724c833e..12dd8bab2 100644 --- a/src/main/java/com/hbm/tileentity/bomb/TileEntityCompactLauncher.java +++ b/src/main/java/com/hbm/tileentity/bomb/TileEntityCompactLauncher.java @@ -220,7 +220,15 @@ public class TileEntityCompactLauncher extends TileEntityLoadedBase implements I float moX = (float) (dir ? 0 : worldObj.rand.nextGaussian() * 0.5F); float moZ = (float) (!dir ? 0 : worldObj.rand.nextGaussian() * 0.5F); - MainRegistry.proxy.spawnParticle(xCoord + 0.5, yCoord + 0.25, zCoord + 0.5, "launchsmoke", new float[] {moX, 0, moZ}); + NBTTagCompound data = new NBTTagCompound(); + data.setDouble("posX", xCoord + 0.5); + data.setDouble("posY", yCoord + 0.25); + data.setDouble("posZ", zCoord + 0.5); + data.setString("type", "launchSmoke"); + data.setDouble("moX", moX); + data.setDouble("moY", 0); + data.setDouble("moZ", moZ); + MainRegistry.proxy.effectNT(data); } break; diff --git a/src/main/java/com/hbm/tileentity/bomb/TileEntityLaunchPad.java b/src/main/java/com/hbm/tileentity/bomb/TileEntityLaunchPad.java index 0adf91ab8..11650a3ff 100644 --- a/src/main/java/com/hbm/tileentity/bomb/TileEntityLaunchPad.java +++ b/src/main/java/com/hbm/tileentity/bomb/TileEntityLaunchPad.java @@ -18,16 +18,16 @@ public class TileEntityLaunchPad extends TileEntityLaunchPadBase { @Override public boolean isReadyForLaunch() { return delay <= 0; } @Override public double getLaunchOffset() { return 1D; } - + public int delay = 0; @Override public void updateEntity() { - + if(!worldObj.isRemote) { - + if(this.delay > 0) delay--; - + if(!this.isMissileValid() || !this.hasFuel()) { this.delay = 100; } @@ -41,11 +41,11 @@ public class TileEntityLaunchPad extends TileEntityLaunchPadBase { this.state = this.STATE_READY; } } - + } else { - + List entities = worldObj.getEntitiesWithinAABB(EntityMissileBaseNT.class, AxisAlignedBB.getBoundingBox(xCoord - 0.5, yCoord, zCoord - 0.5, xCoord + 1.5, yCoord + 10, zCoord + 1.5)); - + if(!entities.isEmpty()) { for(int i = 0; i < 15; i++) { @@ -54,12 +54,20 @@ public class TileEntityLaunchPad extends TileEntityLaunchPadBase { if(worldObj.rand.nextBoolean()) dir = dir.getRotation(ForgeDirection.UP); float moX = (float) (worldObj.rand.nextGaussian() * 0.15F + 0.75) * dir.offsetX; float moZ = (float) (worldObj.rand.nextGaussian() * 0.15F + 0.75) * dir.offsetZ; - - MainRegistry.proxy.spawnParticle(xCoord + 0.5, yCoord + 0.25, zCoord + 0.5, "launchsmoke", new float[] {moX, 0, moZ}); + + NBTTagCompound data = new NBTTagCompound(); + data.setDouble("posX", xCoord + 0.5); + data.setDouble("posY", yCoord + 0.25); + data.setDouble("posZ", zCoord + 0.5); + data.setString("type", "launchSmoke"); + data.setDouble("moX", moX); + data.setDouble("moY", 0); + data.setDouble("moZ", moZ); + MainRegistry.proxy.effectNT(data); } } } - + super.updateEntity(); } @@ -68,7 +76,7 @@ public class TileEntityLaunchPad extends TileEntityLaunchPadBase { super.finalizeLaunch(missile); this.delay = 100; } - + @Override public DirPos[] getConPos() { return new DirPos[] { @@ -82,24 +90,24 @@ public class TileEntityLaunchPad extends TileEntityLaunchPadBase { new DirPos(xCoord + 1, yCoord, zCoord - 2, Library.NEG_Z) }; } - + @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); this.delay = nbt.getInteger("delay"); } - + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setInteger("delay", delay); } - + AxisAlignedBB bb = null; - + @Override public AxisAlignedBB getRenderBoundingBox() { - + if(bb == null) { bb = AxisAlignedBB.getBoundingBox( xCoord - 2, @@ -110,10 +118,10 @@ public class TileEntityLaunchPad extends TileEntityLaunchPadBase { zCoord + 3 ); } - + return bb; } - + @Override @SideOnly(Side.CLIENT) public double getMaxRenderDistanceSquared() { diff --git a/src/main/java/com/hbm/tileentity/bomb/TileEntityLaunchPadLarge.java b/src/main/java/com/hbm/tileentity/bomb/TileEntityLaunchPadLarge.java index 55a9dac77..ef3868d79 100644 --- a/src/main/java/com/hbm/tileentity/bomb/TileEntityLaunchPadLarge.java +++ b/src/main/java/com/hbm/tileentity/bomb/TileEntityLaunchPadLarge.java @@ -37,10 +37,10 @@ public class TileEntityLaunchPadLarge extends TileEntityLaunchPadBase { private int sync; /** Delay between erector movements */ public int delay = 20; - + private AudioWrapper audioLift; private AudioWrapper audioErector; - + protected boolean liftMoving = false; protected boolean erectorMoving = false; @@ -49,26 +49,26 @@ public class TileEntityLaunchPadLarge extends TileEntityLaunchPadBase { @Override public void updateEntity() { - + if(!worldObj.isRemote) { this.prevLift = this.lift; this.prevErector = this.erector; - + float erectorSpeed = 1.5F; float liftSpeed = 0.025F; - + if(this.isMissileValid()) { if(slots[0].getItem() instanceof ItemMissile) { ItemMissile missile = (ItemMissile) slots[0].getItem(); this.formFactor = missile.formFactor.ordinal(); - + if(missile.formFactor == MissileFormFactor.ATLAS || missile.formFactor == MissileFormFactor.HUGE) { erectorSpeed /= 2F; liftSpeed /= 2F; } } - + if(this.erector == 90F && this.lift == 1F) { this.readyToLoad = true; } @@ -77,16 +77,16 @@ public class TileEntityLaunchPadLarge extends TileEntityLaunchPadBase { erected = false; delay = 20; } - + if(this.power >= 75_000) { if(delay > 0) { delay--; - + if(delay < 10 && scheduleErect) { this.erected = true; this.scheduleErect = false; } - + // if there is no missile or the missile isn't ready (i.e. the erector hasn't returned to zero position yet), retract if(slots[0] == null || !readyToLoad) { //fold back erector @@ -103,13 +103,13 @@ public class TileEntityLaunchPadLarge extends TileEntityLaunchPadBase { } } } - + } else { - + //only extend if the erector isn't up yet and the missile can be loaded if(!erected && readyToLoad) { this.state = this.STATE_LOADING; - + //first, rotate the erector if(erector != 0F) { erector = Math.max(erector - erectorSpeed, 0F); @@ -140,7 +140,7 @@ public class TileEntityLaunchPadLarge extends TileEntityLaunchPadBase { } } } - + if(!this.hasFuel() || !this.isMissileValid()) this.state = this.STATE_MISSING; if(this.erected && this.canLaunch()) this.state = this.STATE_READY; @@ -153,11 +153,11 @@ public class TileEntityLaunchPadLarge extends TileEntityLaunchPadBase { if(prevLiftMoving && !this.liftMoving) worldObj.playSoundEffect(xCoord, yCoord, zCoord, "hbm:door.wgh_stop", 2F, 1F); if(prevErectorMoving && !this.erectorMoving) worldObj.playSoundEffect(xCoord, yCoord, zCoord, "hbm:door.garage_stop", 2F, 1F); - + } else { this.prevLift = this.lift; this.prevErector = this.erector; - + if(this.sync > 0) { this.lift = this.lift + ((this.syncLift - this.lift) / (float) this.sync); this.erector = this.erector + ((this.syncErector - this.erector) / (float) this.sync); @@ -166,7 +166,7 @@ public class TileEntityLaunchPadLarge extends TileEntityLaunchPadBase { this.lift = this.syncLift; this.erector = this.syncErector; } - + if(this.liftMoving) { if(this.audioLift == null || !this.audioLift.isPlaying()) { this.audioLift = MainRegistry.proxy.getLoopedSound("hbm:door.wgh_start", xCoord, yCoord, zCoord, 0.75F, 25F, 1.0F, 5); @@ -179,7 +179,7 @@ public class TileEntityLaunchPadLarge extends TileEntityLaunchPadBase { this.audioLift = null; } } - + if(this.erectorMoving) { if(this.audioErector == null || !this.audioErector.isPlaying()) { this.audioErector = MainRegistry.proxy.getLoopedSound("hbm:door.garage_move", xCoord, yCoord, zCoord, 1.5F, 25F, 1.0F, 5); @@ -192,7 +192,7 @@ public class TileEntityLaunchPadLarge extends TileEntityLaunchPadBase { this.audioErector = null; } } - + if(this.erected && (this.formFactor == MissileFormFactor.HUGE.ordinal() || this.formFactor == MissileFormFactor.ATLAS.ordinal()) && this.tanks[1].getFill() > 0) { NBTTagCompound data = new NBTTagCompound(); data.setString("type", "tower"); @@ -208,9 +208,9 @@ public class TileEntityLaunchPadLarge extends TileEntityLaunchPadBase { data.setFloat("strafe", 0.05F); for(int i = 0; i < 3; i++) MainRegistry.proxy.effectNT(data); } - + List entities = worldObj.getEntitiesWithinAABB(EntityMissileBaseNT.class, AxisAlignedBB.getBoundingBox(xCoord - 0.5, yCoord, zCoord - 0.5, xCoord + 1.5, yCoord + 10, zCoord + 1.5)); - + if(!entities.isEmpty()) { for(int i = 0; i < 15; i++) { @@ -218,19 +218,27 @@ public class TileEntityLaunchPadLarge extends TileEntityLaunchPadBase { if(worldObj.rand.nextBoolean()) dir = dir.getOpposite(); float moX = (float) (worldObj.rand.nextGaussian() * 0.15F + 0.75) * dir.offsetX; float moZ = (float) (worldObj.rand.nextGaussian() * 0.15F + 0.75) * dir.offsetZ; - - MainRegistry.proxy.spawnParticle(xCoord + 0.5, yCoord + 0.25, zCoord + 0.5, "launchsmoke", new float[] {moX, 0, moZ}); + + NBTTagCompound data = new NBTTagCompound(); + data.setDouble("posX", xCoord + 0.5); + data.setDouble("posY", yCoord + 0.25); + data.setDouble("posZ", zCoord + 0.5); + data.setString("type", "launchSmoke"); + data.setDouble("moX", moX); + data.setDouble("moY", 0); + data.setDouble("moZ", moZ); + MainRegistry.proxy.effectNT(data); } } } - + super.updateEntity(); } @Override public void serialize(ByteBuf buf) { super.serialize(buf); - + buf.writeBoolean(this.liftMoving); buf.writeBoolean(this.erectorMoving); buf.writeBoolean(this.erected); @@ -239,7 +247,7 @@ public class TileEntityLaunchPadLarge extends TileEntityLaunchPadBase { buf.writeFloat(this.lift); buf.writeFloat(this.erector); } - + @Override public void deserialize(ByteBuf buf) { super.deserialize(buf); @@ -251,12 +259,12 @@ public class TileEntityLaunchPadLarge extends TileEntityLaunchPadBase { this.formFactor = buf.readByte(); this.syncLift = buf.readFloat(); this.syncErector = buf.readFloat(); - + if(this.lift != this.syncLift || this.erector != this.syncErector) { this.sync = 3; } } - + @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); @@ -267,7 +275,7 @@ public class TileEntityLaunchPadLarge extends TileEntityLaunchPadBase { this.erector = nbt.getFloat("erector"); this.formFactor = nbt.getInteger("formFactor"); } - + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); @@ -284,7 +292,7 @@ public class TileEntityLaunchPadLarge extends TileEntityLaunchPadBase { super.finalizeLaunch(missile); this.erected = false; } - + @Override public DirPos[] getConPos() { return new DirPos[] { @@ -298,12 +306,12 @@ public class TileEntityLaunchPadLarge extends TileEntityLaunchPadBase { new DirPos(xCoord + 2, yCoord, zCoord - 5, Library.NEG_Z) }; } - + AxisAlignedBB bb = null; - + @Override public AxisAlignedBB getRenderBoundingBox() { - + if(bb == null) { bb = AxisAlignedBB.getBoundingBox( xCoord - 10, @@ -314,10 +322,10 @@ public class TileEntityLaunchPadLarge extends TileEntityLaunchPadBase { zCoord + 11 ); } - + return bb; } - + @Override @SideOnly(Side.CLIENT) public double getMaxRenderDistanceSquared() { diff --git a/src/main/java/com/hbm/tileentity/bomb/TileEntityLaunchPadRusted.java b/src/main/java/com/hbm/tileentity/bomb/TileEntityLaunchPadRusted.java index 8137fa469..973a078da 100644 --- a/src/main/java/com/hbm/tileentity/bomb/TileEntityLaunchPadRusted.java +++ b/src/main/java/com/hbm/tileentity/bomb/TileEntityLaunchPadRusted.java @@ -35,9 +35,9 @@ public class TileEntityLaunchPadRusted extends TileEntityMachineBase implements public int prevRedstonePower; public int redstonePower; public Set activatedBlocks = new HashSet<>(4); - + public boolean missileLoaded; - + public TileEntityLaunchPadRusted() { super(4); } @@ -49,19 +49,19 @@ public class TileEntityLaunchPadRusted extends TileEntityMachineBase implements @Override public void updateEntity() { - + if(!worldObj.isRemote) { - + if(this.redstonePower > 0 && this.prevRedstonePower <= 0) { this.launch(); } - + this.prevRedstonePower = this.redstonePower; this.networkPackNT(250); } else { - + List entities = worldObj.getEntitiesWithinAABB(EntityMissileBaseNT.class, AxisAlignedBB.getBoundingBox(xCoord - 0.5, yCoord, zCoord - 0.5, xCoord + 1.5, yCoord + 10, zCoord + 1.5)); - + if(!entities.isEmpty()) { for(int i = 0; i < 15; i++) { @@ -70,8 +70,17 @@ public class TileEntityLaunchPadRusted extends TileEntityMachineBase implements if(worldObj.rand.nextBoolean()) dir = dir.getRotation(ForgeDirection.UP); float moX = (float) (worldObj.rand.nextGaussian() * 0.15F + 0.75) * dir.offsetX; float moZ = (float) (worldObj.rand.nextGaussian() * 0.15F + 0.75) * dir.offsetZ; - - MainRegistry.proxy.spawnParticle(xCoord + 0.5, yCoord + 0.25, zCoord + 0.5, "launchsmoke", new float[] {moX, 0, moZ}); + + NBTTagCompound data = new NBTTagCompound(); + data.setDouble("posX", xCoord + 0.5); + data.setDouble("posY", yCoord + 0.25); + data.setDouble("posZ", zCoord + 0.5); + data.setString("type", "launchSmoke"); + data.setDouble("moX", moX); + data.setDouble("moY", 0); + data.setDouble("moZ", moZ); + MainRegistry.proxy.effectNT(data); + } } } @@ -82,7 +91,7 @@ public class TileEntityLaunchPadRusted extends TileEntityMachineBase implements super.serialize(buf); buf.writeBoolean(this.missileLoaded); } - + @Override public void deserialize(ByteBuf buf) { super.deserialize(buf); @@ -90,18 +99,18 @@ public class TileEntityLaunchPadRusted extends TileEntityMachineBase implements } public BombReturnCode launch() { - + if(slots[1] != null && slots[2] != null && slots[3] != null && this.missileLoaded) { if(slots[1].getItem() == ModItems.launch_code && slots[2].getItem() == ModItems.launch_key) { if(slots[3] != null && slots[3].getItem() instanceof IDesignatorItem) { IDesignatorItem designator = (IDesignatorItem) slots[3].getItem(); - + if(!designator.isReady(worldObj, slots[3], xCoord, yCoord, zCoord)) return BombReturnCode.ERROR_MISSING_COMPONENT; - + Vec3 coords = designator.getCoords(worldObj, slots[3], xCoord, yCoord, zCoord); int targetX = (int) Math.floor(coords.xCoord); int targetZ = (int) Math.floor(coords.zCoord); - + EntityMissileDoomsdayRusted missile = new EntityMissileDoomsdayRusted(worldObj, xCoord + 0.5F, yCoord + 1F, zCoord + 0.5F, targetX, targetZ); worldObj.spawnEntityInWorld(missile); TrackerUtil.setTrackingRange(worldObj, missile, 500); @@ -109,19 +118,19 @@ public class TileEntityLaunchPadRusted extends TileEntityMachineBase implements this.missileLoaded = false; this.decrStackSize(1, 1); this.markDirty(); - + return BombReturnCode.LAUNCHED; } } } - + return BombReturnCode.ERROR_MISSING_COMPONENT; } - + @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); - + this.missileLoaded = nbt.getBoolean("missileLoaded"); this.redstonePower = nbt.getInteger("redstonePower"); @@ -132,11 +141,11 @@ public class TileEntityLaunchPadRusted extends TileEntityMachineBase implements this.activatedBlocks.add(new BlockPos(activatedBlocks.getInteger("x" + i), activatedBlocks.getInteger("y" + i), activatedBlocks.getInteger("z" + i))); } } - + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); - + nbt.setBoolean("missileLoaded", missileLoaded); nbt.setInteger("redstonePower", redstonePower); @@ -172,10 +181,10 @@ public class TileEntityLaunchPadRusted extends TileEntityMachineBase implements } AxisAlignedBB bb = null; - + @Override public AxisAlignedBB getRenderBoundingBox() { - + if(bb == null) { bb = AxisAlignedBB.getBoundingBox( xCoord - 2, @@ -186,10 +195,10 @@ public class TileEntityLaunchPadRusted extends TileEntityMachineBase implements zCoord + 3 ); } - + return bb; } - + @Override @SideOnly(Side.CLIENT) public double getMaxRenderDistanceSquared() { diff --git a/src/main/java/com/hbm/tileentity/bomb/TileEntityLaunchTable.java b/src/main/java/com/hbm/tileentity/bomb/TileEntityLaunchTable.java index 053ae6eff..a5e49a870 100644 --- a/src/main/java/com/hbm/tileentity/bomb/TileEntityLaunchTable.java +++ b/src/main/java/com/hbm/tileentity/bomb/TileEntityLaunchTable.java @@ -226,7 +226,15 @@ public class TileEntityLaunchTable extends TileEntityLoadedBase implements ISide float moX = (float) (dir ? 0 : worldObj.rand.nextGaussian() * 0.65F); float moZ = (float) (!dir ? 0 : worldObj.rand.nextGaussian() * 0.65F); - MainRegistry.proxy.spawnParticle(xCoord + 0.5, yCoord + 0.25, zCoord + 0.5, "launchsmoke", new float[] {moX, 0, moZ}); + NBTTagCompound data = new NBTTagCompound(); + data.setDouble("posX", xCoord + 0.5); + data.setDouble("posY", yCoord + 0.25); + data.setDouble("posZ", zCoord + 0.5); + data.setString("type", "launchSmoke"); + data.setDouble("moX", moX); + data.setDouble("moY", 0); + data.setDouble("moZ", moZ); + MainRegistry.proxy.effectNT(data); } } } diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityBlastDoor.java b/src/main/java/com/hbm/tileentity/machine/TileEntityBlastDoor.java index d22bd4150..5d52acb62 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityBlastDoor.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityBlastDoor.java @@ -14,19 +14,19 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; public class TileEntityBlastDoor extends TileEntityLockableBase { - + public boolean isOpening = false; //0: closed, 1: opening/closing, 2:open public int state = 0; public long sysTime; private int timer = 0; public boolean redstoned = false; - + @Override public AxisAlignedBB getRenderBoundingBox() { return TileEntity.INFINITE_EXTENT_AABB; } - + @Override @SideOnly(Side.CLIENT) public double getMaxRenderDistanceSquared() @@ -36,25 +36,25 @@ public class TileEntityBlastDoor extends TileEntityLockableBase { @Override public void updateEntity() { - + if(!worldObj.isRemote) { - + if(!isLocked() && worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord) || worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord + 6, zCoord)) { - + if(!redstoned) { this.tryToggle(); } redstoned = true; - + } else { redstoned = false; } - + if(state != 1) { timer = 0; } else { timer++; - + if(isOpening) { if(timer >= 0) { removeDummy(xCoord, yCoord + 1, zCoord); @@ -88,20 +88,20 @@ public class TileEntityBlastDoor extends TileEntityLockableBase { placeDummy(xCoord, yCoord + 1, zCoord); } } - + if(timer >= 100) { - + if(isOpening) finishOpen(); else finishClose(); } } - + PacketDispatcher.wrapper.sendToAllAround(new TEVaultPacket(xCoord, yCoord, zCoord, isOpening, state, 0, 0), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 250)); } } - + public void open() { if(state == 0) { PacketDispatcher.wrapper.sendToAllAround(new TEVaultPacket(xCoord, yCoord, zCoord, isOpening, state, 1, 0), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 250)); @@ -112,17 +112,17 @@ public class TileEntityBlastDoor extends TileEntityLockableBase { 0.75F); } } - + public void finishOpen() { state = 2; this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, "hbm:block.reactorStop", 0.5F, 1.0F); } - + public void close() { if(state == 2) { - PacketDispatcher.wrapper.sendToAll(new TEVaultPacket(xCoord, yCoord, zCoord, isOpening, state, 1, 0)); + PacketDispatcher.wrapper.sendToAllAround(new TEVaultPacket(xCoord, yCoord, zCoord, isOpening, state, 1, 0), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 250)); isOpening = false; state = 1; @@ -130,116 +130,116 @@ public class TileEntityBlastDoor extends TileEntityLockableBase { 0.75F); } } - + public void finishClose() { state = 0; this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, "hbm:block.reactorStop", 0.5F, 1.0F); } - + public void openNeigh() { TileEntity te0 = worldObj.getTileEntity(xCoord + 1, yCoord, zCoord); TileEntity te1 = worldObj.getTileEntity(xCoord - 1, yCoord, zCoord); TileEntity te2 = worldObj.getTileEntity(xCoord, yCoord, zCoord + 1); TileEntity te3 = worldObj.getTileEntity(xCoord, yCoord, zCoord - 1); - + if(te0 instanceof TileEntityBlastDoor) { - + if(((TileEntityBlastDoor)te0).canOpen() && (!((TileEntityBlastDoor)te0).isLocked() || ((TileEntityBlastDoor)te0).lock == lock)) { ((TileEntityBlastDoor)te0).open(); ((TileEntityBlastDoor)te0).openNeigh(); } } - + if(te1 instanceof TileEntityBlastDoor) { - + if(((TileEntityBlastDoor)te1).canOpen() && (!((TileEntityBlastDoor)te1).isLocked() || ((TileEntityBlastDoor)te1).lock == lock)) { ((TileEntityBlastDoor)te1).open(); ((TileEntityBlastDoor)te1).openNeigh(); } } - + if(te2 instanceof TileEntityBlastDoor) { - + if(((TileEntityBlastDoor)te2).canOpen() && (!((TileEntityBlastDoor)te2).isLocked() || ((TileEntityBlastDoor)te2).lock == lock)) { ((TileEntityBlastDoor)te2).open(); ((TileEntityBlastDoor)te2).openNeigh(); } } - + if(te3 instanceof TileEntityBlastDoor) { - + if(((TileEntityBlastDoor)te3).canOpen() && (!((TileEntityBlastDoor)te3).isLocked() || ((TileEntityBlastDoor)te3).lock == lock)) { ((TileEntityBlastDoor)te3).open(); ((TileEntityBlastDoor)te3).openNeigh(); } } } - + @Override public void lock() { super.lock(); lockNeigh(); } - + public void closeNeigh() { TileEntity te0 = worldObj.getTileEntity(xCoord + 1, yCoord, zCoord); TileEntity te1 = worldObj.getTileEntity(xCoord - 1, yCoord, zCoord); TileEntity te2 = worldObj.getTileEntity(xCoord, yCoord, zCoord + 1); TileEntity te3 = worldObj.getTileEntity(xCoord, yCoord, zCoord - 1); - + if(te0 instanceof TileEntityBlastDoor) { - + if(((TileEntityBlastDoor)te0).canClose() && (!((TileEntityBlastDoor)te0).isLocked() || ((TileEntityBlastDoor)te0).lock == lock)) { ((TileEntityBlastDoor)te0).close(); ((TileEntityBlastDoor)te0).closeNeigh(); } } - + if(te1 instanceof TileEntityBlastDoor) { - + if(((TileEntityBlastDoor)te1).canClose() && (!((TileEntityBlastDoor)te1).isLocked() || ((TileEntityBlastDoor)te1).lock == lock)) { ((TileEntityBlastDoor)te1).close(); ((TileEntityBlastDoor)te1).closeNeigh(); } } - + if(te2 instanceof TileEntityBlastDoor) { - + if(((TileEntityBlastDoor)te2).canClose() && (!((TileEntityBlastDoor)te2).isLocked() || ((TileEntityBlastDoor)te2).lock == lock)) { ((TileEntityBlastDoor)te2).close(); ((TileEntityBlastDoor)te2).closeNeigh(); } } - + if(te3 instanceof TileEntityBlastDoor) { - + if(((TileEntityBlastDoor)te3).canClose() && (!((TileEntityBlastDoor)te3).isLocked() || ((TileEntityBlastDoor)te3).lock == lock)) { ((TileEntityBlastDoor)te3).close(); ((TileEntityBlastDoor)te3).closeNeigh(); } } } - + public void lockNeigh() { TileEntity te0 = worldObj.getTileEntity(xCoord + 1, yCoord, zCoord); TileEntity te1 = worldObj.getTileEntity(xCoord - 1, yCoord, zCoord); TileEntity te2 = worldObj.getTileEntity(xCoord, yCoord, zCoord + 1); TileEntity te3 = worldObj.getTileEntity(xCoord, yCoord, zCoord - 1); - + if(te0 instanceof TileEntityBlastDoor) { - + if(!((TileEntityBlastDoor)te0).isLocked()) { ((TileEntityBlastDoor)te0).setPins(this.lock); ((TileEntityBlastDoor)te0).lock(); ((TileEntityBlastDoor)te0).setMod(lockMod); } } - + if(te1 instanceof TileEntityBlastDoor) { if(!((TileEntityBlastDoor)te1).isLocked()) { @@ -248,7 +248,7 @@ public class TileEntityBlastDoor extends TileEntityLockableBase { ((TileEntityBlastDoor)te1).setMod(lockMod); } } - + if(te2 instanceof TileEntityBlastDoor) { if(!((TileEntityBlastDoor)te2).isLocked()) { @@ -257,7 +257,7 @@ public class TileEntityBlastDoor extends TileEntityLockableBase { ((TileEntityBlastDoor)te2).setMod(lockMod); } } - + if(te3 instanceof TileEntityBlastDoor) { if(!((TileEntityBlastDoor)te3).isLocked()) { @@ -267,15 +267,15 @@ public class TileEntityBlastDoor extends TileEntityLockableBase { } } } - + public boolean canOpen() { return state == 0; } - + public boolean canClose() { return state == 2; } - + public void tryToggle() { if(canOpen()) { @@ -286,28 +286,28 @@ public class TileEntityBlastDoor extends TileEntityLockableBase { closeNeigh(); } } - + public boolean placeDummy(int x, int y, int z) { - + if(!worldObj.getBlock(x, y, z).isReplaceable(worldObj, x, y, z)) return false; - + worldObj.setBlock(x, y, z, ModBlocks.dummy_block_blast); - + TileEntity te = worldObj.getTileEntity(x, y, z); - + if(te instanceof TileEntityDummy) { TileEntityDummy dummy = (TileEntityDummy)te; dummy.targetX = xCoord; dummy.targetY = yCoord; dummy.targetZ = zCoord; } - + return true; } - + public void removeDummy(int x, int y, int z) { - + if(worldObj.getBlock(x, y, z) == ModBlocks.dummy_block_blast) { DummyBlockBlast.safeBreak = true; worldObj.setBlock(x, y, z, Blocks.air); @@ -317,7 +317,7 @@ public class TileEntityBlastDoor extends TileEntityLockableBase { public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); - + isOpening = nbt.getBoolean("isOpening"); state = nbt.getInteger("state"); sysTime = nbt.getLong("sysTime"); diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityBroadcaster.java b/src/main/java/com/hbm/tileentity/machine/TileEntityBroadcaster.java index 744e3bab9..4cebc8174 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityBroadcaster.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityBroadcaster.java @@ -1,14 +1,17 @@ package com.hbm.tileentity.machine; import java.util.List; +import java.util.Random; import com.hbm.lib.ModDamageSource; -import com.hbm.packet.PacketDispatcher; -import com.hbm.packet.toclient.LoopedSoundPacket; +import com.hbm.main.MainRegistry; -import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; +import com.hbm.sound.AudioWrapper; +import com.hbm.tileentity.TileEntityLoadedBase; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityClientPlayerMP; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.potion.Potion; @@ -16,23 +19,25 @@ import net.minecraft.potion.PotionEffect; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; -public class TileEntityBroadcaster extends TileEntity { - +public class TileEntityBroadcaster extends TileEntityLoadedBase { + + private AudioWrapper audio; + @Override public void updateEntity() { - + List list = worldObj.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB.getBoundingBox(xCoord + 0.5 - 25, yCoord + 0.5 - 25, zCoord + 0.5 - 25, xCoord + 0.5 + 25, yCoord + 0.5 + 25, zCoord + 0.5 + 25)); - + for(int i = 0; i < list.size(); i++) { if(list.get(i) instanceof EntityLivingBase) { EntityLivingBase e = (EntityLivingBase)list.get(i); double d = Math.sqrt(Math.pow(e.posX - (xCoord + 0.5), 2) + Math.pow(e.posY - (yCoord + 0.5), 2) + Math.pow(e.posZ - (zCoord + 0.5), 2)); - + if(d <= 25) { if(e.getActivePotionEffect(Potion.confusion) == null || e.getActivePotionEffect(Potion.confusion).getDuration() < 100) e.addPotionEffect(new PotionEffect(Potion.confusion.id, 300, 0)); } - + if(d <= 15) { double t = (15 - d) / 15 * 10; e.attackEntityFrom(ModDamageSource.broadcast, (float) t); @@ -40,16 +45,59 @@ public class TileEntityBroadcaster extends TileEntity { } } - if(!worldObj.isRemote) { - PacketDispatcher.wrapper.sendToAllAround(new LoopedSoundPacket(xCoord, yCoord, zCoord), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 150)); + if (worldObj.isRemote) { + if(audio == null) { + audio = createAudioLoop(); + audio.startSound(); + } else if(!audio.isPlaying()) { + audio = rebootAudio(audio); + } + + int intendedVolume = 25; + + EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer; + float volume; + if(player != null) { + float f = (float)Math.sqrt(Math.pow(xCoord - player.posX, 2) + Math.pow(yCoord - player.posY, 2) + Math.pow(zCoord - player.posZ, 2)); + volume = (f / intendedVolume) * -2 + 2; + } else { + volume = intendedVolume; + } + + audio.updateVolume(getVolume(volume)); + audio.keepAlive(); } } - + + @Override + public void onChunkUnload() { + super.onChunkUnload(); + if(audio != null) { + audio.stopSound(); + audio = null; + } + } + + @Override + public void invalidate() { + super.invalidate(); + if(audio != null) { + audio.stopSound(); + audio = null; + } + } + + @Override + public AudioWrapper createAudioLoop() { + Random rand = new Random(xCoord + yCoord + zCoord); + return MainRegistry.proxy.getLoopedSound("hbm:block.broadcast" + (rand.nextInt(3) + 1), xCoord, yCoord, zCoord, 1.0F, 10F, 1.0F); + } + @Override public AxisAlignedBB getRenderBoundingBox() { return TileEntity.INFINITE_EXTENT_AABB; } - + @Override @SideOnly(Side.CLIENT) public double getMaxRenderDistanceSquared() diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineArcFurnace.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineArcFurnace.java index e2090764d..15a099436 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineArcFurnace.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineArcFurnace.java @@ -6,18 +6,15 @@ import com.hbm.inventory.container.ContainerMachineArcFurnace; import com.hbm.inventory.gui.GUIMachineArcFurnace; import com.hbm.items.ModItems; import com.hbm.lib.Library; -import com.hbm.packet.PacketDispatcher; -import com.hbm.packet.toclient.AuxElectricityPacket; -import com.hbm.packet.toclient.AuxGaugePacket; import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.TileEntityLoadedBase; import com.hbm.util.CompatEnergyControl; import api.hbm.energymk2.IEnergyReceiverMK2; import api.hbm.tile.IInfoProviderEC; -import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ISidedInventory; @@ -31,12 +28,12 @@ import net.minecraftforge.common.util.ForgeDirection; public class TileEntityMachineArcFurnace extends TileEntityLoadedBase implements ISidedInventory, IEnergyReceiverMK2, IGUIProvider, IInfoProviderEC { private ItemStack slots[]; - + public int dualCookTime; public long power; public static final long maxPower = 50000; public static final int processingSpeed = 20; - + //0: i //1: o //2: 1 @@ -44,9 +41,9 @@ public class TileEntityMachineArcFurnace extends TileEntityLoadedBase implements //4: 3 //5: b private static final int[] slots_io = new int[] {0, 1, 2, 3, 4, 5}; - + private String customName; - + public TileEntityMachineArcFurnace() { slots = new ItemStack[6]; } @@ -91,7 +88,7 @@ public class TileEntityMachineArcFurnace extends TileEntityLoadedBase implements public boolean hasCustomInventoryName() { return this.customName != null && this.customName.length() > 0; } - + public void setCustomName(String name) { this.customName = name; } @@ -110,7 +107,7 @@ public class TileEntityMachineArcFurnace extends TileEntityLoadedBase implements return player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <=64; } } - + //You scrubs aren't needed for anything (right now) @Override public void openInventory() {} @@ -119,16 +116,16 @@ public class TileEntityMachineArcFurnace extends TileEntityLoadedBase implements @Override public boolean isItemValidForSlot(int i, ItemStack itemStack) { - + if(i == 2 || i == 3 || i == 4) return itemStack.getItem() == ModItems.arc_electrode; - + if(i == 0) return FurnaceRecipes.smelting().getSmeltingResult(itemStack) != null; - + return false; } - + @Override public ItemStack decrStackSize(int i, int j) { if(slots[i] != null) @@ -144,22 +141,22 @@ public class TileEntityMachineArcFurnace extends TileEntityLoadedBase implements { slots[i] = null; } - + return itemStack1; } else { return null; } } - + @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); NBTTagList list = nbt.getTagList("items", 10); - + this.power = nbt.getLong("powerTime"); this.dualCookTime = nbt.getInteger("cookTime"); slots = new ItemStack[getSizeInventory()]; - + for(int i = 0; i < list.tagCount(); i++) { NBTTagCompound nbt1 = list.getCompoundTagAt(i); @@ -170,14 +167,14 @@ public class TileEntityMachineArcFurnace extends TileEntityLoadedBase implements } } } - + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setLong("powerTime", power); nbt.setInteger("cookTime", dualCookTime); NBTTagList list = new NBTTagList(); - + for(int i = 0; i < slots.length; i++) { if(slots[i] != null) @@ -190,7 +187,7 @@ public class TileEntityMachineArcFurnace extends TileEntityLoadedBase implements } nbt.setTag("items", list); } - + @Override public int[] getAccessibleSlotsFromSide(int side) { return slots_io; @@ -203,87 +200,87 @@ public class TileEntityMachineArcFurnace extends TileEntityLoadedBase implements @Override public boolean canExtractItem(int i, ItemStack itemStack, int j) { - + if(i == 1) return true; - + if(i == 2 || i == 3 || i == 4) return itemStack.getItem() == ModItems.arc_electrode_burnt; - + return false; } - + public int getDiFurnaceProgressScaled(int i) { return (dualCookTime * i) / processingSpeed; } - + public long getPowerRemainingScaled(long i) { return (power * i) / maxPower; } - + public boolean hasPower() { return power >= 250; } - + public boolean isProcessing() { return this.dualCookTime > 0; } - + private boolean hasElectrodes() { - + if(slots[2] != null && slots[3] != null && slots[4] != null) { if((slots[2].getItem() == ModItems.arc_electrode) && (slots[3].getItem() == ModItems.arc_electrode) && (slots[4].getItem() == ModItems.arc_electrode)) return true; } - + return false; } - + public boolean canProcess() { - + if(!hasElectrodes()) return false; - + if(slots[0] == null) { return false; } ItemStack itemStack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]); - + if(itemStack == null) { return false; } - + if(slots[1] == null) { return true; } - + if(!slots[1].isItemEqual(itemStack)) { return false; } - + if(slots[1].stackSize < getInventoryStackLimit() && slots[1].stackSize < slots[1].getMaxStackSize()) { return true; }else{ return slots[1].stackSize < itemStack.getMaxStackSize(); } } - + private void processItem() { if(canProcess()) { ItemStack itemStack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]); - + if(slots[1] == null) { slots[1] = itemStack.copy(); }else if(slots[1].isItemEqual(itemStack)) { slots[1].stackSize += itemStack.stackSize; } - + for(int i = 0; i < 1; i++) { if(slots[i].stackSize <= 0) @@ -299,26 +296,26 @@ public class TileEntityMachineArcFurnace extends TileEntityLoadedBase implements } } } - + //TODO: fix this punjabi trash @Override public void updateEntity() { boolean flag1 = false; - + if(!worldObj.isRemote) { for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) this.trySubscribe(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir); - + if(hasPower() && canProcess()) { dualCookTime++; - + power -= 250; - + if(power < 0) power = 0; - + if(this.dualCookTime == processingSpeed) { this.dualCookTime = 0; @@ -328,22 +325,22 @@ public class TileEntityMachineArcFurnace extends TileEntityLoadedBase implements }else{ dualCookTime = 0; } - + boolean trigger = true; - + if(hasPower() && canProcess() && this.dualCookTime == 0) { trigger = false; } - + if(trigger) { flag1 = true; MachineArcFurnace.updateBlockState(this.dualCookTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord); } - + if(worldObj.getBlock(xCoord, yCoord, zCoord) == ModBlocks.machine_arc_furnace_off) { - + int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); if(hasElectrodes() && meta <= 5) { @@ -353,30 +350,42 @@ public class TileEntityMachineArcFurnace extends TileEntityLoadedBase implements worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, meta - 4, 2); } } - + power = Library.chargeTEFromItems(slots, 5, power, maxPower); - PacketDispatcher.wrapper.sendToAllAround(new AuxElectricityPacket(xCoord, yCoord, zCoord, power), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50)); - PacketDispatcher.wrapper.sendToAllAround(new AuxGaugePacket(xCoord, yCoord, zCoord, dualCookTime, 0), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50)); + networkPackNT(50); // it makes no sense to refactor this to some, but I want to delete the AuxElectricityPacket already } - - + if(flag1) { this.markDirty(); } } + @Override + public void serialize(ByteBuf buf) { + super.serialize(buf); + buf.writeLong(power); + buf.writeInt(dualCookTime); + } + + @Override + public void deserialize(ByteBuf buf) { + super.deserialize(buf); + power = buf.readLong(); + dualCookTime = buf.readInt(); + } + @Override public void setPower(long i) { power = i; - + } @Override public long getPower() { return power; - + } @Override diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineGasCent.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineGasCent.java index 384e252c7..62e76ae0e 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineGasCent.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineGasCent.java @@ -11,8 +11,8 @@ import com.hbm.inventory.recipes.GasCentrifugeRecipes.PseudoFluidType; import com.hbm.items.ModItems; import com.hbm.items.machine.IItemFluidIdentifier; import com.hbm.lib.Library; -import com.hbm.packet.PacketDispatcher; -import com.hbm.packet.toclient.LoopedSoundPacket; +import com.hbm.main.MainRegistry; +import com.hbm.sound.AudioWrapper; import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.TileEntityMachineBase; import com.hbm.util.BufferUtil; @@ -23,7 +23,6 @@ import com.hbm.util.fauxpointtwelve.DirPos; import api.hbm.energymk2.IEnergyReceiverMK2; import api.hbm.fluid.IFluidStandardReceiver; import api.hbm.tile.IInfoProviderEC; -import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; @@ -33,57 +32,61 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; //epic! public class TileEntityMachineGasCent extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardReceiver, IGUIProvider, IInfoProviderEC { - + public long power; public int progress; public boolean isProgressing; public static final int maxPower = 100000; public static final int processingSpeed = 150; - + public FluidTank tank; public PseudoFluidTank inputTank; public PseudoFluidTank outputTank; - + + private int audioDuration = 0; + private AudioWrapper audio; + private static final int[] slots_io = new int[] { 0, 1, 2, 3 }; - + public TileEntityMachineGasCent() { - super(7); + super(7); tank = new FluidTank(Fluids.UF6, 2000); inputTank = new PseudoFluidTank(PseudoFluidType.NUF6, 8000); outputTank = new PseudoFluidTank(PseudoFluidType.LEUF6, 8000); } - + @Override public String getName() { return "container.gasCentrifuge"; } - + @Override public boolean canExtractItem(int i, ItemStack itemStack, int j) { return i < 4; } - + @Override public int[] getAccessibleSlotsFromSide(int side) { return slots_io; } - + @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); - + power = nbt.getLong("power"); progress = nbt.getShort("progress"); tank.readFromNBT(nbt, "tank"); inputTank.readFromNBT(nbt, "inputTank"); outputTank.readFromNBT(nbt, "outputTank"); } - + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); @@ -93,127 +96,127 @@ public class TileEntityMachineGasCent extends TileEntityMachineBase implements I inputTank.writeToNBT(nbt, "inputTank"); outputTank.writeToNBT(nbt, "outputTank"); } - + public int getCentrifugeProgressScaled(int i) { return (progress * i) / getProcessingSpeed(); } - + public long getPowerRemainingScaled(int i) { return (power * i) / maxPower; } - + private boolean canEnrich() { if(power > 0 && this.inputTank.getFill() >= inputTank.getTankType().getFluidConsumed() && this.outputTank.getFill() + this.inputTank.getTankType().getFluidProduced() <= outputTank.getMaxFill()) { - + ItemStack[] list = inputTank.getTankType().getOutput(); - + if(this.inputTank.getTankType().getIfHighSpeed()) if(!(slots[6] != null && slots[6].getItem() == ModItems.upgrade_gc_speed)) return false; - + if(list == null) return false; - + if(list.length < 1) return false; - + if(InventoryUtil.doesArrayHaveSpace(slots, 0, 3, list)) return true; } - + return false; } - + private void enrich() { ItemStack[] output = inputTank.getTankType().getOutput(); - + this.progress = 0; - inputTank.setFill(inputTank.getFill() - inputTank.getTankType().getFluidConsumed()); - outputTank.setFill(outputTank.getFill() + inputTank.getTankType().getFluidProduced()); - + inputTank.setFill(inputTank.getFill() - inputTank.getTankType().getFluidConsumed()); + outputTank.setFill(outputTank.getFill() + inputTank.getTankType().getFluidProduced()); + for(byte i = 0; i < output.length; i++) InventoryUtil.tryAddItemToInventory(slots, 0, 3, output[i].copy()); //reference types almost got me again } - + private void attemptConversion() { if(inputTank.getFill() < inputTank.getMaxFill() && tank.getFill() > 0) { int fill = Math.min(inputTank.getMaxFill() - inputTank.getFill(), tank.getFill()); - + tank.setFill(tank.getFill() - fill); inputTank.setFill(inputTank.getFill() + fill); } } - + private boolean attemptTransfer(TileEntity te) { if(te instanceof TileEntityMachineGasCent) { TileEntityMachineGasCent cent = (TileEntityMachineGasCent) te; - + if(cent.tank.getFill() == 0 && cent.tank.getTankType() == tank.getTankType()) { if(cent.inputTank.getTankType() != outputTank.getTankType() && outputTank.getTankType() != PseudoFluidType.NONE) { cent.inputTank.setTankType(outputTank.getTankType()); cent.outputTank.setTankType(outputTank.getTankType().getOutputType()); } - + //God, why did I forget about the entirety of the fucking math library? if(cent.inputTank.getFill() < cent.inputTank.getMaxFill() && outputTank.getFill() > 0) { int fill = Math.min(cent.inputTank.getMaxFill() - cent.inputTank.getFill(), outputTank.getFill()); - + outputTank.setFill(outputTank.getFill() - fill); cent.inputTank.setFill(cent.inputTank.getFill() + fill); } - + return true; } } - + return false; } - + @Override public void updateEntity() { - + if(!worldObj.isRemote) { - + updateConnections(); power = Library.chargeTEFromItems(slots, 4, power, maxPower); setTankType(5); - + if(GasCentrifugeRecipes.fluidConversions.containsValue(inputTank.getTankType())) { attemptConversion(); } - + if(canEnrich()) { - + isProgressing = true; this.progress++; - + if(slots[6] != null && slots[6].getItem() == ModItems.upgrade_gc_speed) this.power -= 300; else this.power -= 200; - + if(this.power < 0) { power = 0; this.progress = 0; } - + if(progress >= getProcessingSpeed()) enrich(); - + } else { isProgressing = false; this.progress = 0; } - + if(worldObj.getTotalWorldTime() % 10 == 0) { ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset); TileEntity te = worldObj.getTileEntity(this.xCoord - dir.offsetX, this.yCoord, this.zCoord - dir.offsetZ); - + //*AT THE MOMENT*, there's not really any need for a dedicated method for this. Yet. if(!attemptTransfer(te) && this.inputTank.getTankType() == PseudoFluidType.LEUF6) { ItemStack[] converted = new ItemStack[] { new ItemStack(ModItems.nugget_uranium_fuel, 6), new ItemStack(ModItems.fluorite) }; - + if(this.outputTank.getFill() >= 600 && InventoryUtil.doesArrayHaveSpace(slots, 0, 3, converted)) { this.outputTank.setFill(this.outputTank.getFill() - 600); for(ItemStack stack : converted) @@ -221,13 +224,46 @@ public class TileEntityMachineGasCent extends TileEntityMachineBase implements I } } } - + this.networkPackNT(50); - PacketDispatcher.wrapper.sendToAllAround(new LoopedSoundPacket(xCoord, yCoord, zCoord), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50)); + } else { + + if(isProgressing) { + audioDuration += 2; + } else { + audioDuration -= 3; + } + + audioDuration = MathHelper.clamp_int(audioDuration, 0, 60); + + if(audioDuration > 10) { + + if(audio == null) { + audio = createAudioLoop(); + audio.startSound(); + } else if(!audio.isPlaying()) { + audio = rebootAudio(audio); + } + + audio.updateVolume(getVolume(1F)); + audio.updatePitch((audioDuration - 10) / 100F + 0.5F); + + } else { + + if(audio != null) { + audio.stopSound(); + audio = null; + } + } } } - + + @Override + public AudioWrapper createAudioLoop() { + return MainRegistry.proxy.getLoopedSound("hbm:block.centrifugeOperate", xCoord, yCoord, zCoord, 1.0F, 10F, 1.0F); + } + @Override public void serialize(ByteBuf buf) { super.serialize(buf); @@ -239,35 +275,35 @@ public class TileEntityMachineGasCent extends TileEntityMachineBase implements I buf.writeInt(outputTank.getFill()); BufferUtil.writeString(buf, inputTank.getTankType().name); //cough cough BufferUtil.writeString(buf, outputTank.getTankType().name); - + tank.serialize(buf); } - + @Override public void deserialize(ByteBuf buf) { super.deserialize(buf); power = buf.readLong(); progress = buf.readInt(); isProgressing = buf.readBoolean(); - + inputTank.setFill(buf.readInt()); outputTank.setFill(buf.readInt()); inputTank.setTankType(PseudoFluidType.types.get(BufferUtil.readString(buf))); outputTank.setTankType(PseudoFluidType.types.get(BufferUtil.readString(buf))); - + tank.deserialize(buf); } - + private void updateConnections() { for(DirPos pos : getConPos()) { this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); - + if(GasCentrifugeRecipes.fluidConversions.containsValue(inputTank.getTankType())) { this.trySubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); } } } - + private DirPos[] getConPos() { return new DirPos[] { new DirPos(xCoord, yCoord - 1, zCoord, Library.NEG_Y), @@ -286,40 +322,40 @@ public class TileEntityMachineGasCent extends TileEntityMachineBase implements I @Override public long getPower() { return power; - + } @Override public long getMaxPower() { return maxPower; } - + public int getProcessingSpeed() { if(slots[6] != null && slots[6].getItem() == ModItems.upgrade_gc_speed) { return processingSpeed - 70; } return processingSpeed; } - + public void setTankType(int in) { - + if(slots[in] != null && slots[in].getItem() instanceof IItemFluidIdentifier) { IItemFluidIdentifier id = (IItemFluidIdentifier) slots[in].getItem(); FluidType newType = id.getType(worldObj, xCoord, yCoord, zCoord, slots[in]); - + if(tank.getTankType() != newType) { PseudoFluidType pseudo = GasCentrifugeRecipes.fluidConversions.get(newType); - + if(pseudo != null) { inputTank.setTankType(pseudo); outputTank.setTankType(pseudo.getOutputType()); tank.setTankType(newType); } } - + } } - + @Override public FluidTank[] getReceivingTanks() { return new FluidTank[] { tank }; @@ -329,71 +365,71 @@ public class TileEntityMachineGasCent extends TileEntityMachineBase implements I public FluidTank[] getAllTanks() { return new FluidTank[] { tank }; } - + AxisAlignedBB bb = null; - + @Override public AxisAlignedBB getRenderBoundingBox() { - + if(bb == null) { bb = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 5, zCoord + 1); } - + return bb; } - + @Override @SideOnly(Side.CLIENT) public double getMaxRenderDistanceSquared() { return 65536.0D; } - + public class PseudoFluidTank { PseudoFluidType type; int fluid; int maxFluid; - + public PseudoFluidTank(PseudoFluidType type, int maxFluid) { this.type = type; this.maxFluid = maxFluid; } - + public void setFill(int i) { fluid = i; } - + public void setTankType(PseudoFluidType type) { - + if(this.type.equals(type)) return; - + if(type == null) this.type = PseudoFluidType.NONE; else this.type = type; - + this.setFill(0); } - + public PseudoFluidType getTankType() { return type; } - + public int getFill() { return fluid; } - + public int getMaxFill() { return maxFluid; } - + //Called by TE to save fillstate public void writeToNBT(NBTTagCompound nbt, String s) { nbt.setInteger(s, fluid); nbt.setInteger(s + "_max", maxFluid); nbt.setString(s + "_type", type.name); } - + //Called by TE to load fillstate public void readFromNBT(NBTTagCompound nbt, String s) { fluid = nbt.getInteger(s); @@ -402,7 +438,7 @@ public class TileEntityMachineGasCent extends TileEntityMachineBase implements I type = PseudoFluidType.types.get(nbt.getString(s + "_type")); if(type == null) type = PseudoFluidType.NONE; } - + /* ______ ______ * _I____I_ _I____I_ * / \\\ / \\\ diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineRTG.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineRTG.java index 0ce599eea..e5a502f0c 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineRTG.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineRTG.java @@ -4,8 +4,6 @@ import com.hbm.config.VersatileConfig; import com.hbm.inventory.container.ContainerMachineRTG; import com.hbm.inventory.gui.GUIMachineRTG; import com.hbm.items.machine.ItemRTGPellet; -import com.hbm.packet.PacketDispatcher; -import com.hbm.packet.toclient.AuxElectricityPacket; import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.TileEntityLoadedBase; import com.hbm.util.CompatEnergyControl; @@ -13,9 +11,9 @@ import com.hbm.util.RTGUtil; import api.hbm.energymk2.IEnergyProviderMK2; import api.hbm.tile.IInfoProviderEC; -import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ISidedInventory; @@ -28,16 +26,16 @@ import net.minecraftforge.common.util.ForgeDirection; public class TileEntityMachineRTG extends TileEntityLoadedBase implements ISidedInventory, IEnergyProviderMK2, IGUIProvider, IInfoProviderEC { private ItemStack slots[]; - + public int heat; public final int heatMax = VersatileConfig.rtgDecay() ? 600 : 200; public long power; public final long powerMax = 100000; - + public static final int[] slot_io = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; - + private String customName; - + public TileEntityMachineRTG() { slots = new ItemStack[15]; } @@ -82,7 +80,7 @@ public class TileEntityMachineRTG extends TileEntityLoadedBase implements ISided public boolean hasCustomInventoryName() { return this.customName != null && this.customName.length() > 0; } - + public void setCustomName(String name) { this.customName = name; } @@ -101,7 +99,7 @@ public class TileEntityMachineRTG extends TileEntityLoadedBase implements ISided return player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <=64; } } - + //You scrubs aren't needed for anything (right now) @Override public void openInventory() {} @@ -112,7 +110,7 @@ public class TileEntityMachineRTG extends TileEntityLoadedBase implements ISided public boolean isItemValidForSlot(int i, ItemStack itemStack) { return itemStack.getItem() instanceof ItemRTGPellet; } - + @Override public ItemStack decrStackSize(int i, int j) { if(slots[i] != null) @@ -128,13 +126,13 @@ public class TileEntityMachineRTG extends TileEntityLoadedBase implements ISided { slots[i] = null; } - + return itemStack1; } else { return null; } } - + @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); @@ -143,7 +141,7 @@ public class TileEntityMachineRTG extends TileEntityLoadedBase implements ISided power = nbt.getLong("power"); heat = nbt.getInteger("heat"); slots = new ItemStack[getSizeInventory()]; - + for(int i = 0; i < list.tagCount(); i++) { NBTTagCompound nbt1 = list.getCompoundTagAt(i); @@ -154,14 +152,14 @@ public class TileEntityMachineRTG extends TileEntityLoadedBase implements ISided } } } - + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setLong("power", power); nbt.setInteger("heat", heat); NBTTagList list = new NBTTagList(); - + for(int i = 0; i < slots.length; i++) { if(slots[i] != null) { NBTTagCompound nbt1 = new NBTTagCompound(); @@ -172,7 +170,7 @@ public class TileEntityMachineRTG extends TileEntityLoadedBase implements ISided } nbt.setTag("items", list); } - + @Override public int[] getAccessibleSlotsFromSide(int p_94128_1_) { return slot_io; @@ -187,19 +185,19 @@ public class TileEntityMachineRTG extends TileEntityLoadedBase implements ISided public boolean canExtractItem(int i, ItemStack itemStack, int j) { return false; } - + public long getPowerScaled(long i) { return (power * i) / powerMax; } - + public int getHeatScaled(int i) { return (heat * i) / heatMax; } - + public boolean hasPower() { return power > 0; } - + public boolean hasHeat() { return RTGUtil.hasHeat(slots, slot_io); } @@ -208,23 +206,35 @@ public class TileEntityMachineRTG extends TileEntityLoadedBase implements ISided public void updateEntity() { if(!worldObj.isRemote) { - + for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) this.tryProvide(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir); - + heat = RTGUtil.updateRTGs(slots, slot_io); - + if(heat > heatMax) heat = heatMax; - + power += heat * 5; if(power > powerMax) power = powerMax; - - PacketDispatcher.wrapper.sendToAllAround(new AuxElectricityPacket(xCoord, yCoord, zCoord, power), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50)); + + networkPackNT(50); } } + @Override + public void serialize(ByteBuf buf) { + super.serialize(buf); + buf.writeLong(power); + } + + @Override + public void deserialize(ByteBuf buf) { + super.deserialize(buf); + power = buf.readLong(); + } + @Override public long getPower() { return power; diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineShredder.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineShredder.java index 67ad5583c..f948a67f4 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineShredder.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineShredder.java @@ -5,16 +5,14 @@ import com.hbm.inventory.gui.GUIMachineShredder; import com.hbm.inventory.recipes.ShredderRecipes; import com.hbm.items.machine.ItemBlades; import com.hbm.lib.Library; -import com.hbm.packet.PacketDispatcher; -import com.hbm.packet.toclient.AuxElectricityPacket; import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.TileEntityLoadedBase; import api.hbm.energymk2.IBatteryItem; import api.hbm.energymk2.IEnergyReceiverMK2; -import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ISidedInventory; @@ -33,11 +31,11 @@ public class TileEntityMachineShredder extends TileEntityLoadedBase implements I public int soundCycle = 0; public static final long maxPower = 10000; public static final int processingSpeed = 60; - + private static final int[] slots_io = new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29}; - + private String customName; - + public TileEntityMachineShredder() { slots = new ItemStack[30]; } @@ -82,7 +80,7 @@ public class TileEntityMachineShredder extends TileEntityLoadedBase implements I public boolean hasCustomInventoryName() { return this.customName != null && this.customName.length() > 0; } - + public void setCustomName(String name) { this.customName = name; } @@ -101,7 +99,7 @@ public class TileEntityMachineShredder extends TileEntityLoadedBase implements I return player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <=64; } } - + //You scrubs aren't needed for anything (right now) @Override public void openInventory() {} @@ -113,10 +111,10 @@ public class TileEntityMachineShredder extends TileEntityLoadedBase implements I if(i < 9) return ShredderRecipes.getShredderResult(stack) != null && !(stack.getItem() instanceof ItemBlades); if(i == 29) return stack.getItem() instanceof IBatteryItem; if(i == 27 || i == 28) return stack.getItem() instanceof ItemBlades; - + return false; } - + @Override public ItemStack decrStackSize(int i, int j) { if(slots[i] != null) @@ -132,21 +130,21 @@ public class TileEntityMachineShredder extends TileEntityLoadedBase implements I { slots[i] = null; } - + return itemStack1; } else { return null; } } - + @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); NBTTagList list = nbt.getTagList("items", 10); - + this.power = nbt.getLong("powerTime"); slots = new ItemStack[getSizeInventory()]; - + for(int i = 0; i < list.tagCount(); i++) { NBTTagCompound nbt1 = list.getCompoundTagAt(i); @@ -157,13 +155,13 @@ public class TileEntityMachineShredder extends TileEntityLoadedBase implements I } } } - + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setLong("powerTime", power); NBTTagList list = new NBTTagList(); - + for(int i = 0; i < slots.length; i++) { if(slots[i] != null) @@ -176,7 +174,7 @@ public class TileEntityMachineShredder extends TileEntityLoadedBase implements I } nbt.setTag("items", list); } - + @Override public int[] getAccessibleSlotsFromSide(int side) { return slots_io; @@ -186,20 +184,20 @@ public class TileEntityMachineShredder extends TileEntityLoadedBase implements I public boolean canInsertItem(int slot, ItemStack itemStack, int side) { if((slot >= 9 && slot != 27 && slot != 28) || !this.isItemValidForSlot(slot, itemStack)) return false; - + if(slots[slot] == null) return true; - + int size = slots[slot].stackSize; - + for(int k = 0; k < 9; k++) { if(slots[k] == null) return false; - + if(slots[k].getItem() == itemStack.getItem() && slots[k].getItemDamage() == itemStack.getItemDamage() && slots[k].stackSize < size) return false; } - + return true; } @@ -207,42 +205,42 @@ public class TileEntityMachineShredder extends TileEntityLoadedBase implements I public boolean canExtractItem(int i, ItemStack itemStack, int j) { if(i >= 9 && i <= 26) return true; if(i >= 27 && i <= 28) if(itemStack.getItemDamage() == itemStack.getMaxDamage() && itemStack.getMaxDamage() > 0) return true; - + return false; } - + public int getDiFurnaceProgressScaled(int i) { return (progress * i) / processingSpeed; } - + public boolean hasPower() { return power > 0; } - + public boolean isProcessing() { return this.progress > 0; } - + @Override public void updateEntity() { boolean flag1 = false; - + if(!worldObj.isRemote) { - + this.updateConnections(); - + if(hasPower() && canProcess()) { progress++; - + power -= 5; - + if(this.progress == TileEntityMachineShredder.processingSpeed) { for(int i = 27; i <= 28; i++) if(slots[i].getMaxDamage() > 0) this.slots[i].setItemDamage(this.slots[i].getItemDamage() + 1); - + this.progress = 0; this.processItem(); flag1 = true; @@ -250,66 +248,78 @@ public class TileEntityMachineShredder extends TileEntityLoadedBase implements I if(soundCycle == 0) this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, "minecart.base", getVolume(1.0F), 0.75F); soundCycle++; - + if(soundCycle >= 50) soundCycle = 0; }else{ progress = 0; } - + boolean trigger = true; - + if(hasPower() && canProcess() && this.progress == 0) { trigger = false; } - + if(trigger) { flag1 = true; } - + power = Library.chargeTEFromItems(slots, 29, power, maxPower); - - PacketDispatcher.wrapper.sendToAllAround(new AuxElectricityPacket(xCoord, yCoord, zCoord, power), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50)); + + networkPackNT(50); } - + if(flag1) { this.markDirty(); } } - + + @Override + public void serialize(ByteBuf buf) { + super.serialize(buf); + buf.writeLong(power); + } + + @Override + public void deserialize(ByteBuf buf) { + super.deserialize(buf); + power = buf.readLong(); + } + private void updateConnections() { - + for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) this.trySubscribe(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir); } - + public void processItem() { - + for(int inpSlot = 0; inpSlot < 9; inpSlot++) { if(slots[inpSlot] != null && hasSpace(slots[inpSlot])) { ItemStack inp = slots[inpSlot]; ItemStack outp = ShredderRecipes.getShredderResult(inp); - + boolean flag = false; - + for (int outSlot = 9; outSlot < 27; outSlot++) { - if (slots[outSlot] != null && slots[outSlot].getItem() == outp.getItem() && + if (slots[outSlot] != null && slots[outSlot].getItem() == outp.getItem() && slots[outSlot].getItemDamage() == outp.getItemDamage() && slots[outSlot].stackSize + outp.stackSize <= outp.getMaxStackSize()) { - + slots[outSlot].stackSize += outp.stackSize; slots[inpSlot].stackSize -= 1; flag = true; break; } } - + if(!flag) for (int outSlot = 9; outSlot < 27; outSlot++) { @@ -319,18 +329,18 @@ public class TileEntityMachineShredder extends TileEntityLoadedBase implements I break; } } - + if(slots[inpSlot].stackSize <= 0) slots[inpSlot] = null; } } } - + public boolean canProcess() { - if(slots[27] != null && slots[28] != null && - this.getGearLeft() > 0 && this.getGearLeft() < 3 && + if(slots[27] != null && slots[28] != null && + this.getGearLeft() > 0 && this.getGearLeft() < 3 && this.getGearRight() > 0 && this.getGearRight() < 3) { - + for(int i = 0; i < 9; i++) { if(slots[i] != null && slots[i].stackSize > 0 && hasSpace(slots[i])) @@ -339,14 +349,14 @@ public class TileEntityMachineShredder extends TileEntityLoadedBase implements I } } } - + return false; } - + public boolean hasSpace(ItemStack stack) { - + ItemStack result = ShredderRecipes.getShredderResult(stack); - + if (result != null) for (int i = 9; i < 27; i++) { if (slots[i] == null) { @@ -358,16 +368,16 @@ public class TileEntityMachineShredder extends TileEntityLoadedBase implements I return true; } } - + return false; } @Override public void setPower(long i) { this.power = i; - + } - + public long getPowerScaled(long i) { return (power * i) / maxPower; } @@ -381,14 +391,14 @@ public class TileEntityMachineShredder extends TileEntityLoadedBase implements I public long getMaxPower() { return TileEntityMachineShredder.maxPower; } - + public int getGearLeft() { - + if(slots[27] != null && slots[27].getItem() instanceof ItemBlades) { if(slots[27].getMaxDamage() == 0) return 1; - + if(slots[27].getItemDamage() < slots[27].getItem().getMaxDamage()/2) { return 1; @@ -398,17 +408,17 @@ public class TileEntityMachineShredder extends TileEntityLoadedBase implements I return 3; } } - + return 0; } - + public int getGearRight() { - + if(slots[28] != null && slots[28].getItem() instanceof ItemBlades) { if(slots[28].getMaxDamage() == 0) return 1; - + if(slots[28].getItemDamage() < slots[28].getItem().getMaxDamage()/2) { return 1; @@ -418,7 +428,7 @@ public class TileEntityMachineShredder extends TileEntityLoadedBase implements I return 3; } } - + return 0; }