Skip to content

Commit a5ccc60

Browse files
committed
Add javadoc about new UIs on MTEs and fix not returning true from onRightClick client side
1 parent ba64936 commit a5ccc60

File tree

3 files changed

+65
-53
lines changed

3 files changed

+65
-53
lines changed

src/main/java/gregtech/api/metatileentity/MetaTileEntity.java

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@
111111

112112
import static gregtech.api.capability.GregtechDataCodes.*;
113113

114+
/**
115+
* For addon developers: <br/>
116+
* Legacy GregTech MUI UIs are being deprecated. GUIs are now done through
117+
* <a href="https://github.com/CleanroomMC/ModularUI/">Modular UI</a>. To use the new MUI UIs, implement
118+
* {@link IMetaTileEntityGuiHolder} on your MetaTileEntity class. Opening the UI on right clicks is handled
119+
* automatically.
120+
*/
114121
public abstract class MetaTileEntity implements ISyncedTileEntity, CoverHolder, IVoidable {
115122

116123
public static final IndexedCuboid6 FULL_CUBE_COLLISION = new IndexedCuboid6(null, Cuboid6.full);
@@ -450,6 +457,10 @@ protected FluidTankList createExportFluidHandler() {
450457
return new FluidTankList(false);
451458
}
452459

460+
/**
461+
* @return if this MetaTileEntity should open a legacy MUI UI when right-clicked. <br/>
462+
* Do not override if you're implementing {@link IMetaTileEntityGuiHolder}!
463+
*/
453464
@Deprecated
454465
protected boolean openGUIOnRightClick() {
455466
return true;
@@ -496,59 +507,60 @@ public boolean onRightClick(EntityPlayer playerIn, EnumHand hand, EnumFacing fac
496507
}
497508

498509
if (!playerIn.isSneaking()) {
499-
if (!world.isRemote) {
500-
EntityPlayerMP playerMP = (EntityPlayerMP) playerIn;
501-
boolean uiOpened = false;
502-
503-
if (this instanceof IMetaTileEntityGuiHolder guiHolder &&
504-
guiHolder.shouldOpenUI(playerMP, hand, facing, hitResult)) {
505-
MetaTileEntityGuiFactory.open(playerMP, (MetaTileEntity & IMetaTileEntityGuiHolder) this);
506-
uiOpened = true;
507-
} else if (openGUIOnRightClick()) {
508-
MetaTileEntityUIFactory.INSTANCE.openUI(getHolder(), playerMP);
509-
uiOpened = true;
510-
}
511-
512-
if (uiOpened) {
513-
if (getOwner() == null) {
514-
this.owner = playerIn.getUniqueID();
510+
if (this instanceof IMetaTileEntityGuiHolder guiHolder) {
511+
if (guiHolder.shouldOpenUI()) {
512+
if (!world.isRemote) {
513+
MetaTileEntityGuiFactory.open((EntityPlayerMP) playerIn,
514+
(MetaTileEntity & IMetaTileEntityGuiHolder) this);
515+
if (!hasOwner()) {
516+
setOwner(playerIn);
517+
}
515518
}
516519

517520
return true;
518521
}
519-
}
520-
} else {
521-
// Attempt to rename the MTE first
522-
if (heldStack.getItem() == Items.NAME_TAG) {
523-
if (playerIn.isSneaking() && heldStack.getTagCompound() != null &&
524-
heldStack.getTagCompound().hasKey("display")) {
525-
MetaTileEntityHolder mteHolder = (MetaTileEntityHolder) getHolder();
526-
527-
mteHolder.setCustomName(heldStack.getTagCompound().getCompoundTag("display").getString("Name"));
528-
if (!playerIn.isCreative()) {
529-
heldStack.shrink(1);
522+
} else if (openGUIOnRightClick()) {
523+
if (!world.isRemote) {
524+
MetaTileEntityUIFactory.INSTANCE.openUI(getHolder(), (EntityPlayerMP) playerIn);
525+
if (!hasOwner()) {
526+
setOwner(playerIn);
530527
}
531-
return true;
532528
}
529+
530+
return true;
533531
}
532+
}
534533

535-
// Try to do cover right-click behavior on this specific side first
536-
EnumFacing hitFacing = hitResult.sideHit;
537-
Cover cover = hitFacing == null ? null : getCoverAtSide(hitFacing);
538-
if (cover != null) {
539-
if (cover.onRightClick(playerIn, hand, hitResult) == EnumActionResult.SUCCESS) {
540-
return true;
534+
// Attempt to rename the MTE first
535+
if (heldStack.getItem() == Items.NAME_TAG) {
536+
if (playerIn.isSneaking() && heldStack.getTagCompound() != null &&
537+
heldStack.getTagCompound().hasKey("display")) {
538+
MetaTileEntityHolder mteHolder = (MetaTileEntityHolder) getHolder();
539+
540+
mteHolder.setCustomName(heldStack.getTagCompound().getCompoundTag("display").getString("Name"));
541+
if (!playerIn.isCreative()) {
542+
heldStack.shrink(1);
541543
}
544+
return true;
542545
}
546+
}
543547

544-
// Then try to do cover screwdriver-click behavior on the cover grid side next
545-
EnumFacing gridSideHit = CoverRayTracer.determineGridSideHit(hitResult);
546-
cover = gridSideHit == null ? null : getCoverAtSide(gridSideHit);
547-
if (cover != null && playerIn.isSneaking() && playerIn.getHeldItemMainhand().isEmpty()) {
548-
return cover.onScrewdriverClick(playerIn, hand, hitResult) == EnumActionResult.SUCCESS;
548+
// Try to do cover right-click behavior on this specific side first
549+
EnumFacing hitFacing = hitResult.sideHit;
550+
Cover cover = hitFacing == null ? null : getCoverAtSide(hitFacing);
551+
if (cover != null) {
552+
if (cover.onRightClick(playerIn, hand, hitResult) == EnumActionResult.SUCCESS) {
553+
return true;
549554
}
550555
}
551556

557+
// Then try to do cover screwdriver-click behavior on the cover grid side next
558+
EnumFacing gridSideHit = CoverRayTracer.determineGridSideHit(hitResult);
559+
cover = gridSideHit == null ? null : getCoverAtSide(gridSideHit);
560+
if (cover != null && playerIn.isSneaking() && playerIn.getHeldItemMainhand().isEmpty()) {
561+
return cover.onScrewdriverClick(playerIn, hand, hitResult) == EnumActionResult.SUCCESS;
562+
}
563+
552564
return false;
553565
}
554566

@@ -1509,11 +1521,23 @@ public boolean getWitherProof() {
15091521
return false;
15101522
}
15111523

1524+
public boolean hasOwner() {
1525+
return this.owner != null;
1526+
}
1527+
15121528
@Nullable
15131529
public UUID getOwner() {
15141530
return owner;
15151531
}
15161532

1533+
protected void setOwner(@NotNull EntityPlayer player) {
1534+
this.owner = player.getUniqueID();
1535+
}
1536+
1537+
protected void setOwner(@Nullable UUID uuid) {
1538+
this.owner = uuid;
1539+
}
1540+
15171541
public final void toggleMuffled() {
15181542
muffled = !muffled;
15191543
if (!getWorld().isRemote) {

src/main/java/gregtech/api/mui/IMetaTileEntityGuiHolder.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
import gregtech.api.metatileentity.MetaTileEntity;
44

5-
import net.minecraft.entity.player.EntityPlayerMP;
65
import net.minecraft.network.PacketBuffer;
7-
import net.minecraft.util.EnumFacing;
8-
import net.minecraft.util.EnumHand;
96

10-
import codechicken.lib.raytracer.CuboidRayTraceResult;
117
import com.cleanroommc.modularui.api.IGuiHolder;
128
import com.cleanroommc.modularui.api.value.IStringValue;
139
import com.cleanroommc.modularui.screen.ModularPanel;
@@ -20,7 +16,6 @@
2016
import com.cleanroommc.modularui.widgets.textfield.TextFieldWidget;
2117
import org.jetbrains.annotations.ApiStatus;
2218
import org.jetbrains.annotations.NotNull;
23-
import org.jetbrains.annotations.UnknownNullability;
2419

2520
public interface IMetaTileEntityGuiHolder extends IGuiHolder<MetaTileEntityGuiData> {
2621

@@ -38,8 +33,7 @@ default GTGuiTheme getUITheme() {
3833
/**
3934
* @return whether this {@link MetaTileEntity} should open its UI.
4035
*/
41-
default boolean shouldOpenUI(@NotNull EntityPlayerMP player, @NotNull EnumHand hand, @NotNull EnumFacing side,
42-
@UnknownNullability CuboidRayTraceResult hitResult) {
36+
default boolean shouldOpenUI() {
4337
return true;
4438
}
4539

src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828

2929
import net.minecraft.client.resources.I18n;
3030
import net.minecraft.creativetab.CreativeTabs;
31-
import net.minecraft.entity.player.EntityPlayerMP;
3231
import net.minecraft.item.ItemStack;
33-
import net.minecraft.util.EnumFacing;
34-
import net.minecraft.util.EnumHand;
3532
import net.minecraft.util.NonNullList;
3633
import net.minecraft.util.ResourceLocation;
3734
import net.minecraft.util.text.ITextComponent;
@@ -40,7 +37,6 @@
4037
import net.minecraft.world.World;
4138
import net.minecraftforge.items.IItemHandlerModifiable;
4239

43-
import codechicken.lib.raytracer.CuboidRayTraceResult;
4440
import codechicken.lib.render.CCRenderState;
4541
import codechicken.lib.render.pipeline.IVertexOperation;
4642
import codechicken.lib.vec.Matrix4;
@@ -60,7 +56,6 @@
6056
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
6157
import org.jetbrains.annotations.NotNull;
6258
import org.jetbrains.annotations.Nullable;
63-
import org.jetbrains.annotations.UnknownNullability;
6459

6560
import java.util.*;
6661

@@ -121,8 +116,7 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation,
121116
}
122117

123118
@Override
124-
public boolean shouldOpenUI(@NotNull EntityPlayerMP player, @NotNull EnumHand hand, @NotNull EnumFacing side,
125-
@UnknownNullability CuboidRayTraceResult hitResult) {
119+
public boolean shouldOpenUI() {
126120
return !isCreative;
127121
}
128122

0 commit comments

Comments
 (0)