Make ExtPropPacket ByteBuf based, along with some other performance improvements such as removing debug fluid net code and making RBMKDials more accepting of new gamerules.

This commit is contained in:
BallOfEnergy 2024-10-27 23:06:40 -05:00
parent a226685e21
commit 6443a4c391
8 changed files with 473 additions and 395 deletions

View File

@ -138,6 +138,7 @@ public class PipeNet implements IPipeNet {
tile.getWorldObj().markTileEntityChunkModified(tile.xCoord, tile.yCoord, tile.zCoord, tile);
}
/* debug code
if(trackingInstances != null) {
for(int j = 0; j < trackingInstances.size(); j++) {
PipeNet net = trackingInstances.get(j);
@ -146,6 +147,7 @@ public class PipeNet implements IPipeNet {
log(net, sdf.format(new Date(System.currentTimeMillis())) + " Sending " + given + "mB to " + conToString(con));
}
}
*/
}
}

View File

@ -14,6 +14,7 @@ import com.hbm.packet.toclient.PlayerInformPacket;
import com.hbm.util.ChatBuilder;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@ -296,6 +297,37 @@ public class HbmLivingProps implements IExtendedEntityProperties {
@Override
public void init(Entity entity, World world) { }
public void serialize(ByteBuf buf) {
buf.writeFloat(radiation);
buf.writeFloat(digamma);
buf.writeInt(asbestos);
buf.writeInt(bombTimer);
buf.writeInt(contagion);
buf.writeInt(blacklung);
buf.writeInt(oil);
buf.writeInt(this.contamination.size());
for (ContaminationEffect contaminationEffect : this.contamination) {
contaminationEffect.serialize(buf); // long ass buffers? uh, yes please!
}
}
public void deserialize(ByteBuf buf) {
if(buf.readableBytes() > 0) {
radiation = buf.readFloat();
digamma = buf.readFloat();
asbestos = buf.readInt();
bombTimer = buf.readInt();
contagion = buf.readInt();
blacklung = buf.readInt();
oil = buf.readInt();
int size = buf.readInt();
for (int i = 0; i < size; i++) {
this.contamination.add(ContaminationEffect.deserialize(buf));
}
}
}
@Deprecated
@Override
public void saveNBTData(NBTTagCompound nbt) {
@ -318,6 +350,7 @@ public class HbmLivingProps implements IExtendedEntityProperties {
nbt.setTag("HbmLivingProps", props);
}
@Deprecated
@Override
public void loadNBTData(NBTTagCompound nbt) {
@ -357,6 +390,23 @@ public class HbmLivingProps implements IExtendedEntityProperties {
return maxRad * ((float)time / (float)maxTime);
}
public void serialize(ByteBuf buf) {
buf.writeFloat(this.maxRad);
buf.writeInt(this.maxTime);
buf.writeInt(this.time);
buf.writeBoolean(ignoreArmor);
}
public static ContaminationEffect deserialize(ByteBuf buf) {
float maxRad = buf.readFloat();
int maxTime = buf.readInt();
int time = buf.readInt();
boolean ignoreArmor = buf.readBoolean();
ContaminationEffect effect = new ContaminationEffect(maxRad, maxTime, ignoreArmor);
effect.time = time;
return effect;
}
public void save(NBTTagCompound nbt, int index) {
NBTTagCompound me = new NBTTagCompound();
me.setFloat("maxRad", this.maxRad);

View File

@ -8,6 +8,7 @@ import com.hbm.main.MainRegistry;
import com.hbm.tileentity.IGUIProvider;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -165,6 +166,29 @@ public class HbmPlayerProps implements IExtendedEntityProperties {
@Override
public void init(Entity entity, World world) { }
public void serialize(ByteBuf buf) {
buf.writeBoolean(this.hasReceivedBook);
buf.writeFloat(this.shield);
buf.writeFloat(this.maxShield);
buf.writeBoolean(this.enableBackpack);
buf.writeBoolean(this.enableHUD);
buf.writeInt(this.reputation);
buf.writeBoolean(this.isOnLadder);
}
public void deserialize(ByteBuf buf) {
if(buf.readableBytes() > 0) {
this.hasReceivedBook = buf.readBoolean();
this.shield = buf.readFloat();
this.maxShield = buf.readFloat();
this.enableBackpack = buf.readBoolean();
this.enableHUD = buf.readBoolean();
this.reputation = buf.readInt();
this.isOnLadder = buf.readBoolean();
}
}
@Deprecated
@Override
public void saveNBTData(NBTTagCompound nbt) {
@ -181,6 +205,7 @@ public class HbmPlayerProps implements IExtendedEntityProperties {
nbt.setTag("HbmPlayerProps", props);
}
@Deprecated
@Override
public void loadNBTData(NBTTagCompound nbt) {

View File

@ -34,6 +34,8 @@ import com.hbm.util.ContaminationUtil.HazardType;
import com.hbm.world.biome.BiomeGenCraterBase;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@ -75,7 +77,7 @@ public class EntityEffectHandler {
if(entity instanceof EntityPlayerMP) {
HbmLivingProps props = HbmLivingProps.getData(entity);
HbmPlayerProps pprps = HbmPlayerProps.getData((EntityPlayerMP) entity);
NBTTagCompound data = new NBTTagCompound();
ByteBuf buf = Unpooled.buffer();
if(pprps.shield < pprps.getEffectiveMaxShield() && entity.ticksExisted > pprps.lastDamage + 60) {
int tsd = entity.ticksExisted - (pprps.lastDamage + 60);
@ -85,9 +87,9 @@ public class EntityEffectHandler {
if(pprps.shield > pprps.getEffectiveMaxShield())
pprps.shield = pprps.getEffectiveMaxShield();
props.saveNBTData(data);
pprps.saveNBTData(data);
PacketDispatcher.wrapper.sendTo(new ExtPropPacket(data), (EntityPlayerMP) entity);
props.serialize(buf);
pprps.serialize(buf);
PacketDispatcher.wrapper.sendTo(new ExtPropPacket(buf), (EntityPlayerMP) entity);
}
if(!entity.worldObj.isRemote) {

View File

@ -15,23 +15,19 @@ import io.netty.buffer.Unpooled;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ExtPropPacket implements IMessage {
PacketBuffer buffer;
ByteBuf buffer;
public ExtPropPacket() { }
public ExtPropPacket(NBTTagCompound nbt) {
public ExtPropPacket(ByteBuf buf) {
this.buffer = new PacketBuffer(Unpooled.buffer());
try {
buffer.writeNBTTagCompoundToBuffer(nbt);
} catch (IOException e) {
e.printStackTrace();
}
this.buffer = Unpooled.buffer();
buffer.writeBytes(buf);
}
@Override
@ -61,17 +57,13 @@ public class ExtPropPacket implements IMessage {
if(Minecraft.getMinecraft().theWorld == null)
return null;
try {
ByteBuf buf = Unpooled.buffer();
NBTTagCompound nbt = m.buffer.readNBTTagCompoundFromBuffer();
HbmLivingProps props = HbmLivingProps.getData(Minecraft.getMinecraft().thePlayer);
HbmPlayerProps pprps = HbmPlayerProps.getData(Minecraft.getMinecraft().thePlayer);
props.loadNBTData(nbt);
pprps.loadNBTData(nbt);
HbmLivingProps props = HbmLivingProps.getData(Minecraft.getMinecraft().thePlayer);
HbmPlayerProps pprps = HbmPlayerProps.getData(Minecraft.getMinecraft().thePlayer);
} catch (IOException e) {
e.printStackTrace();
}
props.deserialize(buf);
pprps.deserialize(buf);
return null;
}

View File

@ -64,9 +64,6 @@ public class TileEntityCondenser extends TileEntityLoadedBase implements IFluidS
age = 0;
}
NBTTagCompound data = new NBTTagCompound();
this.tanks[0].writeToNBT(data, "0");
if(this.waterTimer > 0)
this.waterTimer--;
@ -90,8 +87,6 @@ public class TileEntityCondenser extends TileEntityLoadedBase implements IFluidS
postConvert(convert);
}
this.tanks[1].writeToNBT(data, "1");
this.subscribeToAllAround(tanks[0].getTankType(), this);
this.sendFluidToAll(tanks[1], this);

View File

@ -71,7 +71,7 @@ public class RBMKDials {
* @return >0
*/
public static double getPassiveCooling(World world) {
return Math.max(GameRuleHelper.parseDouble(world.getGameRules().getGameRuleStringValue(KEY_PASSIVE_COOLING), 1.0D), 0.0D);
return Math.max(GameRuleHelper.parseDouble(world, world.getGameRules().getGameRuleStringValue(KEY_PASSIVE_COOLING), 1.0D), 0.0D);
}
/**
@ -80,7 +80,7 @@ public class RBMKDials {
* @return [0;1]
*/
public static double getColumnHeatFlow(World world) {
return MathHelper.clamp_double(GameRuleHelper.parseDouble(world.getGameRules().getGameRuleStringValue(KEY_COLUMN_HEAT_FLOW), 0.2D), 0.0D, 1.0D);
return MathHelper.clamp_double(GameRuleHelper.parseDouble(world, world.getGameRules().getGameRuleStringValue(KEY_COLUMN_HEAT_FLOW), 0.2D), 0.0D, 1.0D);
}
/**
@ -89,7 +89,7 @@ public class RBMKDials {
* @return >0
*/
public static double getFuelDiffusionMod(World world) {
return Math.max(GameRuleHelper.parseDouble(world.getGameRules().getGameRuleStringValue(KEY_FUEL_DIFFUSION_MOD), 1.0D), 0.0D);
return Math.max(GameRuleHelper.parseDouble(world, world.getGameRules().getGameRuleStringValue(KEY_FUEL_DIFFUSION_MOD), 1.0D), 0.0D);
}
/**
@ -98,7 +98,7 @@ public class RBMKDials {
* @return [0;1]
*/
public static double getFuelHeatProvision(World world) {
return MathHelper.clamp_double(GameRuleHelper.parseDouble(world.getGameRules().getGameRuleStringValue(KEY_HEAT_PROVISION), 0.2D), 0.0D, 1.0D);
return MathHelper.clamp_double(GameRuleHelper.parseDouble(world, world.getGameRules().getGameRuleStringValue(KEY_HEAT_PROVISION), 0.2D), 0.0D, 1.0D);
}
/**
@ -107,7 +107,7 @@ public class RBMKDials {
* @return [0;15]
*/
public static int getColumnHeight(World world) {
return MathHelper.clamp_int(GameRuleHelper.parseInt(world.getGameRules().getGameRuleStringValue(KEY_COLUMN_HEIGHT), 4), 2, 16) - 1;
return MathHelper.clamp_int(GameRuleHelper.parseInt(world, world.getGameRules().getGameRuleStringValue(KEY_COLUMN_HEIGHT), 4), 2, 16) - 1;
}
/**
@ -125,7 +125,7 @@ public class RBMKDials {
* @return >0
*/
public static double getBoilerHeatConsumption(World world) {
return Math.max(GameRuleHelper.parseDouble(world.getGameRules().getGameRuleStringValue(KEY_BOILER_HEAT_CONSUMPTION), 0.1D), 0D);
return Math.max(GameRuleHelper.parseDouble(world, world.getGameRules().getGameRuleStringValue(KEY_BOILER_HEAT_CONSUMPTION), 0.1D), 0D);
}
/**
@ -134,7 +134,7 @@ public class RBMKDials {
* @return >0
*/
public static double getControlSpeed(World world) {
return Math.max(GameRuleHelper.parseDouble(world.getGameRules().getGameRuleStringValue(KEY_CONTROL_SPEED_MOD), 1.0D), 0.0D);
return Math.max(GameRuleHelper.parseDouble(world, world.getGameRules().getGameRuleStringValue(KEY_CONTROL_SPEED_MOD), 1.0D), 0.0D);
}
/**
@ -143,7 +143,7 @@ public class RBMKDials {
* @return >0
*/
public static double getReactivityMod(World world) {
return Math.max(GameRuleHelper.parseDouble(world.getGameRules().getGameRuleStringValue(KEY_REACTIVITY_MOD), 1.0D), 0.0D);
return Math.max(GameRuleHelper.parseDouble(world, world.getGameRules().getGameRuleStringValue(KEY_REACTIVITY_MOD), 1.0D), 0.0D);
}
/**
@ -152,7 +152,7 @@ public class RBMKDials {
* @return >0
*/
public static double getOutgasserMod(World world) {
return Math.max(GameRuleHelper.parseDouble(world.getGameRules().getGameRuleStringValue(KEY_OUTGASSER_MOD), 1.0D), 0.0D);
return Math.max(GameRuleHelper.parseDouble(world, world.getGameRules().getGameRuleStringValue(KEY_OUTGASSER_MOD), 1.0D), 0.0D);
}
/**
@ -161,7 +161,7 @@ public class RBMKDials {
* @return >0
*/
public static double getSurgeMod(World world) {
return Math.max(GameRuleHelper.parseDouble(world.getGameRules().getGameRuleStringValue(KEY_SURGE_MOD), 1.0D), 0.0D);
return Math.max(GameRuleHelper.parseDouble(world, world.getGameRules().getGameRuleStringValue(KEY_SURGE_MOD), 1.0D), 0.0D);
}
/**
@ -170,7 +170,7 @@ public class RBMKDials {
* @return [1;100]
*/
public static int getFluxRange(World world) {
return MathHelper.clamp_int(GameRuleHelper.parseInt(world.getGameRules().getGameRuleStringValue(KEY_FLUX_RANGE), 5), 1, 100);
return MathHelper.clamp_int(GameRuleHelper.parseInt(world, world.getGameRules().getGameRuleStringValue(KEY_FLUX_RANGE), 5), 1, 100);
}
/**
@ -179,7 +179,7 @@ public class RBMKDials {
* @return [1;100]
*/
public static int getReaSimRange(World world) {
return MathHelper.clamp_int(GameRuleHelper.parseInt(world.getGameRules().getGameRuleStringValue(KEY_REASIM_RANGE), 10), 1, 100);
return MathHelper.clamp_int(GameRuleHelper.parseInt(world, world.getGameRules().getGameRuleStringValue(KEY_REASIM_RANGE), 10), 1, 100);
}
/**
@ -188,7 +188,7 @@ public class RBMKDials {
* @return [1;24]
*/
public static int getReaSimCount(World world) {
return MathHelper.clamp_int(GameRuleHelper.parseInt(world.getGameRules().getGameRuleStringValue(KEY_REASIM_COUNT), 6), 1, 24);
return MathHelper.clamp_int(GameRuleHelper.parseInt(world, world.getGameRules().getGameRuleStringValue(KEY_REASIM_COUNT), 6), 1, 24);
}
/**
@ -197,7 +197,7 @@ public class RBMKDials {
* @return >0
*/
public static double getReaSimOutputMod(World world) {
return Math.max(GameRuleHelper.parseDouble(world.getGameRules().getGameRuleStringValue(KEY_REASIM_MOD), 1.0D), 0.0D);
return Math.max(GameRuleHelper.parseDouble(world, world.getGameRules().getGameRuleStringValue(KEY_REASIM_MOD), 1.0D), 0.0D);
}
/**
@ -215,7 +215,7 @@ public class RBMKDials {
* @return [0;1]
*/
public static double getReaSimBoilerSpeed(World world) {
return MathHelper.clamp_double(GameRuleHelper.parseDouble(world.getGameRules().getGameRuleStringValue(KEY_REASIM_BOILER_SPEED), 0.05D), 0.0D, 1.0D);
return MathHelper.clamp_double(GameRuleHelper.parseDouble(world, world.getGameRules().getGameRuleStringValue(KEY_REASIM_BOILER_SPEED), 0.05D), 0.0D, 1.0D);
}
/**
@ -243,7 +243,7 @@ public class RBMKDials {
* @return
*/
public static double getModeratorEfficiency(World world) {
return MathHelper.clamp_double(GameRuleHelper.parseDouble(world.getGameRules().getGameRuleStringValue(KEY_MODERATOR_EFFICIENCY), 1D), 0.0D, 1.0D);
return GameRuleHelper.getClampedDouble(world, world.getGameRules().getGameRuleStringValue(KEY_MODERATOR_EFFICIENCY), 1D, 0.0D, 1.0D);
}
/**
@ -252,7 +252,7 @@ public class RBMKDials {
* @return
*/
public static double getAbsorberEfficiency(World world) {
return MathHelper.clamp_double(GameRuleHelper.parseDouble(world.getGameRules().getGameRuleStringValue(KEY_MODERATOR_EFFICIENCY), 1D), 0.0D, 1.0D);
return GameRuleHelper.getClampedDouble(world, world.getGameRules().getGameRuleStringValue(KEY_ABSORBER_EFFICIENCY), 1D, 0.0D, 1.0D);
}
/**
@ -261,6 +261,6 @@ public class RBMKDials {
* @return
*/
public static double getReflectorEfficiency(World world) {
return MathHelper.clamp_double(GameRuleHelper.parseDouble(world.getGameRules().getGameRuleStringValue(KEY_MODERATOR_EFFICIENCY), 1D), 0.0D, 1.0D);
return GameRuleHelper.getClampedDouble(world, world.getGameRules().getGameRuleStringValue(KEY_REFLECTOR_EFFICIENCY), 1D, 0.0D, 1.0D);
}
}

View File

@ -1,23 +1,30 @@
package com.hbm.util;
import net.minecraft.util.MathHelper;
import net.minecraft.world.GameRules;
import net.minecraft.world.World;
public class GameRuleHelper {
public static double getClampedDouble(World world, String rule, double def, double min, double max) {
return MathHelper.clamp_double(GameRuleHelper.parseDouble(world.getGameRules().getGameRuleStringValue(rule), def), min, max);
return MathHelper.clamp_double(GameRuleHelper.parseDouble(world, world.getGameRules().getGameRuleStringValue(rule), def), min, max);
}
public static double getDoubleMinimum(World world, String rule, double def, double min) {
return Math.max(GameRuleHelper.parseDouble(world.getGameRules().getGameRuleStringValue(rule), def), min);
return Math.max(GameRuleHelper.parseDouble(world, world.getGameRules().getGameRuleStringValue(rule), def), min);
}
public static int getIntegerMinimum(World world, String rule, int def, int min) {
return Math.max(GameRuleHelper.parseInt(world.getGameRules().getGameRuleStringValue(rule), def), min);
return Math.max(GameRuleHelper.parseInt(world, world.getGameRules().getGameRuleStringValue(rule), def), min);
}
public static double parseDouble(String s, double def) {
public static double parseDouble(World world, String s, double def) {
GameRules rules = world.getGameRules();
if(s.isEmpty() && !rules.hasRule(s)) {
rules.addGameRule(s, String.valueOf(def));
return def;
}
try {
return Double.parseDouble(s);
@ -26,7 +33,12 @@ public class GameRuleHelper {
return def;
}
public static int parseInt(String s, int def) {
public static int parseInt(World world, String s, int def) {
GameRules rules = world.getGameRules();
if(s.isEmpty() && !rules.hasRule(s)) {
rules.addGameRule(s, String.valueOf(def));
}
try {
return Integer.parseInt(s);