|
100 | 100 | import it.unimi.dsi.fastutil.ints.Int2ObjectMap; |
101 | 101 | import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; |
102 | 102 | import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; |
| 103 | +import it.unimi.dsi.fastutil.objects.ObjectArraySet; |
103 | 104 | import org.apache.commons.lang3.ArrayUtils; |
104 | 105 | import org.apache.commons.lang3.tuple.Pair; |
105 | 106 | import org.jetbrains.annotations.ApiStatus; |
106 | 107 | import org.jetbrains.annotations.NotNull; |
107 | 108 | import org.jetbrains.annotations.Nullable; |
108 | 109 |
|
109 | 110 | import java.util.ArrayList; |
| 111 | +import java.util.Collections; |
110 | 112 | import java.util.EnumMap; |
111 | 113 | import java.util.List; |
112 | 114 | import java.util.Map; |
@@ -166,6 +168,13 @@ public abstract class MetaTileEntity implements ISyncedTileEntity, CoverHolder, |
166 | 168 | @Nullable |
167 | 169 | private UUID owner = null; |
168 | 170 |
|
| 171 | + private final Set<CreativeTabs> creativeTabs = new ObjectArraySet<>(); |
| 172 | + |
| 173 | + { |
| 174 | + creativeTabs.add(CreativeTabs.SEARCH); |
| 175 | + creativeTabs.add(GTCreativeTabs.TAB_GREGTECH_MACHINES); |
| 176 | + } |
| 177 | + |
169 | 178 | protected MetaTileEntity(@NotNull ResourceLocation metaTileEntityId) { |
170 | 179 | this.metaTileEntityId = metaTileEntityId; |
171 | 180 | this.registry = GregTechAPI.mteManager.getRegistry(metaTileEntityId.getNamespace()); |
@@ -365,7 +374,7 @@ public void getSubItems(CreativeTabs creativeTab, NonNullList<ItemStack> subItem |
365 | 374 | * MachineItemBlock#addCreativeTab(CreativeTabs) |
366 | 375 | */ |
367 | 376 | public boolean isInCreativeTab(CreativeTabs creativeTab) { |
368 | | - return creativeTab == CreativeTabs.SEARCH || creativeTab == GTCreativeTabs.TAB_GREGTECH_MACHINES; |
| 377 | + return creativeTabs.contains(creativeTab); |
369 | 378 | } |
370 | 379 |
|
371 | 380 | public String getItemSubTypeId(ItemStack itemStack) { |
@@ -1664,4 +1673,45 @@ public AENetworkProxy getProxy() { |
1664 | 1673 |
|
1665 | 1674 | @Method(modid = Mods.Names.APPLIED_ENERGISTICS2) |
1666 | 1675 | public void gridChanged() {} |
| 1676 | + |
| 1677 | + /** |
| 1678 | + * Add MTE to a creative tab. Ensure that the creative tab has been registered via |
| 1679 | + * {@link gregtech.api.block.machines.MachineItemBlock#addCreativeTab(CreativeTabs) |
| 1680 | + * MachineItemBlock#addCreativeTab(CreativeTabs)} beforehand. |
| 1681 | + */ |
| 1682 | + public void addAdditionalCreativeTabs(CreativeTabs creativeTab) { |
| 1683 | + Preconditions.checkNotNull(creativeTab, "creativeTab"); |
| 1684 | + if (creativeTabs.contains(creativeTab)) { |
| 1685 | + GTLog.logger.error("{} is already in the creative tab {}.", this, creativeTab.tabLabel, |
| 1686 | + new IllegalArgumentException()); |
| 1687 | + return; |
| 1688 | + } |
| 1689 | + |
| 1690 | + creativeTabs.add(creativeTab); |
| 1691 | + } |
| 1692 | + |
| 1693 | + public void removeFromCreativeTab(CreativeTabs creativeTab) { |
| 1694 | + Preconditions.checkNotNull(creativeTab, "creativeTab"); |
| 1695 | + if (creativeTab == CreativeTabs.SEARCH) { |
| 1696 | + GTLog.logger.error("Cannot remove MTEs from the creative search tab.", |
| 1697 | + new IllegalArgumentException()); |
| 1698 | + return; |
| 1699 | + } |
| 1700 | + if (creativeTab == GTCreativeTabs.TAB_GREGTECH_MACHINES && |
| 1701 | + metaTileEntityId.getNamespace().equals(GTValues.MODID)) { |
| 1702 | + GTLog.logger.error("Cannot remove GT MTEs from the GT machines tab.", new IllegalArgumentException()); |
| 1703 | + return; |
| 1704 | + } |
| 1705 | + if (!creativeTabs.contains(creativeTab)) { |
| 1706 | + GTLog.logger.error("{} is not in the creative tab {}.", this, creativeTab.tabLabel, |
| 1707 | + new IllegalArgumentException()); |
| 1708 | + return; |
| 1709 | + } |
| 1710 | + |
| 1711 | + creativeTabs.remove(creativeTab); |
| 1712 | + } |
| 1713 | + |
| 1714 | + public Set<CreativeTabs> getCreativeTabs() { |
| 1715 | + return Collections.unmodifiableSet(creativeTabs); |
| 1716 | + } |
1667 | 1717 | } |
0 commit comments