|
111 | 111 |
|
112 | 112 | import static gregtech.api.capability.GregtechDataCodes.*; |
113 | 113 |
|
| 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 | + */ |
114 | 121 | public abstract class MetaTileEntity implements ISyncedTileEntity, CoverHolder, IVoidable { |
115 | 122 |
|
116 | 123 | public static final IndexedCuboid6 FULL_CUBE_COLLISION = new IndexedCuboid6(null, Cuboid6.full); |
@@ -450,6 +457,10 @@ protected FluidTankList createExportFluidHandler() { |
450 | 457 | return new FluidTankList(false); |
451 | 458 | } |
452 | 459 |
|
| 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 | + */ |
453 | 464 | @Deprecated |
454 | 465 | protected boolean openGUIOnRightClick() { |
455 | 466 | return true; |
@@ -496,59 +507,60 @@ public boolean onRightClick(EntityPlayer playerIn, EnumHand hand, EnumFacing fac |
496 | 507 | } |
497 | 508 |
|
498 | 509 | 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 | + } |
515 | 518 | } |
516 | 519 |
|
517 | 520 | return true; |
518 | 521 | } |
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); |
530 | 527 | } |
531 | | - return true; |
532 | 528 | } |
| 529 | + |
| 530 | + return true; |
533 | 531 | } |
| 532 | + } |
534 | 533 |
|
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); |
541 | 543 | } |
| 544 | + return true; |
542 | 545 | } |
| 546 | + } |
543 | 547 |
|
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; |
549 | 554 | } |
550 | 555 | } |
551 | 556 |
|
| 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 | + |
552 | 564 | return false; |
553 | 565 | } |
554 | 566 |
|
@@ -1509,11 +1521,23 @@ public boolean getWitherProof() { |
1509 | 1521 | return false; |
1510 | 1522 | } |
1511 | 1523 |
|
| 1524 | + public boolean hasOwner() { |
| 1525 | + return this.owner != null; |
| 1526 | + } |
| 1527 | + |
1512 | 1528 | @Nullable |
1513 | 1529 | public UUID getOwner() { |
1514 | 1530 | return owner; |
1515 | 1531 | } |
1516 | 1532 |
|
| 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 | + |
1517 | 1541 | public final void toggleMuffled() { |
1518 | 1542 | muffled = !muffled; |
1519 | 1543 | if (!getWorld().isRemote) { |
|
0 commit comments