aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2019-05-12 16:04:15 +1000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2019-05-12 16:04:15 +1000
commitd30f18947a5c5e275ef7f17323ac837939cb0135 (patch)
treea46120eaace0b136e056e55d53add6129d8e877b /src
parent3615baf8ffb7a2efc44d4770da97ce1337f7801e (diff)
downloadGT5-Unofficial-d30f18947a5c5e275ef7f17323ac837939cb0135.tar.gz
GT5-Unofficial-d30f18947a5c5e275ef7f17323ac837939cb0135.tar.bz2
GT5-Unofficial-d30f18947a5c5e275ef7f17323ac837939cb0135.zip
% More work on Advanced Mufflers.
Diffstat (limited to 'src')
-rw-r--r--src/Java/gtPlusPlus/core/slots/SlotAirFilter.java30
-rw-r--r--src/Java/gtPlusPlus/core/util/math/MathUtils.java9
-rw-r--r--src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java9
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_Hatch_Muffler_Advanced.java25
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/gui/GUI_Hatch_Muffler_Advanced.java22
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java118
6 files changed, 154 insertions, 59 deletions
diff --git a/src/Java/gtPlusPlus/core/slots/SlotAirFilter.java b/src/Java/gtPlusPlus/core/slots/SlotAirFilter.java
new file mode 100644
index 0000000000..92e9bebe21
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/slots/SlotAirFilter.java
@@ -0,0 +1,30 @@
+package gtPlusPlus.core.slots;
+
+import gtPlusPlus.core.item.general.ItemAirFilter;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.ItemStack;
+
+public class SlotAirFilter extends Slot {
+
+ public SlotAirFilter(final IInventory inventory, final int slot, final int x, final int y) {
+ super(inventory, slot, x, y);
+ }
+
+ @Override
+ public boolean isItemValid(final ItemStack itemstack) {
+ if (itemstack == null) {
+ return false;
+ }
+ if (itemstack.getItem() instanceof ItemAirFilter){
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public int getSlotStackLimit() {
+ return 1;
+ }
+
+}
diff --git a/src/Java/gtPlusPlus/core/util/math/MathUtils.java b/src/Java/gtPlusPlus/core/util/math/MathUtils.java
index 3cef3c511f..bda722b47e 100644
--- a/src/Java/gtPlusPlus/core/util/math/MathUtils.java
+++ b/src/Java/gtPlusPlus/core/util/math/MathUtils.java
@@ -7,6 +7,7 @@ import gregtech.api.enums.GT_Values;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.AutoMap;
+import gtPlusPlus.api.objects.data.Pair;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.util.Utils;
@@ -227,7 +228,7 @@ public class MathUtils {
* @param x Value A.
* @return boolean Whether or not it divides evenly.
*/
- public static boolean isNumberEven(final int x){
+ public static boolean isNumberEven(final long x){
if ((x % 2) == 0)
{
return true;
@@ -696,5 +697,11 @@ public class MathUtils {
int aAmount = Math.max(Math.min(i, aMax), aMin);
return aAmount;
}
+
+ public static Pair<Integer, Integer> splitLongIntoIntegers(long aLong){
+ int aIntMaxInLong = (int) Math.min(Integer.MAX_VALUE, Math.floor(aLong/Integer.MAX_VALUE));
+ int aRemainder = (int) (aLong - (aIntMaxInLong * Integer.MAX_VALUE));
+ return new Pair<Integer, Integer>(aIntMaxInLong, aRemainder);
+ }
}
diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
index c86d6ccb83..224d842ba7 100644
--- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
+++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
@@ -318,9 +318,14 @@ public class ReflectionUtils {
/**
* Allows to change the state of an immutable instance. Huh?!?
*/
- public static void setFinalFieldValue(Class<?> clazz, String fieldName, Object newValue) throws Exception {
+ public static void setFinalFieldValue(Class<?> clazz, String fieldName, Object newValue) {
Field nameField = getField(clazz, fieldName);
- setFieldValue_Internal(clazz, nameField, newValue);
+ try {
+ setFieldValue_Internal(clazz, nameField, newValue);
+ }
+ catch (Throwable t) {
+ t.printStackTrace();
+ }
}
@Deprecated
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_Hatch_Muffler_Advanced.java b/src/Java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_Hatch_Muffler_Advanced.java
index 30d0c3dcd6..721fe053ae 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_Hatch_Muffler_Advanced.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_Hatch_Muffler_Advanced.java
@@ -1,13 +1,9 @@
package gtPlusPlus.xmod.gregtech.api.gui;
-import java.util.List;
-
-import net.minecraft.entity.player.InventoryPlayer;
-import net.minecraft.inventory.ICrafting;
-import net.minecraft.inventory.Slot;
import gregtech.api.gui.GT_ContainerMetaTile_Machine;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
-import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler_Adv;
+import gtPlusPlus.core.slots.SlotAirFilter;
+import net.minecraft.entity.player.InventoryPlayer;
public class CONTAINER_Hatch_Muffler_Advanced extends GT_ContainerMetaTile_Machine {
@@ -25,7 +21,7 @@ public class CONTAINER_Hatch_Muffler_Advanced extends GT_ContainerMetaTile_Machi
@Override
public void addSlots(final InventoryPlayer aInventoryPlayer) {
- this.addSlotToContainer(new Slot(this.mTileEntity, 1, 80, 17));
+ this.addSlotToContainer(new SlotAirFilter(this.mTileEntity, 1, 80, 35));
}
@Override
@@ -41,26 +37,15 @@ public class CONTAINER_Hatch_Muffler_Advanced extends GT_ContainerMetaTile_Machi
@Override
public void updateProgressBar(final int id, final int value) {
super.updateProgressBar(id, value);
- switch (id) {
- case 100:
- this.maxEU = value;
- return;
- case 101:
- this.storedEU = value;
- break;
+ switch (id) {
default:
break;
}
}
- @SuppressWarnings("unchecked")
@Override
public void detectAndSendChanges() {
- super.detectAndSendChanges();
- for(final ICrafting crafting : (List<ICrafting>)this.crafters) {
- crafting.sendProgressBarUpdate(this, 100, (int) ((GT_MetaTileEntity_Hatch_Muffler_Adv) this.mTileEntity.getMetaTileEntity()).maxEUStore());
- crafting.sendProgressBarUpdate(this, 101, (int) ((GT_MetaTileEntity_Hatch_Muffler_Adv) this.mTileEntity.getMetaTileEntity()).getEUVar());
- }
+ super.detectAndSendChanges();
}
} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/gui/GUI_Hatch_Muffler_Advanced.java b/src/Java/gtPlusPlus/xmod/gregtech/api/gui/GUI_Hatch_Muffler_Advanced.java
index 7aed0e60e1..4b998f6487 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/api/gui/GUI_Hatch_Muffler_Advanced.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/gui/GUI_Hatch_Muffler_Advanced.java
@@ -1,12 +1,10 @@
package gtPlusPlus.xmod.gregtech.api.gui;
-import net.minecraft.entity.player.InventoryPlayer;
-
import gregtech.api.gui.GT_GUIContainerMetaTile_Machine;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
-
import gtPlusPlus.core.lib.CORE;
+import net.minecraft.entity.player.InventoryPlayer;
public class GUI_Hatch_Muffler_Advanced extends GT_GUIContainerMetaTile_Machine {
@@ -21,18 +19,26 @@ public class GUI_Hatch_Muffler_Advanced extends GT_GUIContainerMetaTile_Machine
@Override
protected void drawGuiContainerForegroundLayer(final int par1, final int par2) {
- this.fontRendererObj.drawString(this.mName, 64, 6, 16448255);
+ this.fontRendererObj.drawString(this.mName, 8, 8, 16448255);
+ /*
+ * ReflectionUtils.setField(this.fontRendererObj, "underlineStyle", true);
+ * ReflectionUtils.setField(this.fontRendererObj, "italicStyle", true);
+ * ReflectionUtils.setField(this.fontRendererObj, "boldStyle", true); boolean
+ * isBold = ReflectionUtils.getField(this.fontRendererObj, "boldStyle");
+ * this.fontRendererObj.drawString("Insert Air Filters - Bold: "+isBold, 8, 18,
+ * 16448255);
+ */
if (this.mContainer != null) {
- this.maxPower = ((CONTAINER_TreeFarmer)this.mContainer).maxEU;
- this.storedPower = ((CONTAINER_TreeFarmer)this.mContainer).storedEU;
+ //this.maxPower = ((CONTAINER_TreeFarmer)this.mContainer).maxEU;
+ //this.storedPower = ((CONTAINER_TreeFarmer)this.mContainer).storedEU;
}
}
@Override
protected void drawGuiContainerBackgroundLayer(final float par1, final int par2, final int par3) {
super.drawGuiContainerBackgroundLayer(par1, par2, par3);
- this.maxPower = ((CONTAINER_TreeFarmer)this.mContainer).maxEU;
- this.storedPower = ((CONTAINER_TreeFarmer)this.mContainer).storedEU;
+ //this.maxPower = ((CONTAINER_TreeFarmer)this.mContainer).maxEU;
+ //this.storedPower = ((CONTAINER_TreeFarmer)this.mContainer).storedEU;
final int x = (this.width - this.xSize) / 2;
final int y = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize);
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java
index 0479914115..4052a5c266 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java
@@ -1,5 +1,6 @@
package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations;
+import gregtech.api.enums.GT_Values;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
@@ -10,6 +11,7 @@ import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.item.general.ItemAirFilter;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils;
+import gtPlusPlus.core.util.reflect.ReflectionUtils;
import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_Hatch_Muffler_Advanced;
import gtPlusPlus.xmod.gregtech.api.gui.GUI_Hatch_Muffler_Advanced;
import gtPlusPlus.xmod.gregtech.common.StaticFields59;
@@ -44,26 +46,30 @@ public class GT_MetaTileEntity_Hatch_Muffler_Adv extends GT_MetaTileEntity_Hatch
public GT_MetaTileEntity_Hatch_Muffler_Adv(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier);
+ ReflectionUtils.setField(this, "mInventory", new ItemStack[1]);
}
public GT_MetaTileEntity_Hatch_Muffler_Adv(String aName, int aTier, String aDescription, ITexture[][][] aTextures) {
super(aName, aTier, aDescription, aTextures);
+ ReflectionUtils.setField(this, "mInventory", new ItemStack[1]);
}
public GT_MetaTileEntity_Hatch_Muffler_Adv(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) {
super(aName, aTier, aDescription[0], aTextures);
+ ReflectionUtils.setField(this, "mInventory", new ItemStack[1]);
}
public String[] getDescription() {
if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) {
String[] mDescArray = StaticFields59.getDescriptionArray(this);
- String[] desc = new String[mDescArray.length + 5];
+ String[] desc = new String[mDescArray.length + 6];
System.arraycopy(mDescArray, 0, desc, 0, mDescArray.length);
desc[mDescArray.length] = "DO NOT OBSTRUCT THE OUTPUT!";
desc[mDescArray.length + 1] = "Requires 3 Air on the exhaust face";
desc[mDescArray.length + 2] = "Requires Air Filters";
- desc[mDescArray.length + 3] = "Reduces Pollution to " + this.calculatePollutionReduction(100) + "%";
- desc[mDescArray.length + 4] = "Recovers " + (105 - this.calculatePollutionReduction(100))
+ desc[mDescArray.length + 3] = "Mufflers require T2 Filters from IV-"+GT_Values.VN[9];
+ desc[mDescArray.length + 4] = "Reduces Pollution to " + this.calculatePollutionReductionForTooltip(100) + "%";
+ desc[mDescArray.length + 5] = "Recovers " + (105 - this.calculatePollutionReductionForTooltip(100))
+ "% of CO2/CO/SO2";
return desc;
}
@@ -81,7 +87,7 @@ public class GT_MetaTileEntity_Hatch_Muffler_Adv extends GT_MetaTileEntity_Hatch
}
public boolean isValidSlot(int aIndex) {
- return false;
+ return aIndex == SLOT_FILTER;
}
public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
@@ -104,7 +110,7 @@ public class GT_MetaTileEntity_Hatch_Muffler_Adv extends GT_MetaTileEntity_Hatch
}
public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) {
- return new GUI_Hatch_Muffler_Advanced(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "machine_Charger.png");
+ return new GUI_Hatch_Muffler_Advanced(aPlayerInventory, aBaseMetaTileEntity, "Advanced Muffler", "machine_Charger.png");
}
private boolean airCheck() {
@@ -119,7 +125,7 @@ public class GT_MetaTileEntity_Hatch_Muffler_Adv extends GT_MetaTileEntity_Hatch
}
public boolean polluteEnvironment() {
- if (airCheck()) {
+ if (airCheck() && damageAirFilter()) {
int aEmission = this.calculatePollutionReduction(10000);
PollutionUtils.addPollution(this.getBaseMetaTileEntity(), aEmission);
//Logger.INFO("Outputting "+aEmission+"gbl");
@@ -130,6 +136,11 @@ public class GT_MetaTileEntity_Hatch_Muffler_Adv extends GT_MetaTileEntity_Hatch
}
}
+
+ public int calculatePollutionReductionForTooltip(int aPollution) {
+ return (int) (aPollution * Math.pow(0.64D, (double) (this.mTier - 1)));
+ }
+
public int calculatePollutionReduction(int aPollution) {
double aVal1 = aPollution * Math.pow(0.64D, (double) (this.mTier - 1));
int aVal2 = (int) aVal1;
@@ -148,21 +159,69 @@ public class GT_MetaTileEntity_Hatch_Muffler_Adv extends GT_MetaTileEntity_Hatch
return false;
}
+ private ItemStack getInventoryStack() {
+ if (this.mInventory != null && this.mInventory.length > 0) {
+ if (this.mInventory.length-1 >= this.SLOT_FILTER) {
+ return this.mInventory[this.SLOT_FILTER];
+ }
+ }
+ return null;
+ }
+
+ private void breakAirFilter() {
+ if (this.mInventory != null && this.mInventory.length > 0) {
+ if (this.mInventory.length-1 >= this.SLOT_FILTER) {
+ Logger.INFO("Breaking Filter");
+ this.mInventory[this.SLOT_FILTER] = null;
+ }
+ }
+ }
+
public boolean hasValidFilter() {
- return isAirFilter(this.mInventory[this.SLOT_FILTER]);
+ return isAirFilter(getInventoryStack());
}
- public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
+ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
+
+ //Logger.INFO("A1");
+
super.onPostTick(aBaseMetaTileEntity, aTick);
- String aParticleName;
- if (hasValidFilter()) {
- aParticleName = "cloud";
- } else {
- aParticleName = "smoke";
+
+ //Logger.INFO("A2");
+
+ String aParticleName;
+ if ((aTick % 2) == 0){
+ aParticleName = "cloud";
}
- if (aBaseMetaTileEntity.isClientSide() && this.getBaseMetaTileEntity().isActive()) {
- this.pollutionParticles(this.getBaseMetaTileEntity().getWorld(), aParticleName);
+ else {
+ aParticleName = "smoke";
+ }
+
+ //Logger.INFO("A3");
+
+ if (aBaseMetaTileEntity.isClientSide()) {
+ //Logger.INFO("B1");
+ if (this.getBaseMetaTileEntity().isActive()) {
+ //Logger.INFO("C1");
+ this.pollutionParticles(this.getBaseMetaTileEntity().getWorld(), aParticleName);
+ }
+ //return;
+ }
+ else {
+ //Logger.INFO("B2");
+ if (this.getInventoryStack() == null) {
+ //Logger.INFO("D1");
+ //Logger.INFO("Empty - "+this.mInventory.length);
+ }
+ else {
+ //Logger.INFO("D2");
+ Logger.INFO("Has Item");
+ }
}
+ //Logger.INFO("A4");
+
+
+
}
public boolean isAirFilter(ItemStack filter){
@@ -170,39 +229,42 @@ public class GT_MetaTileEntity_Hatch_Muffler_Adv extends GT_MetaTileEntity_Hatch
return false;
}
if (filter.getItem() instanceof ItemAirFilter){
- return true;
+
+ if (this.mTier < 5) {
+ return true;
+ }
+ else {
+ if (filter.getItemDamage() == 1) {
+ return true;
+ }
+ }
}
return false;
}
- public boolean damageAirFilter(){
- ItemStack filter = this.mInventory[this.SLOT_FILTER];
+ public boolean damageAirFilter(){
+ ItemStack filter = getInventoryStack();
if (filter == null) {
return false;
}
if (isAirFilter(filter)){
long currentUse = ItemAirFilter.getFilterDamage(filter);
+ Logger.INFO("Filter Damage: "+currentUse);
//Remove broken Filter
- if (filter.getItemDamage() == 0 && currentUse >= 50-1){
- this.mInventory[this.SLOT_FILTER] = null;
+ if ((filter.getItemDamage() == 0 && currentUse >= 50-1) || (filter.getItemDamage() == 1 && currentUse >= 2500-1)){
+ breakAirFilter();
return false;
- }
- else if (filter.getItemDamage() == 1 && currentUse >= 2500-1){
- this.mInventory[this.SLOT_FILTER] = null;
- return false;
- }
+ }
else {
//Do Damage
ItemAirFilter.setFilterDamage(filter, currentUse+1);
- Logger.WARNING("Filter Damage: "+currentUse);
+ Logger.INFO("Filter Damage now: "+currentUse);
return true;
}
}
return false;
}
-
-
public void pollutionParticles(World aWorld, String name) {
float ran1 = CORE.RANDOM.nextFloat();