slightly improved contamination code

This commit is contained in:
Boblet 2021-03-29 13:02:22 +02:00
parent fe0ccbbe67
commit 0556bf3e31
3 changed files with 82 additions and 3 deletions

View File

@ -1,5 +1,6 @@
package com.hbm.inventory.gui;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import com.hbm.inventory.container.ContainerFEL;
@ -10,6 +11,7 @@ import com.hbm.tileentity.machine.TileEntityFEL;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
@ -18,6 +20,7 @@ public class GUIFEL extends GuiInfoContainer {
public static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/machine/gui_fel.png");
private TileEntityFEL fel;
private GuiTextField field;
public GUIFEL(InventoryPlayer invPlayer, TileEntityFEL laser) {
super(new ContainerFEL(invPlayer, laser));
@ -27,6 +30,20 @@ public class GUIFEL extends GuiInfoContainer {
this.ySize = 168;
}
@Override
public void initGui() {
super.initGui();
Keyboard.enableRepeatEvents(true);
this.field = new GuiTextField(this.fontRendererObj, guiLeft + 57, guiTop + 57, 29, 12);
this.field.setTextColor(-1);
this.field.setDisabledTextColour(-1);
this.field.setEnableBackgroundDrawing(false);
this.field.setMaxStringLength(3);
this.field.setText(String.valueOf(fel.watts));
}
@Override
public void drawScreen(int mouseX, int mouseY, float f) {
super.drawScreen(mouseX, mouseY, f);
@ -41,6 +58,8 @@ public class GUIFEL extends GuiInfoContainer {
protected void mouseClicked(int x, int y, int i) {
super.mouseClicked(x, y, i);
this.field.mouseClicked(x, y, i);
for(int k = 0; k < 6; k++) {
@ -64,8 +83,13 @@ public class GUIFEL extends GuiInfoContainer {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
if(field.isFocused())
drawTexturedModalRect(guiLeft + 53, guiTop + 53, 210, 4, 34, 16);
int mode = fel.mode;
drawTexturedModalRect(guiLeft + 133, guiTop + 16 + mode * 9, 176, 52 + mode * 9, 18, 9);
this.field.drawTextBox();
}
}

View File

@ -11,6 +11,7 @@ public class TileEntityFEL extends TileEntityMachineBase {
public long power;
public static final long maxPower = 1000000;
public int watts;
public int mode = 0;
public TileEntityFEL() {

View File

@ -4,6 +4,7 @@ import com.hbm.entity.mob.EntityNuclearCreeper;
import com.hbm.entity.mob.EntityQuackos;
import com.hbm.extprop.HbmLivingProps;
import com.hbm.handler.HazmatRegistry;
import com.hbm.lib.ModDamageSource;
import com.hbm.potion.HbmPotion;
import com.hbm.saveddata.RadiationSavedData;
@ -111,9 +112,6 @@ public class ContaminationUtil {
if(!(e instanceof EntityLivingBase))
return;
if(e instanceof IRadiationImmune)
return;
if(e instanceof EntityPlayer && ((EntityPlayer)e).capabilities.isCreativeMode)
return;
@ -236,4 +234,60 @@ public class ContaminationUtil {
player.addChatMessage(new ChatComponentTranslation("digamma.playerHealth").appendSibling(new ChatComponentText(EnumChatFormatting.RED + " " + halflife + "%")).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.LIGHT_PURPLE)));
player.addChatMessage(new ChatComponentTranslation("digamma.playerRes").appendSibling(new ChatComponentText(EnumChatFormatting.BLUE + " " + "N/A")).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.LIGHT_PURPLE)));
}
public static enum HazardType {
MONOXIDE,
RADIATION,
ASBESTOS,
DIGAMMA
}
public static enum ContaminationType {
GAS, //filterable by gas mask
GAS_NON_REACTIVE, //not filterable by gas mask
GOGGLES, //preventable by goggles
FARADAY, //preventable by metal armor
HAZMAT, //preventable by hazmat
HAZMAT2, //preventable by heavy hazmat
DIGAMMA, //preventable by fau armor or stability
DIGAMMA2, //preventable by robes
CREATIVE, //preventable by creative mode
NONE //not preventable
}
public static boolean contaminate(EntityLivingBase entity, HazardType hazard, ContaminationType cont, float amount) {
if(entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer)entity;
switch(cont) {
case GAS: if(ArmorUtil.checkForGasMask(player)) return false; break;
case GAS_NON_REACTIVE: if(ArmorUtil.checkForHaz2(player)) return false; break;
case GOGGLES: if(ArmorUtil.checkForGoggles(player)) return false; break;
case HAZMAT: if(ArmorUtil.checkForHazmat(player)) return false; break;
case HAZMAT2: if(ArmorUtil.checkForHaz2(player)) return false; break;
case DIGAMMA: if(ArmorUtil.checkForDigamma(player)) return false; if(player.isPotionActive(HbmPotion.stability.id)) return false; break;
case DIGAMMA2: break;
}
if(player.capabilities.isCreativeMode && cont != ContaminationType.NONE)
return false;
if(player.ticksExisted < 200)
return false;
}
if(hazard == HazardType.RADIATION && isRadImmune(entity))
return false;
switch(hazard) {
case MONOXIDE: entity.attackEntityFrom(ModDamageSource.monoxide, amount); break;
case RADIATION: HbmLivingProps.incrementRadiation(entity, amount * calculateRadiationMod(entity)); break;
case ASBESTOS: HbmLivingProps.incrementAsbestos(entity, (int)amount); break;
case DIGAMMA: HbmLivingProps.incrementDigamma(entity, amount); break;
}
return true;
}
}