Skip to content

Commit

Permalink
Slight Cleanup for armor event logic (#148)
Browse files Browse the repository at this point in the history
* Slight Cleanup for armor event logic

* Some null checking to silence some warnings
  • Loading branch information
ALongStringOfNumbers authored Sep 15, 2021
1 parent 222b14a commit 1131763
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
34 changes: 11 additions & 23 deletions src/main/java/gregtech/common/EventHandlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,34 +142,22 @@ public static void onEntityLivingFallEvent(LivingFallEvent event) {
final ItemStack FLUIDJET = MetaItems.SEMIFLUID_JETPACK.getStackForm();


if (jet.isItemEqual(JET) || (jet.isItemEqual(ADJET) || (jet.isItemEqual(FLUIDJET))) || armor.isItemEqual(QUARK) || armor.isItemEqual(NANO)) {
} else {
if (!(jet.isItemEqual(JET) || jet.isItemEqual(ADJET) || (jet.isItemEqual(FLUIDJET)) || armor.isItemEqual(QUARK) || armor.isItemEqual(NANO))) {
return;
}
if (jet.isItemEqual(FLUIDJET)) {
event.setCanceled(true);
} else {
if(jet != null) {
ArmorMetaItem<?>.ArmorMetaValueItem armorMetaValue = ((ArmorMetaItem<?>) armor.getItem()).getItem(armor);
ArmorLogicSuite armorLogic = (ArmorLogicSuite) armorMetaValue.getArmorLogic();
IElectricItem item = armor.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if (item == null) return;
int energyCost = (armorLogic.getEnergyPerUse() * Math.round(event.getDistance()));
if (item.getCharge() >= energyCost) {
item.discharge(energyCost, item.getTier(), true, false, false);
event.setCanceled(true);
}
}
else {
ArmorMetaItem<?>.ArmorMetaValueItem armorMetaValue = ((ArmorMetaItem<?>) jet.getItem()).getItem(jet);
ArmorLogicSuite armorLogic = (ArmorLogicSuite) armorMetaValue.getArmorLogic();
IElectricItem item = jet.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if (item == null) return;
int energyCost = (armorLogic.getEnergyPerUse() * Math.round(event.getDistance()));
if (item.getCharge() >= energyCost) {
item.discharge(energyCost, item.getTier(), true, false, false);
event.setCanceled(true);
}
ItemStack armorPiece = jet.isEmpty() ? armor : jet;

ArmorMetaItem<?>.ArmorMetaValueItem armorMetaValue = ((ArmorMetaItem<?>) armorPiece.getItem()).getItem(armorPiece);
ArmorLogicSuite armorLogic = (ArmorLogicSuite) armorMetaValue.getArmorLogic();
IElectricItem item = armorPiece.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if (item == null) return;
int energyCost = (armorLogic.getEnergyPerUse() * Math.round(event.getDistance()));
if (item.getCharge() >= energyCost) {
item.discharge(energyCost, item.getTier(), true, false, false);
event.setCanceled(true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public AdvancedJetpack(int energyPerUse, long capacity, int tier) {
@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack item) {
IElectricItem cont = item.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if(cont == null) {
return;
}
NBTTagCompound data = GTUtility.getOrCreateNbtCompound(item);
boolean hoverMode = data.hasKey("Hover") && data.getBoolean("Hover");
boolean flyEnabled = data.hasKey("FlyMode") && data.getBoolean("FlyMode");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public AdvancedNanoMuscleSuite(int energyPerUse, long capacity, int tier) {
@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack item) {
IElectricItem cont = item.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if(cont == null) {
return;
}
NBTTagCompound data = GTUtility.getOrCreateNbtCompound(item);
boolean hoverMode = data.hasKey("Hover") && data.getBoolean("Hover");
boolean flyEnabled = data.hasKey("FlyMode") && data.getBoolean("FlyMode");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public AdvancedQuarkTechSuite(int energyPerUse, long capacity, int tier) {
@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack item) {
IElectricItem cont = item.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if(cont == null) {
return;
}
NBTTagCompound data = GTUtility.getOrCreateNbtCompound(item);
boolean hoverMode = data.hasKey("Hover") && data.getBoolean("Hover");
boolean flyEnabled = data.hasKey("FlyMode") && data.getBoolean("FlyMode");
Expand Down

0 comments on commit 1131763

Please sign in to comment.