Skip to content

Commit

Permalink
Disable motor slot for IN only pipes and add relevant tooltip (#981)
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n authored Dec 26, 2024
1 parent 4886d79 commit 7c9bc33
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
package aztech.modern_industrialization.client;

import java.util.ArrayList;
import aztech.modern_industrialization.util.RenderHelper;
import java.util.List;
import java.util.function.Supplier;
import net.minecraft.client.Minecraft;
Expand All @@ -41,10 +41,6 @@ public DynamicTooltip(Supplier<List<Component>> tooltipSupplier) {

@Override
public List<FormattedCharSequence> toCharSequence(Minecraft minecraft) {
List<FormattedCharSequence> charSequences = new ArrayList<>();
for (var component : tooltipSupplier.get()) {
charSequences.addAll(Tooltip.splitTooltip(minecraft, component));
}
return charSequences;
return RenderHelper.splitTooltip(tooltipSupplier.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import aztech.modern_industrialization.network.pipes.SetItemWhitelistPacket;
import aztech.modern_industrialization.pipes.gui.PipeGuiHelper;
import aztech.modern_industrialization.pipes.gui.PipeScreen;
import aztech.modern_industrialization.util.RenderHelper;
import aztech.modern_industrialization.util.TextHelper;
import com.mojang.blaze3d.systems.RenderSystem;
import java.util.ArrayList;
Expand Down Expand Up @@ -122,7 +123,15 @@ protected void renderTooltip(GuiGraphics guiGraphics, int x, int y) {
super.renderTooltip(guiGraphics, x, y);

if (this.hoveredSlot != null && this.hoveredSlot instanceof ItemPipeScreenHandler.UpgradeSlot && !this.hoveredSlot.hasItem()) {
guiGraphics.renderTooltip(font, new MITooltips.Line(MIText.PutMotorToUpgrade).build(), x, y);
List<Component> lines = new ArrayList<>();
lines.add(MIText.PutMotorToUpgrade.text());
if (menu.pipeInterface.getConnectionType() == 0) {
lines.add(MIText.PriorityNotApplicable.text(
MIText.PipeConnectionTooltipInsertOnly.text().setStyle(MITooltips.HIGHLIGHT_STYLE),
MIText.PipeConnectionIn.text().setStyle(MITooltips.HIGHLIGHT_STYLE))
.setStyle(TextHelper.GRAY_TEXT));
}
guiGraphics.renderTooltip(font, RenderHelper.splitTooltip(lines), x, y);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.blaze3d.vertex.VertexFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LevelRenderer;
Expand All @@ -55,7 +58,9 @@
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemDisplayContext;
Expand Down Expand Up @@ -294,4 +299,12 @@ public static void renderAndDecorateItem(GuiGraphics guiGraphics, Font font, Ite
guiGraphics.renderItem(stack, x, y);
guiGraphics.renderItemDecorations(font, stack, x, y, text);
}

public static List<FormattedCharSequence> splitTooltip(List<Component> components) {
List<FormattedCharSequence> charSequences = new ArrayList<>();
for (var component : components) {
charSequences.addAll(Tooltip.splitTooltip(Minecraft.getInstance(), component));
}
return charSequences;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,18 @@ public UpgradeSlot(int x, int y) {

@Override
public boolean mayPlace(ItemStack stack) {
if (pipeInterface.getConnectionType() == 0) {
// Prevent placing motors in `IN` pipes.
return false;
}
return stack.getItemHolder().getData(MIDataMaps.ITEM_PIPE_UPGRADES) != null;
}

@Override
public boolean isHighlightable() {
return pipeInterface.getConnectionType() != 0;
}

@Override
public ItemStack getItem() {
return pipeInterface.getUpgradeStack();
Expand Down

0 comments on commit 7c9bc33

Please sign in to comment.