Skip to content

Commit ce646ba

Browse files
committed
fixes
1 parent 3306b58 commit ce646ba

File tree

6 files changed

+31
-12
lines changed

6 files changed

+31
-12
lines changed

src/main/java/com/cleanroommc/modularui/factory/SidedTileEntityGuiFactory.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public class SidedTileEntityGuiFactory extends AbstractUIFactory<SidedPosGuiData
2323
public <T extends TileEntity & IGuiHolder<SidedPosGuiData>> void open(EntityPlayer player, T tile, EnumFacing facing) {
2424
Objects.requireNonNull(player);
2525
Objects.requireNonNull(facing);
26-
BlockPos pos = TileEntityGuiFactory.getPosFromTile(tile);
26+
TileEntityGuiFactory.verifyTile(player, tile);
27+
BlockPos pos = tile.getPos();
2728
SidedPosGuiData data = new SidedPosGuiData(player, pos.getX(), pos.getY(), pos.getZ(), facing);
2829
GuiManager.open(this, data, (EntityPlayerMP) player);
2930
}
@@ -39,7 +40,8 @@ public void open(EntityPlayer player, BlockPos pos, EnumFacing facing) {
3940
@SideOnly(Side.CLIENT)
4041
public <T extends TileEntity & IGuiHolder<SidedPosGuiData>> void openClient(T tile, EnumFacing facing) {
4142
Objects.requireNonNull(facing);
42-
BlockPos pos = TileEntityGuiFactory.getPosFromTile(tile);
43+
TileEntityGuiFactory.verifyTile(Platform.getClientPlayer(), tile);
44+
BlockPos pos = tile.getPos();
4345
SidedPosGuiData data = new SidedPosGuiData(Platform.getClientPlayer(), pos.getX(), pos.getY(), pos.getZ(), facing);
4446
GuiManager.openFromClient(this, data);
4547
}

src/main/java/com/cleanroommc/modularui/factory/TileEntityGuiFactory.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ private TileEntityGuiFactory() {
2626

2727
public <T extends TileEntity & IGuiHolder<PosGuiData>> void open(EntityPlayer player, T tile) {
2828
Objects.requireNonNull(player);
29-
BlockPos pos = getPosFromTile(tile);
29+
verifyTile(player, tile);
30+
BlockPos pos = tile.getPos();
3031
PosGuiData data = new PosGuiData(player, pos.getX(), pos.getY(), pos.getZ());
3132
GuiManager.open(this, data, (EntityPlayerMP) player);
3233
}
@@ -40,7 +41,8 @@ public void open(EntityPlayer player, BlockPos pos) {
4041

4142
@SideOnly(Side.CLIENT)
4243
public <T extends TileEntity & IGuiHolder<PosGuiData>> void openClient(T tile) {
43-
BlockPos pos = getPosFromTile(tile);
44+
verifyTile(Platform.getClientPlayer(), tile);
45+
BlockPos pos = tile.getPos();
4446
GuiManager.openFromClient(this, new PosGuiData(MCHelper.getPlayer(), pos.getX(), pos.getY(), pos.getZ()));
4547
}
4648

@@ -72,14 +74,13 @@ public void writeGuiData(PosGuiData guiData, PacketBuffer buffer) {
7274
return new PosGuiData(player, buffer.readVarInt(), buffer.readVarInt(), buffer.readVarInt());
7375
}
7476

75-
public static BlockPos getPosFromTile(TileEntity tile) {
77+
public static void verifyTile(EntityPlayer player, TileEntity tile) {
7678
Objects.requireNonNull(tile);
7779
if (tile.isInvalid()) {
7880
throw new IllegalArgumentException("Can't open invalid TileEntity GUI!");
7981
}
8082
if (Platform.getClientPlayer().world != tile.getWorld()) {
8183
throw new IllegalArgumentException("TileEntity must be in same dimension as the player!");
8284
}
83-
return tile.getPos();
8485
}
8586
}

src/main/java/com/cleanroommc/modularui/factory/inventory/InventoryTypes.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import net.minecraftforge.items.IItemHandlerModifiable;
99

1010
import baubles.api.BaublesApi;
11-
import org.apache.commons.lang3.tuple.Pair;
11+
import org.jetbrains.annotations.Nullable;
1212

1313
import java.util.Collection;
1414

@@ -41,10 +41,10 @@ public static Collection<InventoryType> getAll() {
4141
return InventoryType.getAll();
4242
}
4343

44-
public static Pair<InventoryType, Integer> findFirstStackable(EntityPlayer player, ItemStack stack) {
44+
public static @Nullable SlotFindResult findFirstStackable(EntityPlayer player, ItemStack stack) {
4545
for (InventoryType type : getAll()) {
4646
int i = type.findFirstStackable(player, stack);
47-
if (i >= 0) return Pair.of(type, i);
47+
if (i >= 0) return new SlotFindResult(type, i);
4848
}
4949
return null;
5050
}
@@ -64,4 +64,14 @@ public static void visitAll(EntityPlayer player, InventoryVisitor visitor) {
6464
}
6565
}
6666
}
67+
68+
public static class SlotFindResult {
69+
public final InventoryType type;
70+
public final int slot;
71+
72+
public SlotFindResult(InventoryType type, int slot) {
73+
this.type = type;
74+
this.slot = slot;
75+
}
76+
}
6777
}

src/main/java/com/cleanroommc/modularui/network/packets/OpenGuiPacket.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ public class OpenGuiPacket<T extends GuiData> implements IPacket {
2323
private UIFactory<T> factory;
2424
private PacketBuffer data;
2525

26-
public OpenGuiPacket() {
27-
}
26+
public OpenGuiPacket() {}
2827

2928
public OpenGuiPacket(int windowId, UIFactory<T> factory, PacketBuffer data) {
3029
this.windowId = windowId;

src/main/java/com/cleanroommc/modularui/test/TestItem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.cleanroommc.modularui.utils.Alignment;
1010
import com.cleanroommc.modularui.utils.ItemCapabilityProvider;
1111
import com.cleanroommc.modularui.utils.ItemStackItemHandler;
12+
import com.cleanroommc.modularui.utils.Platform;
1213
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
1314
import com.cleanroommc.modularui.value.sync.SyncHandlers;
1415
import com.cleanroommc.modularui.widget.ParentWidget;
@@ -91,7 +92,7 @@ public ICapabilityProvider initCapabilities(@NotNull ItemStack stack, @Nullable
9192
public void addInformation(@NotNull ItemStack stack, @Nullable World worldIn, @NotNull List<String> tooltip, @NotNull ITooltipFlag flagIn) {
9293
super.addInformation(stack, worldIn, tooltip, flagIn);
9394
tooltip.add("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.");
94-
tooltip.add(TextFormatting.GREEN + "Press " + ClientProxy.testKey.getDisplayName() + " to open GUI from Baubles");
95+
tooltip.add(TextFormatting.GREEN + "Press " + Platform.getKeyDisplay(ClientProxy.testKey) + " to open GUI from Baubles");
9596
}
9697

9798
@Override

src/main/java/com/cleanroommc/modularui/utils/Platform.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.minecraft.client.renderer.RenderHelper;
88
import net.minecraft.client.renderer.Tessellator;
99
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
10+
import net.minecraft.client.settings.KeyBinding;
1011
import net.minecraft.item.ItemStack;
1112
import net.minecraft.util.ResourceLocation;
1213
import net.minecraftforge.fml.relauncher.Side;
@@ -30,6 +31,11 @@ public class Platform {
3031
return Minecraft.getMinecraft().player;
3132
}
3233

34+
@SideOnly(Side.CLIENT)
35+
public static String getKeyDisplay(KeyBinding keyBinding) {
36+
return keyBinding.getKeyDescription();
37+
}
38+
3339
public static boolean isStackEmpty(ItemStack stack) {
3440
return stack == null || stack.isEmpty();
3541
}

0 commit comments

Comments
 (0)