mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
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:
parent
a226685e21
commit
6443a4c391
@ -18,18 +18,18 @@ public class PipeNet implements IPipeNet {
|
||||
private FluidType type;
|
||||
private List<IFluidConductor> links = new ArrayList();
|
||||
private HashSet<IFluidConnector> subscribers = new HashSet();
|
||||
|
||||
|
||||
public static List<PipeNet> trackingInstances = null;
|
||||
protected BigInteger totalTransfer = BigInteger.ZERO;
|
||||
public List<String> debug = new ArrayList();
|
||||
|
||||
|
||||
public PipeNet(FluidType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinNetworks(IPipeNet network) {
|
||||
|
||||
|
||||
if(network == this)
|
||||
return;
|
||||
|
||||
@ -38,11 +38,11 @@ public class PipeNet implements IPipeNet {
|
||||
this.getLinks().add(conductor);
|
||||
}
|
||||
network.getLinks().clear();
|
||||
|
||||
|
||||
for(IFluidConnector connector : network.getSubscribers()) {
|
||||
this.subscribe(connector);
|
||||
}
|
||||
|
||||
|
||||
network.destroy();
|
||||
}
|
||||
|
||||
@ -58,10 +58,10 @@ public class PipeNet implements IPipeNet {
|
||||
|
||||
@Override
|
||||
public IPipeNet joinLink(IFluidConductor conductor) {
|
||||
|
||||
|
||||
if(conductor.getPipeNet(type) != null)
|
||||
conductor.getPipeNet(type).leaveLink(conductor);
|
||||
|
||||
|
||||
conductor.setPipeNet(type, this);
|
||||
this.links.add(conductor);
|
||||
return this;
|
||||
@ -91,53 +91,54 @@ public class PipeNet implements IPipeNet {
|
||||
@Override
|
||||
public long transferFluid(long fill, int pressure) {
|
||||
|
||||
subscribers.removeIf(x ->
|
||||
subscribers.removeIf(x ->
|
||||
x == null || !(x instanceof TileEntity) || ((TileEntity)x).isInvalid() || !x.isLoaded()
|
||||
);
|
||||
|
||||
|
||||
if(this.subscribers.isEmpty())
|
||||
return fill;
|
||||
|
||||
|
||||
trackingInstances = new ArrayList();
|
||||
trackingInstances.add(this);
|
||||
List<IFluidConnector> subList = new ArrayList(subscribers);
|
||||
return fairTransfer(subList, type, pressure, fill);
|
||||
}
|
||||
|
||||
|
||||
public static long fairTransfer(List<IFluidConnector> subList, FluidType type, int pressure, long fill) {
|
||||
|
||||
|
||||
if(fill <= 0) return 0;
|
||||
|
||||
|
||||
List<Long> weight = new ArrayList();
|
||||
long totalReq = 0;
|
||||
|
||||
|
||||
for(IFluidConnector con : subList) {
|
||||
long req = con.getDemand(type, pressure);
|
||||
weight.add(req);
|
||||
totalReq += req;
|
||||
}
|
||||
|
||||
|
||||
if(totalReq == 0)
|
||||
return fill;
|
||||
|
||||
|
||||
long totalGiven = 0;
|
||||
|
||||
|
||||
for(int i = 0; i < subList.size(); i++) {
|
||||
IFluidConnector con = subList.get(i);
|
||||
long req = weight.get(i);
|
||||
double fraction = (double)req / (double)totalReq;
|
||||
|
||||
|
||||
long given = (long) Math.floor(fraction * fill);
|
||||
|
||||
|
||||
if(given > 0) {
|
||||
|
||||
|
||||
totalGiven += (given - con.transferFluid(type, pressure, given));
|
||||
|
||||
|
||||
if(con instanceof TileEntity) {
|
||||
TileEntity tile = (TileEntity) con;
|
||||
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,17 +147,18 @@ public class PipeNet implements IPipeNet {
|
||||
log(net, sdf.format(new Date(System.currentTimeMillis())) + " Sending " + given + "mB to " + conToString(con));
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(trackingInstances != null) {
|
||||
|
||||
|
||||
for(int i = 0; i < trackingInstances.size(); i++) {
|
||||
PipeNet net = trackingInstances.get(i);
|
||||
net.totalTransfer = net.totalTransfer.add(BigInteger.valueOf(totalGiven));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return fill - totalGiven;
|
||||
}
|
||||
|
||||
@ -169,10 +171,10 @@ public class PipeNet implements IPipeNet {
|
||||
public void destroy() {
|
||||
this.valid = false;
|
||||
this.subscribers.clear();
|
||||
|
||||
|
||||
for(IFluidConductor con : this.links)
|
||||
con.setPipeNet(type, null);
|
||||
|
||||
|
||||
this.links.clear();
|
||||
}
|
||||
|
||||
@ -185,22 +187,22 @@ public class PipeNet implements IPipeNet {
|
||||
public BigInteger getTotalTransfer() {
|
||||
return this.totalTransfer;
|
||||
}
|
||||
|
||||
|
||||
public static void log(PipeNet net, String msg) {
|
||||
net.debug.add(msg);
|
||||
|
||||
|
||||
while(net.debug.size() > 50) {
|
||||
net.debug.remove(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String conToString(IFluidConnector con) {
|
||||
|
||||
|
||||
if(con instanceof TileEntity) {
|
||||
TileEntity tile = (TileEntity) con;
|
||||
return tile.getClass().getSimpleName() + " @ " + tile.xCoord + "/" + tile.yCoord + "/" + tile.zCoord;
|
||||
}
|
||||
|
||||
|
||||
return "" + con;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -30,11 +31,11 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IExtendedEntityProperties;
|
||||
|
||||
public class HbmLivingProps implements IExtendedEntityProperties {
|
||||
|
||||
|
||||
public static final String key = "NTM_EXT_LIVING";
|
||||
public static final UUID digamma_UUID = UUID.fromString("2a3d8aec-5ab9-4218-9b8b-ca812bdf378b");
|
||||
public EntityLivingBase entity;
|
||||
|
||||
|
||||
/// VALS ///
|
||||
private float radiation;
|
||||
private float digamma;
|
||||
@ -51,24 +52,24 @@ public class HbmLivingProps implements IExtendedEntityProperties {
|
||||
private boolean frozen = false;
|
||||
private boolean burning = false;
|
||||
private List<ContaminationEffect> contamination = new ArrayList();
|
||||
|
||||
|
||||
public HbmLivingProps(EntityLivingBase entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
|
||||
/// DATA ///
|
||||
public static HbmLivingProps registerData(EntityLivingBase entity) {
|
||||
|
||||
|
||||
entity.registerExtendedProperties(key, new HbmLivingProps(entity));
|
||||
return (HbmLivingProps) entity.getExtendedProperties(key);
|
||||
}
|
||||
|
||||
|
||||
public static HbmLivingProps getData(EntityLivingBase entity) {
|
||||
|
||||
|
||||
HbmLivingProps props = (HbmLivingProps) entity.getExtendedProperties(key);
|
||||
return props != null ? props : registerData(entity);
|
||||
}
|
||||
|
||||
|
||||
/// RADIATION ///
|
||||
public static float getRadiation(EntityLivingBase entity) {
|
||||
if(!RadiationConfig.enableContamination)
|
||||
@ -76,89 +77,89 @@ public class HbmLivingProps implements IExtendedEntityProperties {
|
||||
|
||||
return getData(entity).radiation;
|
||||
}
|
||||
|
||||
|
||||
public static void setRadiation(EntityLivingBase entity, float rad) {
|
||||
if(RadiationConfig.enableContamination)
|
||||
getData(entity).radiation = rad;
|
||||
}
|
||||
|
||||
|
||||
public static void incrementRadiation(EntityLivingBase entity, float rad) {
|
||||
if(!RadiationConfig.enableContamination)
|
||||
return;
|
||||
|
||||
|
||||
HbmLivingProps data = getData(entity);
|
||||
float radiation = getData(entity).radiation + rad;
|
||||
|
||||
|
||||
if(radiation > 2500)
|
||||
radiation = 2500;
|
||||
if(radiation < 0)
|
||||
radiation = 0;
|
||||
|
||||
|
||||
data.setRadiation(entity, radiation);
|
||||
}
|
||||
|
||||
|
||||
/// RAD ENV ///
|
||||
public static float getRadEnv(EntityLivingBase entity) {
|
||||
return getData(entity).radEnv;
|
||||
}
|
||||
|
||||
|
||||
public static void setRadEnv(EntityLivingBase entity, float rad) {
|
||||
getData(entity).radEnv = rad;
|
||||
}
|
||||
|
||||
|
||||
/// RAD BUF ///
|
||||
public static float getRadBuf(EntityLivingBase entity) {
|
||||
return getData(entity).radBuf;
|
||||
}
|
||||
|
||||
|
||||
public static void setRadBuf(EntityLivingBase entity, float rad) {
|
||||
getData(entity).radBuf = rad;
|
||||
}
|
||||
|
||||
|
||||
/// CONTAMINATION ///
|
||||
public static List<ContaminationEffect> getCont(EntityLivingBase entity) {
|
||||
return getData(entity).contamination;
|
||||
}
|
||||
|
||||
|
||||
public static void addCont(EntityLivingBase entity, ContaminationEffect cont) {
|
||||
getData(entity).contamination.add(cont);
|
||||
}
|
||||
|
||||
|
||||
/// DIGAMA ///
|
||||
public static float getDigamma(EntityLivingBase entity) {
|
||||
return getData(entity).digamma;
|
||||
}
|
||||
|
||||
|
||||
public static void setDigamma(EntityLivingBase entity, float digamma) {
|
||||
|
||||
|
||||
if(entity.worldObj.isRemote)
|
||||
return;
|
||||
|
||||
|
||||
if(entity instanceof EntityDuck)
|
||||
digamma = 0.0F;
|
||||
|
||||
|
||||
getData(entity).digamma = digamma;
|
||||
|
||||
|
||||
float healthMod = (float)Math.pow(0.5, digamma) - 1F;
|
||||
|
||||
|
||||
IAttributeInstance attributeinstance = entity.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.maxHealth);
|
||||
|
||||
|
||||
try {
|
||||
attributeinstance.removeModifier(attributeinstance.getModifier(digamma_UUID));
|
||||
} catch(Exception ex) { }
|
||||
|
||||
|
||||
attributeinstance.applyModifier(new AttributeModifier(digamma_UUID, "digamma", healthMod, 2));
|
||||
|
||||
|
||||
if(entity.getHealth() > entity.getMaxHealth() && entity.getMaxHealth() > 0) {
|
||||
entity.setHealth(entity.getMaxHealth());
|
||||
}
|
||||
|
||||
|
||||
if((entity.getMaxHealth() <= 0 || digamma >= 10.0F) && entity.isEntityAlive()) {
|
||||
entity.setAbsorptionAmount(0);
|
||||
entity.attackEntityFrom(ModDamageSource.digamma, 500F);
|
||||
entity.setHealth(0);
|
||||
entity.onDeath(ModDamageSource.digamma);
|
||||
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setString("type", "sweat");
|
||||
data.setInteger("count", 50);
|
||||
@ -166,9 +167,9 @@ public class HbmLivingProps implements IExtendedEntityProperties {
|
||||
data.setInteger("entity", entity.getEntityId());
|
||||
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, 0, 0, 0), new TargetPoint(entity.dimension, entity.posX, entity.posY, entity.posZ, 50));
|
||||
}
|
||||
|
||||
|
||||
if(entity instanceof EntityPlayer) {
|
||||
|
||||
|
||||
float di = getData(entity).digamma;
|
||||
|
||||
if(di > 0F)
|
||||
@ -179,107 +180,107 @@ public class HbmLivingProps implements IExtendedEntityProperties {
|
||||
((EntityPlayer) entity).triggerAchievement(MainRegistry.digammaKnow);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void incrementDigamma(EntityLivingBase entity, float digamma) {
|
||||
|
||||
|
||||
if(entity instanceof EntityDuck)
|
||||
digamma = 0.0F;
|
||||
|
||||
|
||||
HbmLivingProps data = getData(entity);
|
||||
float dRad = getDigamma(entity) + digamma;
|
||||
|
||||
|
||||
if(dRad > 10)
|
||||
dRad = 10;
|
||||
if(dRad < 0)
|
||||
dRad = 0;
|
||||
|
||||
|
||||
data.setDigamma(entity, dRad);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// ASBESTOS ///
|
||||
public static int getAsbestos(EntityLivingBase entity) {
|
||||
if(RadiationConfig.disableAsbestos) return 0;
|
||||
return getData(entity).asbestos;
|
||||
}
|
||||
|
||||
|
||||
public static void setAsbestos(EntityLivingBase entity, int asbestos) {
|
||||
if(RadiationConfig.disableAsbestos) return;
|
||||
getData(entity).asbestos = asbestos;
|
||||
|
||||
|
||||
if(asbestos >= maxAsbestos) {
|
||||
getData(entity).asbestos = 0;
|
||||
entity.attackEntityFrom(ModDamageSource.asbestos, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void incrementAsbestos(EntityLivingBase entity, int asbestos) {
|
||||
if(RadiationConfig.disableAsbestos) return;
|
||||
setAsbestos(entity, getAsbestos(entity) + asbestos);
|
||||
|
||||
|
||||
if(entity instanceof EntityPlayerMP) {
|
||||
PacketDispatcher.wrapper.sendTo(new PlayerInformPacket(ChatBuilder.start("").nextTranslation("info.asbestos").color(EnumChatFormatting.RED).flush(), MainRegistry.proxy.ID_GAS_HAZARD, 3000), (EntityPlayerMP) entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// BLACK LUNG DISEASE ///
|
||||
public static int getBlackLung(EntityLivingBase entity) {
|
||||
if(RadiationConfig.disableCoal) return 0;
|
||||
return getData(entity).blacklung;
|
||||
}
|
||||
|
||||
|
||||
public static void setBlackLung(EntityLivingBase entity, int blacklung) {
|
||||
if(RadiationConfig.disableCoal) return;
|
||||
getData(entity).blacklung = blacklung;
|
||||
|
||||
|
||||
if(blacklung >= maxBlacklung) {
|
||||
getData(entity).blacklung = 0;
|
||||
entity.attackEntityFrom(ModDamageSource.blacklung, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void incrementBlackLung(EntityLivingBase entity, int blacklung) {
|
||||
if(RadiationConfig.disableCoal) return;
|
||||
setBlackLung(entity, getBlackLung(entity) + blacklung);
|
||||
|
||||
|
||||
if(entity instanceof EntityPlayerMP) {
|
||||
PacketDispatcher.wrapper.sendTo(new PlayerInformPacket(ChatBuilder.start("").nextTranslation("info.coaldust").color(EnumChatFormatting.RED).flush(), MainRegistry.proxy.ID_GAS_HAZARD, 3000), (EntityPlayerMP) entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// TIME BOMB ///
|
||||
public static int getTimer(EntityLivingBase entity) {
|
||||
return getData(entity).bombTimer;
|
||||
}
|
||||
|
||||
|
||||
public static void setTimer(EntityLivingBase entity, int bombTimer) {
|
||||
getData(entity).bombTimer = bombTimer;
|
||||
}
|
||||
|
||||
|
||||
/// CONTAGION ///
|
||||
public static int getContagion(EntityLivingBase entity) {
|
||||
return getData(entity).contagion;
|
||||
}
|
||||
|
||||
|
||||
public static void setContagion(EntityLivingBase entity, int contageon) {
|
||||
getData(entity).contagion = contageon;
|
||||
}
|
||||
|
||||
|
||||
/// OIL ///
|
||||
public static int getOil(EntityLivingBase entity) {
|
||||
return getData(entity).oil;
|
||||
}
|
||||
|
||||
|
||||
public static void setOil(EntityLivingBase entity, int oil) {
|
||||
getData(entity).oil = oil;
|
||||
}
|
||||
|
||||
|
||||
/// TEMPERATURE ///
|
||||
public static int getTemperature(EntityLivingBase entity) {
|
||||
return getData(entity).temperature;
|
||||
}
|
||||
|
||||
|
||||
public static void setTemperature(EntityLivingBase entity, int temperature) {
|
||||
HbmLivingProps data = getData(entity);
|
||||
temperature = MathHelper.clamp_int(temperature, -2500, 2500);
|
||||
@ -296,11 +297,42 @@ 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) {
|
||||
|
||||
|
||||
NBTTagCompound props = new NBTTagCompound();
|
||||
|
||||
|
||||
props.setFloat("hfr_radiation", radiation);
|
||||
props.setFloat("hfr_digamma", digamma);
|
||||
props.setInteger("hfr_asbestos", asbestos);
|
||||
@ -308,21 +340,22 @@ public class HbmLivingProps implements IExtendedEntityProperties {
|
||||
props.setInteger("hfr_contagion", contagion);
|
||||
props.setInteger("hfr_blacklung", blacklung);
|
||||
props.setInteger("hfr_oil", oil);
|
||||
|
||||
|
||||
props.setInteger("hfr_cont_count", this.contamination.size());
|
||||
|
||||
|
||||
for(int i = 0; i < this.contamination.size(); i++) {
|
||||
this.contamination.get(i).save(props, i);
|
||||
}
|
||||
|
||||
|
||||
nbt.setTag("HbmLivingProps", props);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void loadNBTData(NBTTagCompound nbt) {
|
||||
|
||||
|
||||
NBTTagCompound props = (NBTTagCompound) nbt.getTag("HbmLivingProps");
|
||||
|
||||
|
||||
if(props != null) {
|
||||
radiation = props.getFloat("hfr_radiation");
|
||||
digamma = props.getFloat("hfr_digamma");
|
||||
@ -331,32 +364,49 @@ public class HbmLivingProps implements IExtendedEntityProperties {
|
||||
contagion = props.getInteger("hfr_contagion");
|
||||
blacklung = props.getInteger("hfr_blacklung");
|
||||
oil = props.getInteger("hfr_oil");
|
||||
|
||||
|
||||
int cont = props.getInteger("hfr_cont_count");
|
||||
|
||||
|
||||
for(int i = 0; i < cont; i++) {
|
||||
this.contamination.add(ContaminationEffect.load(props, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class ContaminationEffect {
|
||||
|
||||
|
||||
public float maxRad;
|
||||
public int maxTime;
|
||||
public int time;
|
||||
public boolean ignoreArmor;
|
||||
|
||||
|
||||
public ContaminationEffect(float rad, int time, boolean ignoreArmor) {
|
||||
this.maxRad = rad;
|
||||
this.maxTime = this.time = time;
|
||||
this.ignoreArmor = ignoreArmor;
|
||||
}
|
||||
|
||||
|
||||
public float getRad() {
|
||||
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);
|
||||
@ -365,14 +415,14 @@ public class HbmLivingProps implements IExtendedEntityProperties {
|
||||
me.setBoolean("ignoreArmor", ignoreArmor);
|
||||
nbt.setTag("cont_" + index, me);
|
||||
}
|
||||
|
||||
|
||||
public static ContaminationEffect load(NBTTagCompound nbt, int index) {
|
||||
NBTTagCompound me = (NBTTagCompound) nbt.getTag("cont_" + index);
|
||||
float maxRad = me.getFloat("maxRad");
|
||||
int maxTime = nbt.getInteger("maxTime");
|
||||
int time = nbt.getInteger("time");
|
||||
boolean ignoreArmor = nbt.getBoolean("ignoreArmor");
|
||||
|
||||
|
||||
ContaminationEffect effect = new ContaminationEffect(maxRad, maxTime, ignoreArmor);
|
||||
effect.time = time;
|
||||
return effect;
|
||||
|
||||
@ -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;
|
||||
@ -17,68 +18,68 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IExtendedEntityProperties;
|
||||
|
||||
public class HbmPlayerProps implements IExtendedEntityProperties {
|
||||
|
||||
|
||||
public static final String key = "NTM_EXT_PLAYER";
|
||||
public EntityPlayer player;
|
||||
|
||||
|
||||
public boolean hasReceivedBook = false;
|
||||
|
||||
|
||||
public boolean enableHUD = true;
|
||||
public boolean enableBackpack = true;
|
||||
|
||||
|
||||
private boolean[] keysPressed = new boolean[EnumKeybind.values().length];
|
||||
|
||||
|
||||
public boolean dashActivated = true;
|
||||
|
||||
|
||||
public static final int dashCooldownLength = 5;
|
||||
public int dashCooldown = 0;
|
||||
|
||||
|
||||
public int totalDashCount = 0;
|
||||
public int stamina = 0;
|
||||
|
||||
|
||||
public static final int plinkCooldownLength = 10;
|
||||
public int plinkCooldown = 0;
|
||||
|
||||
|
||||
public float shield = 0;
|
||||
public float maxShield = 0;
|
||||
public int lastDamage = 0;
|
||||
public static final float shieldCap = 100;
|
||||
|
||||
|
||||
public int reputation;
|
||||
|
||||
|
||||
public boolean isOnLadder = false;
|
||||
|
||||
|
||||
public HbmPlayerProps(EntityPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
|
||||
public static HbmPlayerProps registerData(EntityPlayer player) {
|
||||
player.registerExtendedProperties(key, new HbmPlayerProps(player));
|
||||
return (HbmPlayerProps) player.getExtendedProperties(key);
|
||||
}
|
||||
|
||||
|
||||
public static HbmPlayerProps getData(EntityPlayer player) {
|
||||
HbmPlayerProps props = (HbmPlayerProps) player.getExtendedProperties(key);
|
||||
return props != null ? props : registerData(player);
|
||||
}
|
||||
|
||||
|
||||
public boolean getKeyPressed(EnumKeybind key) {
|
||||
return keysPressed[key.ordinal()];
|
||||
}
|
||||
|
||||
|
||||
public boolean isJetpackActive() {
|
||||
return this.enableBackpack && getKeyPressed(EnumKeybind.JETPACK);
|
||||
}
|
||||
|
||||
|
||||
public void setKeyPressed(EnumKeybind key, boolean pressed) {
|
||||
|
||||
|
||||
if(!getKeyPressed(key) && pressed) {
|
||||
|
||||
|
||||
if(key == EnumKeybind.TOGGLE_JETPACK) {
|
||||
|
||||
|
||||
if(!player.worldObj.isRemote) {
|
||||
this.enableBackpack = !this.enableBackpack;
|
||||
|
||||
|
||||
if(this.enableBackpack)
|
||||
MainRegistry.proxy.displayTooltip(EnumChatFormatting.GREEN + "Jetpack ON", MainRegistry.proxy.ID_JETPACK);
|
||||
else
|
||||
@ -86,19 +87,19 @@ public class HbmPlayerProps implements IExtendedEntityProperties {
|
||||
}
|
||||
}
|
||||
if(key == EnumKeybind.TOGGLE_HEAD) {
|
||||
|
||||
|
||||
if(!player.worldObj.isRemote) {
|
||||
this.enableHUD = !this.enableHUD;
|
||||
|
||||
|
||||
if(this.enableHUD)
|
||||
MainRegistry.proxy.displayTooltip(EnumChatFormatting.GREEN + "HUD ON", MainRegistry.proxy.ID_HUD);
|
||||
else
|
||||
MainRegistry.proxy.displayTooltip(EnumChatFormatting.RED + "HUD OFF", MainRegistry.proxy.ID_HUD);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(key == EnumKeybind.TRAIN) {
|
||||
|
||||
|
||||
if(!this.player.worldObj.isRemote) {
|
||||
|
||||
if(player.ridingEntity != null && player.ridingEntity instanceof EntityRailCarBase && player.ridingEntity instanceof IGUIProvider) {
|
||||
@ -107,50 +108,50 @@ public class HbmPlayerProps implements IExtendedEntityProperties {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
keysPressed[key.ordinal()] = pressed;
|
||||
}
|
||||
|
||||
|
||||
public void setDashCooldown(int cooldown) {
|
||||
this.dashCooldown = cooldown;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
public int getDashCooldown() {
|
||||
return this.dashCooldown;
|
||||
}
|
||||
|
||||
|
||||
public void setStamina(int stamina) {
|
||||
this.stamina = stamina;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
public int getStamina() {
|
||||
return this.stamina;
|
||||
}
|
||||
|
||||
|
||||
public void setDashCount(int count) {
|
||||
this.totalDashCount = count;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
public int getDashCount() {
|
||||
return this.totalDashCount;
|
||||
}
|
||||
|
||||
|
||||
public static void plink(EntityPlayer player, String sound, float volume, float pitch) {
|
||||
HbmPlayerProps props = HbmPlayerProps.getData(player);
|
||||
|
||||
|
||||
if(props.plinkCooldown <= 0) {
|
||||
player.worldObj.playSoundAtEntity(player, sound, volume, pitch);
|
||||
props.plinkCooldown = props.plinkCooldownLength;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public float getEffectiveMaxShield() {
|
||||
|
||||
|
||||
float max = this.maxShield;
|
||||
|
||||
|
||||
if(player.getCurrentArmor(2) != null) {
|
||||
ItemStack[] mods = ArmorModHandler.pryMods(player.getCurrentArmor(2));
|
||||
if(mods[ArmorModHandler.kevlar] != null && mods[ArmorModHandler.kevlar].getItem() instanceof ItemModShield) {
|
||||
@ -158,16 +159,39 @@ public class HbmPlayerProps implements IExtendedEntityProperties {
|
||||
max += mod.shield;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
||||
|
||||
NBTTagCompound props = new NBTTagCompound();
|
||||
|
||||
props.setBoolean("hasReceivedBook", hasReceivedBook);
|
||||
@ -177,15 +201,16 @@ public class HbmPlayerProps implements IExtendedEntityProperties {
|
||||
props.setBoolean("enableHUD", enableHUD);
|
||||
props.setInteger("reputation", reputation);
|
||||
props.setBoolean("isOnLadder", isOnLadder);
|
||||
|
||||
|
||||
nbt.setTag("HbmPlayerProps", props);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void loadNBTData(NBTTagCompound nbt) {
|
||||
|
||||
|
||||
NBTTagCompound props = (NBTTagCompound) nbt.getTag("HbmPlayerProps");
|
||||
|
||||
|
||||
if(props != null) {
|
||||
this.hasReceivedBook = props.getBoolean("hasReceivedBook");
|
||||
this.shield = props.getFloat("shield");
|
||||
|
||||
@ -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;
|
||||
@ -55,12 +57,12 @@ import net.minecraft.world.biome.BiomeGenBase;
|
||||
public class EntityEffectHandler {
|
||||
|
||||
public static void onUpdate(EntityLivingBase entity) {
|
||||
|
||||
|
||||
if(entity.ticksExisted % 20 == 0) {
|
||||
HbmLivingProps.setRadBuf(entity, HbmLivingProps.getRadEnv(entity));
|
||||
HbmLivingProps.setRadEnv(entity, 0);
|
||||
}
|
||||
|
||||
|
||||
if(entity instanceof EntityPlayer && entity == MainRegistry.proxy.me()) {
|
||||
EntityPlayer player = MainRegistry.proxy.me();
|
||||
if(player != null) {
|
||||
@ -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,16 +87,16 @@ 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) {
|
||||
int timer = HbmLivingProps.getTimer(entity);
|
||||
if(timer > 0) {
|
||||
HbmLivingProps.setTimer(entity, timer - 1);
|
||||
|
||||
|
||||
if(timer == 1) {
|
||||
ExplosionNukeSmall.explode(entity.worldObj, entity.posX, entity.posY, entity.posZ, ExplosionNukeSmall.PARAMS_MEDIUM);
|
||||
}
|
||||
@ -103,15 +105,15 @@ public class EntityEffectHandler {
|
||||
if((GeneralConfig.enable528 && GeneralConfig.enable528NetherBurn) && entity instanceof EntityPlayer && !entity.isImmuneToFire() && entity.worldObj.provider.isHellWorld) {
|
||||
entity.setFire(5);
|
||||
}
|
||||
|
||||
|
||||
BiomeGenBase biome = entity.worldObj.getBiomeGenForCoords((int) Math.floor(entity.posX), (int) Math.floor(entity.posZ));
|
||||
float radiation = 0;
|
||||
if(biome == BiomeGenCraterBase.craterOuterBiome) radiation = WorldConfig.craterBiomeOuterRad;
|
||||
if(biome == BiomeGenCraterBase.craterBiome) radiation = WorldConfig.craterBiomeRad;
|
||||
if(biome == BiomeGenCraterBase.craterInnerBiome) radiation = WorldConfig.craterBiomeInnerRad;
|
||||
|
||||
|
||||
if(entity.isWet()) radiation *= WorldConfig.craterBiomeWaterMult;
|
||||
|
||||
|
||||
if(radiation > 0) {
|
||||
ContaminationUtil.contaminate(entity, HazardType.RADIATION, ContaminationType.CREATIVE, radiation / 20F);
|
||||
}
|
||||
@ -128,14 +130,14 @@ public class EntityEffectHandler {
|
||||
|
||||
handleDashing(entity);
|
||||
handlePlinking(entity);
|
||||
|
||||
|
||||
if(entity instanceof EntityPlayer) handleFauxLadder((EntityPlayer) entity);
|
||||
}
|
||||
|
||||
|
||||
private static void handleFauxLadder(EntityPlayer player) {
|
||||
|
||||
|
||||
HbmPlayerProps props = HbmPlayerProps.getData(player);
|
||||
|
||||
|
||||
if(props.isOnLadder) {
|
||||
float f5 = 0.15F;
|
||||
|
||||
@ -170,67 +172,67 @@ public class EntityEffectHandler {
|
||||
}
|
||||
|
||||
props.isOnLadder = false;
|
||||
|
||||
|
||||
if(!player.worldObj.isRemote) ArmorUtil.resetFlightTime(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void handleContamination(EntityLivingBase entity) {
|
||||
|
||||
|
||||
if(entity.worldObj.isRemote)
|
||||
return;
|
||||
|
||||
|
||||
List<ContaminationEffect> contamination = HbmLivingProps.getCont(entity);
|
||||
List<ContaminationEffect> rem = new ArrayList();
|
||||
|
||||
|
||||
for(ContaminationEffect con : contamination) {
|
||||
ContaminationUtil.contaminate(entity, HazardType.RADIATION, con.ignoreArmor ? ContaminationType.RAD_BYPASS : ContaminationType.CREATIVE, con.getRad());
|
||||
|
||||
|
||||
con.time--;
|
||||
|
||||
|
||||
if(con.time <= 0)
|
||||
rem.add(con);
|
||||
}
|
||||
|
||||
|
||||
contamination.removeAll(rem);
|
||||
}
|
||||
|
||||
|
||||
private static void handleRadiation(EntityLivingBase entity) {
|
||||
|
||||
|
||||
World world = entity.worldObj;
|
||||
|
||||
|
||||
if(!world.isRemote) {
|
||||
|
||||
|
||||
if(ContaminationUtil.isRadImmune(entity))
|
||||
return;
|
||||
|
||||
|
||||
int ix = (int)MathHelper.floor_double(entity.posX);
|
||||
int iy = (int)MathHelper.floor_double(entity.posY);
|
||||
int iz = (int)MathHelper.floor_double(entity.posZ);
|
||||
|
||||
|
||||
float rad = ChunkRadiationManager.proxy.getRadiation(world, ix, iy, iz);
|
||||
|
||||
|
||||
if(world.provider.isHellWorld && RadiationConfig.hellRad > 0 && rad < RadiationConfig.hellRad)
|
||||
rad = (float) RadiationConfig.hellRad;
|
||||
|
||||
|
||||
if(rad > 0) {
|
||||
ContaminationUtil.contaminate(entity, HazardType.RADIATION, ContaminationType.CREATIVE, rad / 20F);
|
||||
}
|
||||
|
||||
|
||||
if(entity.worldObj.isRaining() && BombConfig.cont > 0 && AuxSavedData.getThunder(entity.worldObj) > 0 && entity.worldObj.canBlockSeeTheSky(ix, iy, iz)) {
|
||||
ContaminationUtil.contaminate(entity, HazardType.RADIATION, ContaminationType.CREATIVE, BombConfig.cont * 0.0005F);
|
||||
}
|
||||
|
||||
|
||||
if(entity instanceof EntityPlayer && ((EntityPlayer)entity).capabilities.isCreativeMode)
|
||||
return;
|
||||
|
||||
|
||||
Random rand = new Random(entity.getEntityId());
|
||||
|
||||
int r600 = rand.nextInt(600);
|
||||
int r1200 = rand.nextInt(1200);
|
||||
|
||||
|
||||
if(HbmLivingProps.getRadiation(entity) > 600) {
|
||||
|
||||
|
||||
if((world.getTotalWorldTime() + r600) % 600 < 20 && canVomit(entity)) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setString("type", "vomit");
|
||||
@ -238,44 +240,44 @@ public class EntityEffectHandler {
|
||||
nbt.setInteger("count", 25);
|
||||
nbt.setInteger("entity", entity.getEntityId());
|
||||
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(nbt, 0, 0, 0), new TargetPoint(entity.dimension, entity.posX, entity.posY, entity.posZ, 25));
|
||||
|
||||
|
||||
if((world.getTotalWorldTime() + r600) % 600 == 1) {
|
||||
world.playSoundEffect(ix, iy, iz, "hbm:player.vomit", 1.0F, 1.0F);
|
||||
entity.addPotionEffect(new PotionEffect(Potion.hunger.id, 60, 19));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else if(HbmLivingProps.getRadiation(entity) > 200 && (world.getTotalWorldTime() + r1200) % 1200 < 20 && canVomit(entity)) {
|
||||
|
||||
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setString("type", "vomit");
|
||||
nbt.setString("mode", "normal");
|
||||
nbt.setInteger("count", 15);
|
||||
nbt.setInteger("entity", entity.getEntityId());
|
||||
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(nbt, 0, 0, 0), new TargetPoint(entity.dimension, entity.posX, entity.posY, entity.posZ, 25));
|
||||
|
||||
|
||||
if((world.getTotalWorldTime() + r1200) % 1200 == 1) {
|
||||
world.playSoundEffect(ix, iy, iz, "hbm:player.vomit", 1.0F, 1.0F);
|
||||
entity.addPotionEffect(new PotionEffect(Potion.hunger.id, 60, 19));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(HbmLivingProps.getRadiation(entity) > 900 && (world.getTotalWorldTime() + rand.nextInt(10)) % 10 == 0) {
|
||||
|
||||
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setString("type", "sweat");
|
||||
nbt.setInteger("count", 1);
|
||||
nbt.setInteger("block", Block.getIdFromBlock(Blocks.redstone_block));
|
||||
nbt.setInteger("entity", entity.getEntityId());
|
||||
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(nbt, 0, 0, 0), new TargetPoint(entity.dimension, entity.posX, entity.posY, entity.posZ, 25));
|
||||
|
||||
|
||||
}
|
||||
} else {
|
||||
float radiation = HbmLivingProps.getRadiation(entity);
|
||||
|
||||
|
||||
if(entity instanceof EntityPlayer && radiation > 600) {
|
||||
|
||||
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setString("type", "radiation");
|
||||
nbt.setInteger("count", radiation > 900 ? 4 : radiation > 800 ? 2 : 1);
|
||||
@ -283,20 +285,20 @@ public class EntityEffectHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void handleDigamma(EntityLivingBase entity) {
|
||||
|
||||
|
||||
if(!entity.worldObj.isRemote) {
|
||||
|
||||
|
||||
float digamma = HbmLivingProps.getDigamma(entity);
|
||||
|
||||
|
||||
if(digamma < 0.01F)
|
||||
return;
|
||||
|
||||
|
||||
int chance = Math.max(10 - (int)(digamma), 1);
|
||||
|
||||
|
||||
if(chance == 1 || entity.getRNG().nextInt(chance) == 0) {
|
||||
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setString("type", "sweat");
|
||||
data.setInteger("count", 1);
|
||||
@ -306,41 +308,41 @@ public class EntityEffectHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void handleContagion(EntityLivingBase entity) {
|
||||
|
||||
|
||||
World world = entity.worldObj;
|
||||
|
||||
|
||||
if(!entity.worldObj.isRemote) {
|
||||
|
||||
|
||||
Random rand = entity.getRNG();
|
||||
int minute = 60 * 20;
|
||||
int hour = 60 * minute;
|
||||
|
||||
|
||||
int contagion = HbmLivingProps.getContagion(entity);
|
||||
|
||||
|
||||
if(entity instanceof EntityPlayer) {
|
||||
|
||||
|
||||
EntityPlayer player = (EntityPlayer) entity;
|
||||
int randSlot = rand.nextInt(player.inventory.mainInventory.length);
|
||||
ItemStack stack = player.inventory.getStackInSlot(randSlot);
|
||||
|
||||
|
||||
if(rand.nextInt(100) == 0) {
|
||||
stack = player.inventory.armorItemInSlot(rand.nextInt(4));
|
||||
}
|
||||
|
||||
|
||||
//only affect unstackables (e.g. tools and armor) so that the NBT tag's stack restrictions isn't noticeable
|
||||
if(stack != null && stack.getMaxStackSize() == 1) {
|
||||
|
||||
|
||||
if(contagion > 0) {
|
||||
|
||||
|
||||
if(!stack.hasTagCompound())
|
||||
stack.stackTagCompound = new NBTTagCompound();
|
||||
|
||||
|
||||
stack.stackTagCompound.setBoolean("ntmContagion", true);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
if(stack.hasTagCompound() && stack.stackTagCompound.getBoolean("ntmContagion")) {
|
||||
if(!ArmorUtil.checkForHaz2(player) || !ArmorRegistry.hasProtection(player, 3, HazardClass.BACTERIA)) //liable to change to hazmat 1 at bob's pleasure
|
||||
HbmLivingProps.setContagion(player, 3 * hour);
|
||||
@ -348,19 +350,19 @@ public class EntityEffectHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(contagion > 0) {
|
||||
HbmLivingProps.setContagion(entity, contagion - 1);
|
||||
|
||||
|
||||
//aerial transmission only happens once a second 5 minutes into the contagion
|
||||
if(contagion < (2 * hour + 55 * minute) && contagion % 20 == 0) {
|
||||
|
||||
|
||||
double range = entity.isWet() ? 16D : 2D; //avoid rain, just avoid it
|
||||
|
||||
|
||||
List<Entity> list = world.getEntitiesWithinAABBExcludingEntity(entity, entity.boundingBox.expand(range, range, range));
|
||||
|
||||
|
||||
for(Entity ent : list) {
|
||||
|
||||
|
||||
if(ent instanceof EntityLivingBase) {
|
||||
EntityLivingBase living = (EntityLivingBase) ent;
|
||||
if(HbmLivingProps.getContagion(living) <= 0) {
|
||||
@ -368,39 +370,39 @@ public class EntityEffectHandler {
|
||||
HbmLivingProps.setContagion(living, 3 * hour);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(ent instanceof EntityItem) {
|
||||
ItemStack stack = ((EntityItem)ent).getEntityItem();
|
||||
|
||||
|
||||
if(!stack.hasTagCompound())
|
||||
stack.stackTagCompound = new NBTTagCompound();
|
||||
|
||||
|
||||
stack.stackTagCompound.setBoolean("ntmContagion", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//one hour in, add rare and subtle screen fuckery
|
||||
if(contagion < 2 * hour && rand.nextInt(1000) == 0) {
|
||||
entity.addPotionEffect(new PotionEffect(Potion.confusion.id, 20, 0));
|
||||
}
|
||||
|
||||
|
||||
//two hours in, give 'em the full blast
|
||||
if(contagion < 1 * hour && rand.nextInt(100) == 0) {
|
||||
entity.addPotionEffect(new PotionEffect(Potion.confusion.id, 60, 0));
|
||||
entity.addPotionEffect(new PotionEffect(Potion.weakness.id, 300, 4));
|
||||
}
|
||||
|
||||
|
||||
//T-30 minutes, take damage every 20 seconds
|
||||
if(contagion < 30 * minute && rand.nextInt(400) == 0) {
|
||||
entity.attackEntityFrom(ModDamageSource.mku, 1F);
|
||||
}
|
||||
|
||||
|
||||
//T-5 minutes, take damage every 5 seconds
|
||||
if(contagion < 5 * minute && rand.nextInt(100) == 0) {
|
||||
entity.attackEntityFrom(ModDamageSource.mku, 2F);
|
||||
}
|
||||
|
||||
|
||||
if(contagion < 30 * minute && (contagion + entity.getEntityId()) % 200 < 20 && canVomit(entity)) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setString("type", "vomit");
|
||||
@ -408,11 +410,11 @@ public class EntityEffectHandler {
|
||||
nbt.setInteger("count", 25);
|
||||
nbt.setInteger("entity", entity.getEntityId());
|
||||
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(nbt, 0, 0, 0), new TargetPoint(entity.dimension, entity.posX, entity.posY, entity.posZ, 25));
|
||||
|
||||
|
||||
if((contagion + entity.getEntityId()) % 200 == 19)
|
||||
world.playSoundEffect(entity.posX, entity.posY, entity.posZ, "hbm:player.vomit", 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
|
||||
//end of contagion, drop dead
|
||||
if(contagion == 0) {
|
||||
entity.attackEntityFrom(ModDamageSource.mku, 1000F);
|
||||
@ -420,20 +422,20 @@ public class EntityEffectHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void handleLungDisease(EntityLivingBase entity) {
|
||||
|
||||
|
||||
if(entity.worldObj.isRemote)
|
||||
return;
|
||||
|
||||
|
||||
if(entity instanceof EntityPlayer && ((EntityPlayer) entity).capabilities.isCreativeMode) {
|
||||
HbmLivingProps.setBlackLung(entity, 0);
|
||||
HbmLivingProps.setAsbestos(entity, 0);
|
||||
return;
|
||||
} else {
|
||||
|
||||
|
||||
int bl = HbmLivingProps.getBlackLung(entity);
|
||||
|
||||
|
||||
if(bl > 0 && bl < HbmLivingProps.maxBlacklung * 0.5)
|
||||
HbmLivingProps.setBlackLung(entity, HbmLivingProps.getBlackLung(entity) - 1);
|
||||
}
|
||||
@ -441,13 +443,13 @@ public class EntityEffectHandler {
|
||||
double blacklung = Math.min(HbmLivingProps.getBlackLung(entity), HbmLivingProps.maxBlacklung);
|
||||
double asbestos = Math.min(HbmLivingProps.getAsbestos(entity), HbmLivingProps.maxAsbestos);
|
||||
double soot = PollutionHandler.getPollution(entity.worldObj, (int) Math.floor(entity.posX), (int) Math.floor(entity.posY + entity.getEyeHeight()), (int) Math.floor(entity.posZ), PollutionType.SOOT);
|
||||
|
||||
|
||||
if(!(entity instanceof EntityPlayer)) soot = 0;
|
||||
|
||||
|
||||
if(ArmorRegistry.hasProtection(entity, 3, HazardClass.PARTICLE_COARSE)) soot = 0;
|
||||
|
||||
|
||||
boolean coughs = blacklung / HbmLivingProps.maxBlacklung > 0.25D || asbestos / HbmLivingProps.maxAsbestos > 0.25D || soot > 30;
|
||||
|
||||
|
||||
if(!coughs)
|
||||
return;
|
||||
|
||||
@ -458,25 +460,25 @@ public class EntityEffectHandler {
|
||||
double blacklungDelta = 1D - (blacklung / (double)HbmLivingProps.maxBlacklung);
|
||||
double asbestosDelta = 1D - (asbestos / (double)HbmLivingProps.maxAsbestos);
|
||||
double sootDelta = 1D - Math.min(soot / 100, 1D);
|
||||
|
||||
|
||||
double total = 1 - (blacklungDelta * asbestosDelta);
|
||||
|
||||
|
||||
World world = entity.worldObj;
|
||||
|
||||
|
||||
if(total > 0.75D) {
|
||||
entity.addPotionEffect(new PotionEffect(Potion.weakness.id, 100, 2));
|
||||
}
|
||||
|
||||
|
||||
if(total > 0.95D) {
|
||||
entity.addPotionEffect(new PotionEffect(Potion.confusion.id, 100, 0));
|
||||
}
|
||||
|
||||
|
||||
total = 1 - (blacklungDelta * asbestosDelta * sootDelta);
|
||||
int freq = Math.max((int) (1000 - 950 * total), 20);
|
||||
|
||||
|
||||
if(world.getTotalWorldTime() % freq == entity.getEntityId() % freq) {
|
||||
world.playSoundEffect(entity.posX, entity.posY, entity.posZ, "hbm:player.cough", 1.0F, 1.0F);
|
||||
|
||||
|
||||
if(coughsBlood) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setString("type", "vomit");
|
||||
@ -485,7 +487,7 @@ public class EntityEffectHandler {
|
||||
nbt.setInteger("entity", entity.getEntityId());
|
||||
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(nbt, 0, 0, 0), new TargetPoint(entity.dimension, entity.posX, entity.posY, entity.posZ, 25));
|
||||
}
|
||||
|
||||
|
||||
if(coughsCoal) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setString("type", "vomit");
|
||||
@ -496,23 +498,23 @@ public class EntityEffectHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void handleOil(EntityLivingBase entity) {
|
||||
|
||||
|
||||
if(entity.worldObj.isRemote)
|
||||
return;
|
||||
|
||||
|
||||
int oil = HbmLivingProps.getOil(entity);
|
||||
|
||||
|
||||
if(oil > 0) {
|
||||
|
||||
|
||||
if(entity.isBurning()) {
|
||||
HbmLivingProps.setOil(entity, 0);
|
||||
entity.worldObj.newExplosion(null, entity.posX, entity.posY + entity.height / 2, entity.posZ, 3F, false, true);
|
||||
} else {
|
||||
HbmLivingProps.setOil(entity, oil - 1);
|
||||
}
|
||||
|
||||
|
||||
if(entity.ticksExisted % 5 == 0) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setString("type", "sweat");
|
||||
@ -523,17 +525,17 @@ public class EntityEffectHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void handlePollution(EntityLivingBase entity) {
|
||||
|
||||
|
||||
if(!RadiationConfig.enablePollution) return;
|
||||
|
||||
|
||||
if(RadiationConfig.enablePoison && !ArmorRegistry.hasProtection(entity, 3, HazardClass.GAS_BLISTERING) && entity.ticksExisted % 60 == 0) {
|
||||
|
||||
|
||||
float poison = PollutionHandler.getPollution(entity.worldObj, (int) Math.floor(entity.posX), (int) Math.floor(entity.posY + entity.getEyeHeight()), (int) Math.floor(entity.posZ), PollutionType.POISON);
|
||||
|
||||
|
||||
if(poison > 10) {
|
||||
|
||||
|
||||
if(poison < 25) {
|
||||
entity.addPotionEffect(new PotionEffect(Potion.poison.id, 100, 0));
|
||||
} else if(poison < 50) {
|
||||
@ -543,13 +545,13 @@ public class EntityEffectHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(RadiationConfig.enableLeadPoisoning && !ArmorRegistry.hasProtection(entity, 3, HazardClass.PARTICLE_FINE) && entity.ticksExisted % 60 == 0) {
|
||||
|
||||
|
||||
float poison = PollutionHandler.getPollution(entity.worldObj, (int) Math.floor(entity.posX), (int) Math.floor(entity.posY + entity.getEyeHeight()), (int) Math.floor(entity.posZ), PollutionType.HEAVYMETAL);
|
||||
|
||||
|
||||
if(poison > 25) {
|
||||
|
||||
|
||||
if(poison < 50) {
|
||||
entity.addPotionEffect(new PotionEffect(HbmPotion.lead.id, 100, 0));
|
||||
} else if(poison < 75) {
|
||||
@ -560,23 +562,23 @@ public class EntityEffectHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void handleTemperature(Entity entity) {
|
||||
|
||||
|
||||
if(!(entity instanceof EntityLivingBase)) return;
|
||||
if(entity.worldObj.isRemote) return;
|
||||
|
||||
|
||||
EntityLivingBase living = (EntityLivingBase) entity;
|
||||
int temp = HbmLivingProps.getTemperature(living);
|
||||
|
||||
if(temp < 0) HbmLivingProps.setTemperature(living, temp + Math.min(-temp, 5));
|
||||
if(temp > 0) HbmLivingProps.setTemperature(living, temp - Math.min(temp, 5));
|
||||
|
||||
|
||||
if(HbmLivingProps.isFrozen(living)) {
|
||||
living.motionX = 0;
|
||||
living.motionZ = 0;
|
||||
living.motionY = Math.min(living.motionY, 0);
|
||||
|
||||
|
||||
if(entity.ticksExisted % 5 == 0) {
|
||||
NBTTagCompound nbt0 = new NBTTagCompound();
|
||||
nbt0.setString("type", "sweat");
|
||||
@ -584,7 +586,7 @@ public class EntityEffectHandler {
|
||||
nbt0.setInteger("block", Block.getIdFromBlock(Blocks.snow));
|
||||
nbt0.setInteger("entity", entity.getEntityId());
|
||||
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(nbt0, 0, 0, 0), new TargetPoint(entity.dimension, entity.posX, entity.posY, entity.posZ, 25));
|
||||
|
||||
|
||||
if(entity instanceof EntityPlayerMP) {
|
||||
NBTTagCompound nbt1 = new NBTTagCompound();
|
||||
nbt1.setString("type", "frozen");
|
||||
@ -592,44 +594,44 @@ public class EntityEffectHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(HbmLivingProps.isBurning(living)) {
|
||||
living.setFire(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void handleDashing(Entity entity) {
|
||||
|
||||
|
||||
//AAAAAAAAAAAAAAAAAAAAEEEEEEEEEEEEEEEEEEEE
|
||||
if(entity instanceof EntityPlayer) {
|
||||
EntityPlayer player = (EntityPlayer)entity;
|
||||
|
||||
|
||||
HbmPlayerProps props = HbmPlayerProps.getData(player);
|
||||
|
||||
|
||||
props.setDashCount(0);
|
||||
|
||||
|
||||
ArmorFSB chestplate = null;
|
||||
|
||||
|
||||
int armorDashCount = 0;
|
||||
int armorModDashCount = 0;
|
||||
|
||||
|
||||
if(ArmorFSB.hasFSBArmor(player)) {
|
||||
ItemStack plate = player.inventory.armorInventory[2];
|
||||
|
||||
ItemStack plate = player.inventory.armorInventory[2];
|
||||
|
||||
chestplate = (ArmorFSB)plate.getItem();
|
||||
}
|
||||
|
||||
|
||||
if(chestplate != null)
|
||||
armorDashCount = chestplate.dashCount;
|
||||
|
||||
|
||||
for(int armorSlot = 0; armorSlot < 4; armorSlot++) {
|
||||
ItemStack armorStack = player.inventory.armorInventory[armorSlot];
|
||||
|
||||
|
||||
if(armorStack != null && armorStack.getItem() instanceof ItemArmor) {
|
||||
|
||||
|
||||
for(int modSlot = 0; modSlot < 8; modSlot++) {
|
||||
ItemStack mod = ArmorModHandler.pryMods(armorStack)[modSlot];
|
||||
|
||||
|
||||
if(mod != null && mod.getItem() instanceof IArmorModDash) {
|
||||
int count = ((IArmorModDash)mod.getItem()).getDashes();
|
||||
armorModDashCount += count;
|
||||
@ -637,24 +639,24 @@ public class EntityEffectHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int dashCount = armorDashCount + armorModDashCount;
|
||||
|
||||
|
||||
boolean dashActivated = props.getKeyPressed(EnumKeybind.DASH);
|
||||
|
||||
|
||||
if(dashCount * 30 < props.getStamina())
|
||||
props.setStamina(dashCount * 30);
|
||||
|
||||
|
||||
if(dashCount > 0) {
|
||||
|
||||
int perDash = 30;
|
||||
|
||||
|
||||
props.setDashCount(dashCount);
|
||||
|
||||
|
||||
int stamina = props.getStamina();
|
||||
|
||||
|
||||
if(props.getDashCooldown() <= 0) {
|
||||
|
||||
|
||||
if(dashActivated && stamina >= perDash) {
|
||||
|
||||
Vec3 lookingIn = player.getLookVec();
|
||||
@ -663,7 +665,7 @@ public class EntityEffectHandler {
|
||||
|
||||
int forward = (int) Math.signum(player.moveForward);
|
||||
int strafe = (int) Math.signum(player.moveStrafing);
|
||||
|
||||
|
||||
if(forward == 0 && strafe == 0)
|
||||
forward = 1;
|
||||
|
||||
@ -671,42 +673,42 @@ public class EntityEffectHandler {
|
||||
player.motionY = 0;
|
||||
player.fallDistance = 0F;
|
||||
player.playSound("hbm:weapon.rocketFlame", 1.0F, 1.0F);
|
||||
|
||||
|
||||
props.setDashCooldown(HbmPlayerProps.dashCooldownLength);
|
||||
stamina -= perDash;
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
props.setDashCooldown(props.getDashCooldown() - 1);
|
||||
props.setKeyPressed(EnumKeybind.DASH, false);
|
||||
}
|
||||
|
||||
|
||||
if(stamina < props.getDashCount() * perDash) {
|
||||
stamina++;
|
||||
|
||||
|
||||
if(stamina % perDash == perDash-1) {
|
||||
|
||||
|
||||
player.playSound("hbm:item.techBoop", 1.0F, (1.0F + ((1F/12F)*(stamina/perDash))));
|
||||
stamina++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
props.setStamina(stamina);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void handlePlinking(Entity entity) {
|
||||
|
||||
|
||||
if(entity instanceof EntityPlayer) {
|
||||
EntityPlayer player = (EntityPlayer)entity;
|
||||
HbmPlayerProps props = HbmPlayerProps.getData(player);
|
||||
|
||||
|
||||
if(props.plinkCooldown > 0)
|
||||
props.plinkCooldown--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static boolean canVomit(Entity e) {
|
||||
if(e.isCreatureType(EnumCreatureType.waterCreature, false)) return false;
|
||||
return true;
|
||||
|
||||
@ -15,28 +15,24 @@ 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) {
|
||||
|
||||
this.buffer = new PacketBuffer(Unpooled.buffer());
|
||||
|
||||
try {
|
||||
buffer.writeNBTTagCompoundToBuffer(nbt);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public ExtPropPacket(ByteBuf buf) {
|
||||
|
||||
this.buffer = Unpooled.buffer();
|
||||
buffer.writeBytes(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
|
||||
|
||||
if (buffer == null) {
|
||||
buffer = new PacketBuffer(Unpooled.buffer());
|
||||
}
|
||||
@ -45,7 +41,7 @@ public class ExtPropPacket implements IMessage {
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
|
||||
|
||||
if (buffer == null) {
|
||||
buffer = new PacketBuffer(Unpooled.buffer());
|
||||
}
|
||||
@ -53,26 +49,22 @@ public class ExtPropPacket implements IMessage {
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<ExtPropPacket, IMessage> {
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IMessage onMessage(ExtPropPacket m, MessageContext ctx) {
|
||||
|
||||
|
||||
if(Minecraft.getMinecraft().theWorld == null)
|
||||
return null;
|
||||
|
||||
try {
|
||||
|
||||
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);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
|
||||
HbmLivingProps props = HbmLivingProps.getData(Minecraft.getMinecraft().thePlayer);
|
||||
HbmPlayerProps pprps = HbmPlayerProps.getData(Minecraft.getMinecraft().thePlayer);
|
||||
|
||||
props.deserialize(buf);
|
||||
pprps.deserialize(buf);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ import net.minecraft.world.World;
|
||||
public class RBMKDials {
|
||||
|
||||
public static final String KEY_SAVE_DIALS = "dialSaveDials";
|
||||
|
||||
|
||||
public static final String KEY_PASSIVE_COOLING = "dialPassiveCooling";
|
||||
public static final String KEY_COLUMN_HEAT_FLOW = "dialColumnHeatFlow";
|
||||
public static final String KEY_FUEL_DIFFUSION_MOD = "dialDiffusionMod";
|
||||
@ -34,10 +34,10 @@ public class RBMKDials {
|
||||
public static final String KEY_MODERATOR_EFFICIENCY = "dialModeratorEfficiency";
|
||||
public static final String KEY_ABSORBER_EFFICIENCY = "dialAbsorberEfficiency";
|
||||
public static final String KEY_REFLECTOR_EFFICIENCY = "dialReflectorEfficiency";
|
||||
|
||||
|
||||
public static void createDials(World world) {
|
||||
GameRules rules = world.getGameRules();
|
||||
|
||||
|
||||
if(!rules.getGameRuleBooleanValue(KEY_SAVE_DIALS)) {
|
||||
rules.setOrCreateGameRule(KEY_PASSIVE_COOLING, "1.0");
|
||||
rules.setOrCreateGameRule(KEY_COLUMN_HEAT_FLOW, "0.2");
|
||||
@ -64,52 +64,52 @@ public class RBMKDials {
|
||||
rules.setOrCreateGameRule(KEY_REFLECTOR_EFFICIENCY, "1.0");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the amount of heat per tick removed from components passively
|
||||
* @param world
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the percentual step size how quickly neighboring component heat equalizes. 1 is instant, 0.5 is in 50% steps, et cetera.
|
||||
* @param world
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a modifier for fuel rod diffusion, i.e. how quickly the core and hull temperatures equalize.
|
||||
* @param world
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the percentual step size how quickly the fuel hull heat and the component heat equalizes. 1 is instant, 0.5 is in 50% steps, et cetera.
|
||||
* @param world
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simple integer that decides how tall the structure is.
|
||||
* @param world
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whether or not scrap entities despawn on their own or remain alive until picked up.
|
||||
* @param world
|
||||
@ -118,88 +118,88 @@ public class RBMKDials {
|
||||
public static boolean getPermaScrap(World world) {
|
||||
return world.getGameRules().getGameRuleBooleanValue(KEY_PERMANENT_SCRAP);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* How many heat units are consumed per mB water used.
|
||||
* @param world
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A multiplier for how quickly the control rods move.
|
||||
* @param world
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A multiplier for how much flux the rods give out.
|
||||
* @param world
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A multiplier for how much flux the rods give out.
|
||||
* @param world
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A multiplier for how high the power surge goes when inserting control rods.
|
||||
* @param world
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simple integer that decides how far the flux of a normal fuel rod reaches.
|
||||
* @param world
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simple integer that decides how far the flux of a ReaSim fuel rod reaches.
|
||||
* @param world
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simple integer that decides how many neutrons are created from ReaSim fuel rods.
|
||||
* @param world
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a modifier for the outgoing flux of individual streams from the ReaSim fuel rod to compensate for the potentially increased stream count.
|
||||
* @param world
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whether or not all components should act like boilers with dedicated in/outlet blocks
|
||||
* @param world
|
||||
@ -208,16 +208,16 @@ public class RBMKDials {
|
||||
public static boolean getReasimBoilers(World world) {
|
||||
return world.getGameRules().getGameRuleBooleanValue(KEY_REASIM_BOILERS) || (GeneralConfig.enable528 && GeneralConfig.enable528ReasimBoilers);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* How much % of the possible steam ends up being produced per tick
|
||||
* @param world
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whether or not fuel columns should initiate a meltdown when overheating
|
||||
* The method is in reverse because the default for older worlds will be 'false'
|
||||
@ -227,7 +227,7 @@ public class RBMKDials {
|
||||
public static boolean getMeltdownsDisabled(World world) {
|
||||
return world.getGameRules().getGameRuleBooleanValue(KEY_DISABLE_MELTDOWNS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whether or not connected pipes and turbines should explode when the reactor undergoes a meltdown.
|
||||
* @param world
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,37 +1,49 @@
|
||||
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);
|
||||
}
|
||||
|
||||
public static double getDoubleMinimum(World world, String rule, double def, double min) {
|
||||
return Math.max(GameRuleHelper.parseDouble(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 MathHelper.clamp_double(GameRuleHelper.parseDouble(world, world.getGameRules().getGameRuleStringValue(rule), def), min, max);
|
||||
}
|
||||
|
||||
public static double parseDouble(String s, double def) {
|
||||
|
||||
public static double getDoubleMinimum(World world, String rule, double def, double 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, world.getGameRules().getGameRuleStringValue(rule), def), min);
|
||||
}
|
||||
|
||||
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);
|
||||
} catch(Exception ex) { }
|
||||
|
||||
|
||||
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);
|
||||
} catch(Exception ex) { }
|
||||
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user