Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Improvments for the Extract Screen (for Version 1.21.1) #247

Open
wants to merge 7 commits into
base: 1.21.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ java_toolchain_version=21

mod_loader=neoforge
minecraft_version=1.21.1
neoforge_version=21.1.23
neoforge_version=21.1.83
neoforge_dependency=[21.0.8-beta,)
corelib_version=2.1.4

Expand Down
80 changes: 80 additions & 0 deletions src/main/java/de/maxhenkel/pipez/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,30 @@

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import de.maxhenkel.corelib.helpers.AbstractStack;
import de.maxhenkel.corelib.helpers.WrappedFluidStack;
import de.maxhenkel.corelib.helpers.WrappedItemStack;
import de.maxhenkel.corelib.tag.SingleElementTag;
import de.maxhenkel.corelib.tag.Tag;
import de.maxhenkel.pipez.utils.ComponentUtils;
import de.maxhenkel.pipez.utils.MekanismUtils;
import de.maxhenkel.pipez.utils.NbtUtils;
import de.maxhenkel.pipez.utils.WrappedGasStack;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.UUIDUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.material.Fluid;
import net.neoforged.neoforge.fluids.FluidStack;

import javax.annotation.Nullable;
import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -247,4 +262,69 @@ public boolean isSingle() {
}
}

public static <T> T get(Tag<T> tag) {
long time = Minecraft.getInstance().level.getGameTime();
List<T> allElements = tag.getAll().stream().toList();
return allElements.get((int) (time / 20L % allElements.size()));
}

@Nullable
public AbstractStack<?> getStack() {
Object o = null;

if (this.getTag() != null) {
o = get(this.getTag());
}

if (o instanceof Item) {
ItemStack stack = new ItemStack((Item) o);
if (this.getMetadata() != null) {
stack.applyComponents(ComponentUtils.getPatch(Minecraft.getInstance().level.registryAccess(), this.getMetadata().copy()));
}
return new WrappedItemStack(stack);
} else if (o instanceof Fluid) {
FluidStack stack = new FluidStack((Fluid) o, 1000);
if (this.getMetadata() != null) {
stack.applyComponents(ComponentUtils.getPatch(Minecraft.getInstance().level.registryAccess(), this.getMetadata().copy()));
}
return new WrappedFluidStack(stack);
}

if (MekanismUtils.isMekanismInstalled()) {
AbstractStack<?> gasStack = WrappedGasStack.dummyStack(o);
if (gasStack != null) {
return gasStack;
}
}

return null;
}

public MutableComponent getTranslatedName() {
AbstractStack<?> stack = this.getStack();
if (stack != null && !stack.isEmpty() && this.getTag() != null) {
if (this.getTag() instanceof SingleElementTag) {
return Component.translatable(stack.getDisplayName().getString());
} else {
return Component.literal(this.getTag().getName().toString());
}
}
return Component.translatable("message.pipez.filter.any_item").withStyle(ChatFormatting.WHITE);
}

public boolean hasDestination() {
return this.destination != null;
}

@Nullable
public Integer getDistanceTo(BlockPos pos) {
DirectionalPosition destination = this.getDestination();
if (destination == null) {
return null;
}

BlockPos posFilter = destination.getPos();

return posFilter.distManhattan(pos);
}
}
22 changes: 5 additions & 17 deletions src/main/java/de/maxhenkel/pipez/gui/CycleIconButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;

import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;

public class CycleIconButton extends AbstractButton {

private List<Icon> icons;
private List<IconButton.Icon> icons;
private Supplier<Integer> index;
private Consumer<CycleIconButton> onPress;

public CycleIconButton(int x, int y, List<Icon> icons, Supplier<Integer> index, Consumer<CycleIconButton> onPress) {
public CycleIconButton(int x, int y, List<IconButton.Icon> icons, Supplier<Integer> index, Consumer<CycleIconButton> onPress) {
// TODO ---> 20
super(x, y, 20, 20, Component.empty());
this.icons = icons;
this.index = index;
Expand All @@ -28,10 +28,10 @@ public CycleIconButton(int x, int y, List<Icon> icons, Supplier<Integer> index,
@Override
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
super.renderWidget(guiGraphics, mouseX, mouseY, partialTicks);
Icon icon = icons.get(index.get());
IconButton.Icon icon = icons.get(index.get());
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1F, 1F, 1F, 1F);
guiGraphics.blit(icon.texture, getX() + 2, getY() + 2, icon.offsetX, icon.offsetY, 16, 16);
guiGraphics.blit(icon.texture, getX() + 2, getY() + 2, icon.spriteRect.x, icon.spriteRect.y, icon.spriteRect.w, icon.spriteRect.h);
}

@Override
Expand All @@ -43,16 +43,4 @@ protected void updateWidgetNarration(NarrationElementOutput output) {
public void onPress() {
onPress.accept(this);
}

public static class Icon {
private ResourceLocation texture;
private int offsetX, offsetY;

public Icon(ResourceLocation texture, int offsetX, int offsetY) {
this.texture = texture;
this.offsetX = offsetX;
this.offsetY = offsetY;
}
}

}
21 changes: 19 additions & 2 deletions src/main/java/de/maxhenkel/pipez/gui/ExtractContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import de.maxhenkel.corelib.inventory.ContainerBase;
import de.maxhenkel.pipez.blocks.tileentity.PipeLogicTileEntity;
import de.maxhenkel.pipez.gui.sprite.ExtractUISprite;
import net.minecraft.core.Direction;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.Slot;

public class ExtractContainer extends ContainerBase implements IPipeContainer {

Expand All @@ -18,7 +20,7 @@ public ExtractContainer(int id, Container playerInventory, PipeLogicTileEntity p
this.side = side;
this.index = index;

addSlot(new UpgradeSlot(pipe.getUpgradeInventory(), side.get3DDataValue(), 9, 81));
addSlot(new UpgradeSlot(pipe.getUpgradeInventory(), side.get3DDataValue(), ExtractUISprite.UPGRADE_SLOT.x, ExtractUISprite.UPGRADE_SLOT.y));

addPlayerInventorySlots();
}
Expand Down Expand Up @@ -47,9 +49,24 @@ public int getInventorySize() {
return 1;
}

@Override
protected void addPlayerInventorySlots() {
if (playerInventory != null) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++) {
addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18 + ExtractUISprite.INVENTORY_OFFSET.x, 84 + i * 18 + ExtractUISprite.INVENTORY_OFFSET.y));
}
}

for (int k = 0; k < 9; k++) {
addSlot(new Slot(playerInventory, k, 8 + k * 18 + ExtractUISprite.INVENTORY_OFFSET.x, 142 + ExtractUISprite.INVENTORY_OFFSET.y));
}
}
}

@Override
public int getInvOffset() {
return 30;
return ExtractUISprite.INVENTORY_OFFSET.y;
}

@Override
Expand Down
Loading