diff --git a/src/main/java/github/kasuminova/mmce/client/gui/GuiMEGasInputBus.java b/src/main/java/github/kasuminova/mmce/client/gui/GuiMEGasInputBus.java index 779a685a..78fbf2c7 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/GuiMEGasInputBus.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/GuiMEGasInputBus.java @@ -1,19 +1,34 @@ package github.kasuminova.mmce.client.gui; import appeng.client.gui.implementations.GuiUpgradeable; +import appeng.client.gui.widgets.GuiCustomSlot; +import appeng.container.interfaces.IJEIGhostIngredients; import appeng.core.localization.GuiText; +import com.mekeng.github.MekEng; import com.mekeng.github.client.slots.SlotGas; import com.mekeng.github.client.slots.SlotGasTank; +import com.mekeng.github.common.me.data.impl.AEGasStack; import com.mekeng.github.common.me.inventory.IGasInventory; +import com.mekeng.github.network.packet.CGasSlotSync; +import com.mekeng.github.util.Utils; import github.kasuminova.mmce.common.container.ContainerMEGasInputBus; import github.kasuminova.mmce.common.tile.MEGasInputBus; import github.kasuminova.mmce.common.tile.base.MEFluidBus; import hellfirepvp.modularmachinery.ModularMachinery; +import mekanism.api.gas.GasStack; +import mezz.jei.api.gui.IGhostIngredientHandler; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; -public class GuiMEGasInputBus extends GuiUpgradeable { +import javax.annotation.Nonnull; +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class GuiMEGasInputBus extends GuiUpgradeable implements IJEIGhostIngredients { private static final ResourceLocation TEXTURES_INPUT_BUS = new ResourceLocation(ModularMachinery.MODID, "textures/gui/mefluidinputbus.png"); private final MEGasInputBus bus; @@ -54,4 +69,47 @@ public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) { this.mc.getTextureManager().bindTexture(TEXTURES_INPUT_BUS); this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize); } + + // Code adapted from com.mekeng.github.client.gui.GuiUpgradeable, full credits to the original author + public List> getPhantomTargets(Object ingredient) { + GasStack gas = null; + if (ingredient instanceof GasStack) { + gas = (GasStack) ingredient; + } else if (ingredient instanceof ItemStack i) { + gas = Utils.getGasFromItem(i); + } + + if (gas == null) { + return Collections.emptyList(); + } else { + final GasStack imGas = gas; + this.mapTargetSlot.clear(); + List> targets = new ArrayList<>(); + List slots = new ArrayList<>(); + if (!this.getGuiSlots().isEmpty()) { + for (GuiCustomSlot slot : this.getGuiSlots()) { + if (slot instanceof SlotGas) { + slots.add((SlotGas) slot); + } + } + } + + for (final SlotGas slot : slots) { + IGhostIngredientHandler.Target targetItem = new IGhostIngredientHandler.Target<>() { + @Nonnull + public Rectangle getArea() { + return slot.isSlotEnabled() ? new Rectangle(GuiMEGasInputBus.this.getGuiLeft() + slot.xPos(), GuiMEGasInputBus.this.getGuiTop() + slot.yPos(), 16, 16) : new Rectangle(); + } + + public void accept(@Nonnull Object o) { + MekEng.proxy.netHandler.sendToServer(new CGasSlotSync(Collections.singletonMap(slot.getId(), AEGasStack.of(imGas)))); + } + }; + targets.add(targetItem); + this.mapTargetSlot.putIfAbsent(targetItem, slot); + } + + return targets; + } + } } diff --git a/src/main/java/github/kasuminova/mmce/client/gui/GuiMEItemInputBus.java b/src/main/java/github/kasuminova/mmce/client/gui/GuiMEItemInputBus.java index f94c0b24..413632a0 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/GuiMEItemInputBus.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/GuiMEItemInputBus.java @@ -7,8 +7,6 @@ import appeng.core.localization.GuiText; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketInventoryAction; -import appeng.fluids.client.gui.widgets.GuiFluidSlot; -import appeng.fluids.util.AEFluidStack; import appeng.helpers.InventoryAction; import appeng.util.item.AEItemStack; import github.kasuminova.mmce.common.container.ContainerMEItemInputBus; @@ -17,6 +15,9 @@ import hellfirepvp.modularmachinery.ModularMachinery; import hellfirepvp.modularmachinery.client.ClientProxy; import hellfirepvp.modularmachinery.common.util.MiscUtils; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import it.unimi.dsi.fastutil.objects.ObjectLists; import mezz.jei.api.gui.IGhostIngredientHandler; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.renderer.GlStateManager; @@ -26,23 +27,23 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.TextFormatting; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fml.client.config.GuiUtils; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import javax.annotation.Nonnull; -import java.awt.*; +import java.awt.Rectangle; import java.io.IOException; import java.text.NumberFormat; -import java.util.*; +import java.util.ArrayList; import java.util.List; +import java.util.Locale; +import java.util.Map; public class GuiMEItemInputBus extends GuiMEItemBus implements IJEIGhostIngredients { private static final ResourceLocation TEXTURES_INPUT_BUS = new ResourceLocation(ModularMachinery.MODID, "textures/gui/meiteminputbus.png"); - protected final Map, Object> mapTargetSlot = new HashMap<>(); + protected final Map, Object> mapTargetSlot = new Object2ObjectOpenHashMap<>(); private int invActionAmount = 0; public GuiMEItemInputBus(final MEItemInputBus te, final EntityPlayer player) { @@ -225,73 +226,55 @@ protected void renderToolTip(@Nonnull final ItemStack stack, final int x, final // Code adapted from appeng.client.gui.implementations.GuiUpgradeable, full credits to the original author @Override public List> getPhantomTargets(Object ingredient) { - mapTargetSlot.clear(); - - FluidStack fluidStack = null; - ItemStack itemStack = ItemStack.EMPTY; + this.mapTargetSlot.clear(); + if (ingredient instanceof ItemStack itemStack) { + List> targets = new ObjectArrayList<>(); + List slots = new ObjectArrayList<>(); + if (!this.inventorySlots.inventorySlots.isEmpty()) { + for (Slot slot : this.inventorySlots.inventorySlots) { + if (slot instanceof SlotFake && !itemStack.isEmpty()) { + slots.add((IJEITargetSlot) slot); + } + } + } - if (ingredient instanceof ItemStack) { - itemStack = (ItemStack) ingredient; - fluidStack = FluidUtil.getFluidContained(itemStack); - } else if (ingredient instanceof FluidStack) { - fluidStack = (FluidStack) ingredient; - } + for (final IJEITargetSlot slot : slots) { + var targetItem = getObjectTarget(itemStack, slot); + targets.add(targetItem); + this.mapTargetSlot.putIfAbsent(targetItem, slot); + } - if (!(ingredient instanceof ItemStack) && !(ingredient instanceof FluidStack)) { - return Collections.emptyList(); + return targets; + } else { + return ObjectLists.emptyList(); } + } - List> targets = new ArrayList(); - List slots = new ArrayList(); - if (!this.inventorySlots.inventorySlots.isEmpty()) { - for(Slot slot : this.inventorySlots.inventorySlots) { - if (slot instanceof SlotFake && (!itemStack.isEmpty())) { - slots.add((IJEITargetSlot)slot); + private IGhostIngredientHandler.Target getObjectTarget(ItemStack itemStack, IJEITargetSlot slot) { + final GuiMEItemBus g = this; + return new IGhostIngredientHandler.Target<>() { + @Nonnull + public Rectangle getArea() { + if (slot instanceof SlotFake slotFake && slotFake.isSlotEnabled()) { + return new Rectangle(g.getGuiLeft() + slotFake.xPos, g.getGuiTop() + slotFake.yPos, 16, 16); } + return new Rectangle(); } - } - for (IJEITargetSlot slot : slots) { - ItemStack finalItemStack = itemStack; - FluidStack finalFluidStack = fluidStack; - IGhostIngredientHandler.Target targetItem = new IGhostIngredientHandler.Target<>() { - @Nonnull - @Override - public Rectangle getArea() { - if (slot instanceof SlotFake && ((SlotFake) slot).isSlotEnabled()) { - return new Rectangle(getGuiLeft() + ((SlotFake) slot).xPos, getGuiTop() + ((SlotFake) slot).yPos, 16, 16); - } else if (slot instanceof GuiFluidSlot && ((GuiFluidSlot) slot).isSlotEnabled()) { - return new Rectangle(getGuiLeft() + ((GuiFluidSlot) slot).xPos(), getGuiTop() + ((GuiFluidSlot) slot).yPos(), 16, 16); - } - return new Rectangle(); - } - @Override - public void accept(@Nonnull Object ingredient) { - PacketInventoryAction p = null; - try { - if (slot instanceof SlotFake && ((SlotFake) slot).isSlotEnabled()) { - if (finalItemStack.isEmpty() && finalFluidStack != null) { - p = new PacketInventoryAction(InventoryAction.PLACE_JEI_GHOST_ITEM, slot, AEItemStack.fromItemStack(FluidUtil.getFilledBucket(finalFluidStack))); - } else if (!finalItemStack.isEmpty()) { - p = new PacketInventoryAction(InventoryAction.PLACE_JEI_GHOST_ITEM, slot, AEItemStack.fromItemStack(finalItemStack)); - } - } else { - if (finalFluidStack == null) { - return; - } - p = new PacketInventoryAction(InventoryAction.PLACE_JEI_GHOST_ITEM, slot, AEItemStack.fromItemStack(AEFluidStack.fromFluidStack(finalFluidStack).asItemStackRepresentation())); + public void accept(@Nonnull Object ingredient) { + try { + if (slot instanceof SlotFake && ((SlotFake) slot).isSlotEnabled()) { + if (!itemStack.isEmpty()) { + PacketInventoryAction p = new PacketInventoryAction(InventoryAction.PLACE_JEI_GHOST_ITEM, slot, AEItemStack.fromItemStack(itemStack)); + NetworkHandler.instance().sendToServer(p); } - NetworkHandler.instance().sendToServer(p); - - } catch (IOException e) { - e.printStackTrace(); } + } catch (IOException ignored) { + } - }; - targets.add(targetItem); - mapTargetSlot.putIfAbsent(targetItem, slot); - } - return targets; + + } + }; } @Override diff --git a/src/main/java/github/kasuminova/mmce/client/gui/integration/handler/MEInputGhostSlotHandler.java b/src/main/java/github/kasuminova/mmce/client/gui/integration/handler/MEInputGhostSlotHandler.java deleted file mode 100644 index 58879b57..00000000 --- a/src/main/java/github/kasuminova/mmce/client/gui/integration/handler/MEInputGhostSlotHandler.java +++ /dev/null @@ -1,62 +0,0 @@ -package github.kasuminova.mmce.client.gui.integration.handler; - -import appeng.client.gui.AEGuiHandler; -import appeng.container.interfaces.IJEIGhostIngredients; -import appeng.container.slot.IJEITargetSlot; -import github.kasuminova.mmce.client.gui.GuiMEItemInputBus; -import mezz.jei.api.gui.IAdvancedGuiHandler; -import mezz.jei.api.gui.IGhostIngredientHandler; -import net.minecraft.client.gui.GuiScreen; -import org.jetbrains.annotations.Nullable; -import org.lwjgl.input.Mouse; - -import java.awt.*; -import java.util.ArrayList; -import java.util.List; - -public class MEInputGhostSlotHandler implements IGhostIngredientHandler, IAdvancedGuiHandler { - - private static final AEGuiHandler aeGuiHandler = new AEGuiHandler(); - - - @Override - public List> getTargets(GuiMEItemInputBus guiMEItemInputBus, I ingredient, boolean doStart) { - ArrayList> targets = new ArrayList<>(); - IJEIGhostIngredients ghostGui = guiMEItemInputBus; - List> phantomTargets = ghostGui.getPhantomTargets(ingredient); - targets.addAll((List>) (Object) phantomTargets); - if (doStart && GuiScreen.isShiftKeyDown() && Mouse.isButtonDown(0)) { - for (Target target : targets) { - if (ghostGui.getFakeSlotTargetMap().get(target) instanceof IJEITargetSlot jeiSlot) { - if (jeiSlot.needAccept()) { - target.accept(ingredient); - break; - } - } - } - } - return targets; - } - - @Override - public void onComplete() { - - } - - @Override - public Class getGuiContainerClass() { - return GuiMEItemInputBus.class; - } - - @Nullable - @Override - public List getGuiExtraAreas(GuiMEItemInputBus guiContainer) { - return guiContainer.getJEIExclusionArea(); - } - - @Nullable - @Override - public Object getIngredientUnderMouse(GuiMEItemInputBus guiContainer, int mouseX, int mouseY) { - return aeGuiHandler.getIngredientUnderMouse(guiContainer, mouseX, mouseY); - } -} diff --git a/src/main/java/github/kasuminova/mmce/common/container/handler/MEInputRecipeTransferHandler.java b/src/main/java/github/kasuminova/mmce/common/container/handler/MEInputRecipeTransferHandler.java index 01afc9f9..39c5c9db 100644 --- a/src/main/java/github/kasuminova/mmce/common/container/handler/MEInputRecipeTransferHandler.java +++ b/src/main/java/github/kasuminova/mmce/common/container/handler/MEInputRecipeTransferHandler.java @@ -10,6 +10,7 @@ import mezz.jei.transfer.RecipeTransferErrorInternal; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -17,6 +18,7 @@ public class MEInputRecipeTransferHandler implements IRecipeTransferHandler { + @NotNull @Override public Class getContainerClass() { return ContainerMEItemInputBus.class; @@ -24,7 +26,7 @@ public Class getContainerClass() { @Nullable @Override - public IRecipeTransferError transferRecipe(ContainerMEItemInputBus containerMEItemInputBus, IRecipeLayout recipeLayout, EntityPlayer entityPlayer, boolean maxTransfer, boolean doTransfer) { + public IRecipeTransferError transferRecipe(@NotNull ContainerMEItemInputBus containerMEItemInputBus, IRecipeLayout recipeLayout, @NotNull EntityPlayer entityPlayer, boolean maxTransfer, boolean doTransfer) { final String recipeType = recipeLayout.getRecipeCategory().getUid(); // MM recipes are identified by this prefix diff --git a/src/main/java/github/kasuminova/mmce/common/network/PktMEInputBusRecipeTransfer.java b/src/main/java/github/kasuminova/mmce/common/network/PktMEInputBusRecipeTransfer.java index ec866827..c7e99edb 100644 --- a/src/main/java/github/kasuminova/mmce/common/network/PktMEInputBusRecipeTransfer.java +++ b/src/main/java/github/kasuminova/mmce/common/network/PktMEInputBusRecipeTransfer.java @@ -20,12 +20,12 @@ public class PktMEInputBusRecipeTransfer implements IMessage, IMessageHandler { - private ArrayList inputs; + private List inputs; public PktMEInputBusRecipeTransfer() { } - public PktMEInputBusRecipeTransfer(ArrayList inputs) { + public PktMEInputBusRecipeTransfer(List inputs) { this.inputs = inputs; } @@ -60,20 +60,29 @@ public void toBytes(ByteBuf buf) { public IMessage onMessage(PktMEInputBusRecipeTransfer message, MessageContext ctx) { final EntityPlayerMP player = ctx.getServerHandler().player; final Container container = player.openContainer; - ArrayList inputs = message.inputs; + List inputs = message.inputs; List inventorySlots = container.inventorySlots; - ext: for (ItemStack input : inputs) { - for (Slot slot : inventorySlots) { - if (slot instanceof SlotFake slotFake) { - if (!slotFake.getHasStack()) { - slotFake.putStack(input.copy()); - continue ext; - } - } - } + var slot = getAvailableSlot(input, inventorySlots); + if (slot != null) + slot.putStack(input.copy()); } return null; } + + private SlotFake getAvailableSlot(ItemStack stack, List slots) { + SlotFake emptySlot = null; + for (Slot slot : slots) { + if (slot instanceof SlotFake slotFake) { + var item = slotFake.getStack(); + if (item.isEmpty()) { + if (emptySlot == null) emptySlot = slotFake; + } else if (ItemStack.areItemStacksEqual(item, stack)) { + return null; + } + } + } + return emptySlot; + } } diff --git a/src/main/java/github/kasuminova/mmce/common/tile/MEPatternMirrorImage.java b/src/main/java/github/kasuminova/mmce/common/tile/MEPatternMirrorImage.java index e6c43f10..312f3203 100644 --- a/src/main/java/github/kasuminova/mmce/common/tile/MEPatternMirrorImage.java +++ b/src/main/java/github/kasuminova/mmce/common/tile/MEPatternMirrorImage.java @@ -11,6 +11,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.WorldServer; import javax.annotation.Nullable; @@ -26,7 +27,7 @@ public MEPatternMirrorImage() { @Nullable @Override public MachineComponent provideComponent() { - if (providerPos != null) { + if (!this.world.isRemote && providerPos != null && ((WorldServer) this.world).getChunkProvider().chunkExists(providerPos.getX() >> 4, providerPos.getZ() >> 4)) { TileEntity tileEntity = this.world.getTileEntity(providerPos); if (tileEntity instanceof MEPatternProvider) { return new MachineComponent<>(IOType.INPUT) { diff --git a/src/main/java/github/kasuminova/mmce/common/world/MachineComponentManager.java b/src/main/java/github/kasuminova/mmce/common/world/MachineComponentManager.java index 29620ccc..a754c5b7 100644 --- a/src/main/java/github/kasuminova/mmce/common/world/MachineComponentManager.java +++ b/src/main/java/github/kasuminova/mmce/common/world/MachineComponentManager.java @@ -1,6 +1,7 @@ package github.kasuminova.mmce.common.world; import com.github.bsideup.jabel.Desugar; +import com.mojang.realmsclient.util.Pair; import github.kasuminova.mmce.common.tile.MEPatternMirrorImage; import github.kasuminova.mmce.common.tile.MEPatternProvider; import github.kasuminova.mmce.common.util.concurrent.ExecuteGroup; @@ -27,7 +28,7 @@ private MachineComponentManager() { } @Optional.Method(modid = "appliedenergistics2") - private static Object[] getResult(TileEntity component, World world) { + private static Pair getResult(TileEntity component, World world) { BlockPos pos = component.getPos(); TileEntity te = component; @@ -40,7 +41,7 @@ private static Object[] getResult(TileEntity component, World world) { } } } - return new Object[]{pos, te}; + return Pair.of(pos, te); } public void addWorld(World world) { @@ -64,9 +65,9 @@ public void checkComponentShared(TileEntity component, TileMultiblockMachineCont TileEntity te; if (Loader.isModLoaded("appliedenergistics2")) { - Object[] result = getResult(component, world); - pos = (BlockPos) result[0]; - te = (TileEntity) result[1]; + Pair result = getResult(component, world); + pos = result.first(); + te = result.second(); } else { te = component; pos = component.getPos(); @@ -109,9 +110,9 @@ public void removeOwner(TileEntity component, TileMultiblockMachineController ct TileEntity te; if (Loader.isModLoaded("appliedenergistics2")) { - Object[] result = getResult(component, world); - pos = (BlockPos) result[0]; - te = (TileEntity) result[1]; + Pair result = getResult(component, world); + pos = result.first(); + te = result.second(); } else { te = component; pos = component.getPos(); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/ModIntegrationJEI.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/ModIntegrationJEI.java index 8fcf21b9..537705a0 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/ModIntegrationJEI.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/ModIntegrationJEI.java @@ -9,8 +9,6 @@ package hellfirepvp.modularmachinery.common.integration; import com.google.common.collect.Lists; -import github.kasuminova.mmce.client.gui.GuiMEItemInputBus; -import github.kasuminova.mmce.client.gui.integration.handler.MEInputGhostSlotHandler; import github.kasuminova.mmce.common.container.handler.MEInputRecipeTransferHandler; import hellfirepvp.modularmachinery.ModularMachinery; import hellfirepvp.modularmachinery.common.base.Mods; @@ -50,6 +48,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.Optional; +import org.jetbrains.annotations.NotNull; import java.lang.reflect.Field; import java.util.HashMap; @@ -159,7 +158,7 @@ public void registerItemSubtypes(ISubtypeRegistry subtypeRegistry) { */ @Override @Deprecated - public void registerIngredients(IModIngredientRegistration registry) { + public void registerIngredients(@NotNull IModIngredientRegistration registry) { try { registry.register(() -> HybridFluid.class, Lists.newArrayList(), new HybridStackHelper<>(), new HybridFluidRenderer<>()); if (Mods.MEKANISM.isPresent()) { @@ -207,8 +206,6 @@ public void register(IModRegistry registry) { registry.addRecipeCatalyst(stack, machineCategory); } - registry.addGhostIngredientHandler(GuiMEItemInputBus.class, new MEInputGhostSlotHandler()); - // Only handle MM recipes for (DynamicMachine machine : MachineRegistry.getRegistry()) { String machineCategory = getCategoryStringFor(machine); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java b/src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java index ba71b2fb..918a693e 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java @@ -775,7 +775,7 @@ private void checkAndAddComponents(final BlockPos pos, final BlockPos ctrlPos, f } TileEntity te = getWorld().getTileEntity(realPos); MachineComponent component; - if (!(te instanceof MachineComponentTile)) { + if (!(te instanceof MachineComponentTile mte)) { if (te == null) { return; } @@ -785,7 +785,7 @@ private void checkAndAddComponents(final BlockPos pos, final BlockPos ctrlPos, f } component = proxiedComponent; } else { - component = ((MachineComponentTile) te).provideComponent(); + component = mte.provideComponent(); } ComponentSelectorTag tag = this.foundPattern.getTag(pos); diff --git a/src/main/java/youyihj/mmce/common/item/MachineProjector.java b/src/main/java/youyihj/mmce/common/item/MachineProjector.java index b0406420..954a988d 100644 --- a/src/main/java/youyihj/mmce/common/item/MachineProjector.java +++ b/src/main/java/youyihj/mmce/common/item/MachineProjector.java @@ -18,6 +18,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import org.jetbrains.annotations.NotNull; import youyihj.mmce.common.preview.StructurePreviewHelper; import javax.annotation.Nonnull; @@ -42,16 +43,14 @@ private MachineProjector() { public EnumActionResult onItemUse(@Nonnull EntityPlayer player, World worldIn, @Nonnull BlockPos pos, @Nonnull EnumHand hand, @Nonnull EnumFacing facing, float hitX, float hitY, float hitZ) { IBlockState blockState = worldIn.getBlockState(pos); Block block = blockState.getBlock(); - if (block instanceof BlockController && worldIn.isRemote) { - BlockController controller = (BlockController) block; + if (block instanceof BlockController controller && worldIn.isRemote) { DynamicMachine machine = controller.getParentMachine(); if (machine != null) { StructurePreviewHelper.renderMachinePreview(machine, pos); return EnumActionResult.SUCCESS; } } - if (block instanceof BlockFactoryController && worldIn.isRemote) { - BlockFactoryController controller = (BlockFactoryController) block; + if (block instanceof BlockFactoryController controller && worldIn.isRemote) { DynamicMachine machine = controller.getParentMachine(); if (machine != null) { StructurePreviewHelper.renderMachinePreview(machine, pos); @@ -62,7 +61,7 @@ public EnumActionResult onItemUse(@Nonnull EntityPlayer player, World worldIn, @ } @Override - public void addInformation(@Nonnull ItemStack stack, @Nullable World worldIn, List tooltip, ITooltipFlag flagIn) { + public void addInformation(@Nonnull ItemStack stack, @Nullable World worldIn, List tooltip, @NotNull ITooltipFlag flagIn) { tooltip.add(I18n.format("tooltip.modularmachinery.machine_projector")); } }