From 9ce7ea0d9e608e4b03b603224799244bca15df39 Mon Sep 17 00:00:00 2001 From: SrdjanV Date: Wed, 7 Dec 2022 15:47:24 +0100 Subject: [PATCH] Fixed another Gas Core sample crash Version Bump --- build.gradle | 2 + gradle.properties | 2 +- .../mixin/MixinEventHandler.java | 101 +++++++++++++++++- .../resources/mixins.tweakedpetroleumgas.json | 2 +- 4 files changed, 104 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 6bb9984..a81b05a 100644 --- a/build.gradle +++ b/build.gradle @@ -28,6 +28,7 @@ configurations { apply { plugin 'net.minecraftforge.gradle' + plugin 'org.spongepowered.mixin' plugin 'java' plugin 'idea' } @@ -157,6 +158,7 @@ dependencies { if (project.use_mixins.toBoolean()) { compileOnly 'zone.rong:mixinbooter:5.0' runtimeOnly 'zone.rong:mixinbooter:5.0' + annotationProcessor "org.spongepowered:mixin:0.8.2:processor" } } diff --git a/gradle.properties b/gradle.properties index 3826634..0b6775a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.daemon = false tweaked_petroleum_version = 1.3.0 tweaked_lib_version = 1.0.0 -mod_version = 1.1.1 +mod_version = 1.1.2 maven_group = srki2k archives_base_name = tweakedpetroleumgas diff --git a/src/main/java/srki2k/tweakedpetroleumgas/mixin/MixinEventHandler.java b/src/main/java/srki2k/tweakedpetroleumgas/mixin/MixinEventHandler.java index 0e7aa0d..df0d223 100644 --- a/src/main/java/srki2k/tweakedpetroleumgas/mixin/MixinEventHandler.java +++ b/src/main/java/srki2k/tweakedpetroleumgas/mixin/MixinEventHandler.java @@ -1,13 +1,26 @@ package srki2k.tweakedpetroleumgas.mixin; +import blusunrize.immersiveengineering.client.ClientProxy; +import blusunrize.immersiveengineering.client.ClientUtils; +import blusunrize.immersiveengineering.common.Config; +import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces; +import blusunrize.immersiveengineering.common.blocks.stone.TileEntityCoresample; import blusunrize.immersiveengineering.common.items.ItemCoresample; import blusunrize.immersiveengineering.common.util.ItemNBTHelper; +import blusunrize.immersiveengineering.common.util.Utils; import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler; import flaxbeard.immersivepetroleum.common.EventHandler; +import flaxbeard.immersivepetroleum.common.entity.EntitySpeedboat; import mekanism.api.gas.Gas; import mekanism.api.gas.GasRegistry; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.RayTraceResult; +import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; @@ -23,7 +36,7 @@ import java.util.Optional; @Mixin(value = EventHandler.class, remap = false) -public class MixinEventHandler { +public abstract class MixinEventHandler { @Inject(method = "handleItemTooltip", cancellable = true, at = @At( value = "INVOKE", @@ -79,4 +92,90 @@ private static void onHandleItemTooltip(ItemTooltipEvent event, CallbackInfo ci) } ci.cancel(); } + + @Inject(method = "renderCoresampleInfo", cancellable = true, at = @At( + value = "INVOKE", + target = "Lblusunrize/immersiveengineering/client/ClientUtils;mc()Lnet/minecraft/client/Minecraft;", + shift = At.Shift.BEFORE, + ordinal = 1)) + private static void onRenderCoresampleInfo(RenderGameOverlayEvent.Post event, CallbackInfo ci) { + EntityPlayer player = ClientUtils.mc().player; + if (ClientUtils.mc().objectMouseOver != null) { + boolean hammer = player.getHeldItem(EnumHand.MAIN_HAND) != null && Utils.isHammer(player.getHeldItem(EnumHand.MAIN_HAND)); + RayTraceResult mop = ClientUtils.mc().objectMouseOver; + int amnt; + if (mop != null && mop.getBlockPos() != null) { + TileEntity tileEntity = player.world.getTileEntity(mop.getBlockPos()); + if (tileEntity instanceof TileEntityCoresample) { + IEBlockInterfaces.IBlockOverlayText overlayBlock = (IEBlockInterfaces.IBlockOverlayText) tileEntity; + String[] text = overlayBlock.getOverlayText(ClientUtils.mc().player, mop, hammer); + boolean useNixie = overlayBlock.useNixieFont(ClientUtils.mc().player, mop); + ItemStack coresample = ((TileEntityCoresample) tileEntity).coresample; + if (ItemNBTHelper.hasKey(coresample, "oil") && text != null && text.length > 0) { + final String resName = ItemNBTHelper.hasKey(coresample, "resType") ? ItemNBTHelper.getString(coresample, "resType") : ""; + amnt = ItemNBTHelper.getInt(coresample, "oil"); + + Optional res = PumpjackHandler.reservoirList.keySet().stream(). + map(reservoirType -> (IReservoirType) reservoirType). + filter(reservoirType -> reservoirType.getName().equals(resName)). + findFirst(); + + String tooltip = null; + if (res.isPresent()) { + IReservoirType reservoirType = res.get(); + 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 = 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 = 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 = 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 = I18n.format("chat.immersivepetroleum.info.coresample.oilRep", reservoirType.getReplenishRate(), fluidName); + } + } + } else { + tooltip = I18n.format("chat.immersivepetroleum.info.coresample.noOil"); + } + + if (tooltip != null) { + FontRenderer font = useNixie ? ClientProxy.nixieFontOptional : ClientUtils.font(); + int col = useNixie && Config.IEConfig.nixietubeFont ? 16750848 : 16777215; + int i = text.length; + font.drawString(tooltip, (float) (event.getResolution().getScaledWidth() / 2 + 8), (float) (event.getResolution().getScaledHeight() / 2 + 8 + i * font.FONT_HEIGHT), col, true); + } + } + } + } else if (mop != null && mop.entityHit != null && mop.entityHit instanceof EntitySpeedboat) { + String[] text = ((EntitySpeedboat) mop.entityHit).getOverlayText(ClientUtils.mc().player, mop); + if (text != null && text.length > 0) { + FontRenderer font = ClientUtils.font(); + int col = 16777215; + int i = 0; + + for (amnt = 0; amnt < text.length; ++amnt) { + String s = text[amnt]; + if (s != null) { + font.drawString(s, (float) (event.getResolution().getScaledWidth() / 2 + 8), (float) (event.getResolution().getScaledHeight() / 2 + 8 + i++ * font.FONT_HEIGHT), col, true); + } + } + } + } + } + ci.cancel(); + } + } diff --git a/src/main/resources/mixins.tweakedpetroleumgas.json b/src/main/resources/mixins.tweakedpetroleumgas.json index 4d097bc..a425c2a 100644 --- a/src/main/resources/mixins.tweakedpetroleumgas.json +++ b/src/main/resources/mixins.tweakedpetroleumgas.json @@ -3,11 +3,11 @@ "package": "srki2k.tweakedpetroleumgas.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ - "MixinEventHandler", "MixinReservoirType", "MixinTileEntityPumpjack" ], "client": [ + "MixinEventHandler", "MixinClientProxy" ], "server": []