Skip to content

Commit

Permalink
Fixed Gas Core sample crash
Browse files Browse the repository at this point in the history
Version Bump
  • Loading branch information
Srdjan-V committed Dec 6, 2022
1 parent 691decf commit cd0cdeb
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 3 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ minecraft {
}
runs {
client {
workingDirectory project.file('run/client')
workingDirectory project.file('run')
if (project.use_coremod.toBoolean()) {
jvmArg '-Dfml.coreMods.load=' + coremod_plugin_class_name
}
Expand All @@ -78,7 +78,7 @@ minecraft {
}

server {
workingDirectory project.file('run/server')
workingDirectory project.file('run')
if (project.use_coremod.toBoolean()) {
jvmArg '-Dfml.coreMods.load=' + coremod_plugin_class_name
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.daemon = false
tweaked_petroleum_version = 1.3.0
tweaked_lib_version = 1.0.0

mod_version = 1.1.0
mod_version = 1.1.1
maven_group = srki2k
archives_base_name = tweakedpetroleumgas

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package srki2k.tweakedpetroleumgas.mixin;

import blusunrize.immersiveengineering.common.items.ItemCoresample;
import blusunrize.immersiveengineering.common.util.ItemNBTHelper;
import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler;
import flaxbeard.immersivepetroleum.common.EventHandler;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import srki2k.tweakedpetroleum.api.crafting.TweakedPumpjackHandler;
import srki2k.tweakedpetroleum.api.ihelpers.IReservoirType;

import java.text.DecimalFormat;
import java.util.List;
import java.util.Optional;

@Mixin(value = EventHandler.class, remap = false)
public class MixinEventHandler {

@Inject(method = "handleItemTooltip", cancellable = true, at = @At(
value = "INVOKE",
target = "Lnet/minecraftforge/event/entity/player/ItemTooltipEvent;getItemStack()Lnet/minecraft/item/ItemStack;",
shift = At.Shift.BEFORE))
private static void onHandleItemTooltip(ItemTooltipEvent event, CallbackInfo ci) {
ItemStack stack = event.getItemStack();

if (stack.getItem() instanceof ItemCoresample && ItemNBTHelper.hasKey(stack, "oil")) {
final String resName;
if (ItemNBTHelper.hasKey(stack, "resType")) {
resName = ItemNBTHelper.getString(stack, "resType");
} else {
resName = "";
}

Optional<IReservoirType> res = PumpjackHandler.reservoirList.keySet().stream().
map(reservoirType -> (IReservoirType) reservoirType).
filter(reservoirType -> reservoirType.getName().equals(resName)).
findFirst();
List<String> tooltip = event.getToolTip();
if (res.isPresent()) {
IReservoirType reservoirType = res.get();

int amnt = ItemNBTHelper.getInt(stack, "oil");
String fluidName;
if (reservoirType.getReservoirContent() == TweakedPumpjackHandler.ReservoirContent.LIQUID) {
if (amnt > 0) {
int est = amnt / 1000 * 1000;
Fluid fluid = FluidRegistry.getFluid(reservoirType.getStringFluid());
fluidName = net.minecraft.util.text.translation.I18n.translateToLocal(fluid.getUnlocalizedName());
tooltip.add(2, I18n.format("chat.immersivepetroleum.info.coresample.oil", (new DecimalFormat("#,###.##")).format(est), fluidName));
} else if (reservoirType.getReplenishRate() > 0) {
Fluid fluid = FluidRegistry.getFluid(reservoirType.getStringFluid());
fluidName = net.minecraft.util.text.translation.I18n.translateToLocal(fluid.getUnlocalizedName());
tooltip.add(2, I18n.format("chat.immersivepetroleum.info.coresample.oilRep", reservoirType.getReplenishRate(), fluidName));
}
} else if (reservoirType.getReservoirContent() == TweakedPumpjackHandler.ReservoirContent.GAS) {
if (amnt > 0) {
int est = amnt / 1000 * 1000;
Gas g = GasRegistry.getGas(reservoirType.getStringFluid());
fluidName = g.getLocalizedName();
tooltip.add(2, I18n.format("chat.immersivepetroleum.info.coresample.oil", (new DecimalFormat("#,###.##")).format(est), fluidName));
} else if (reservoirType.getReplenishRate() > 0) {
Gas g = GasRegistry.getGas(reservoirType.getStringFluid());
fluidName = g.getLocalizedName();
tooltip.add(2, I18n.format("chat.immersivepetroleum.info.coresample.oilRep", reservoirType.getReplenishRate(), fluidName));
}
}
} else {
tooltip.add(2, I18n.format("chat.immersivepetroleum.info.coresample.noOil"));
}
}
ci.cancel();
}
}
1 change: 1 addition & 0 deletions src/main/resources/mixins.tweakedpetroleumgas.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"package": "srki2k.tweakedpetroleumgas.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinEventHandler",
"MixinReservoirType",
"MixinTileEntityPumpjack"
],
Expand Down

0 comments on commit cd0cdeb

Please sign in to comment.