Skip to content

Commit

Permalink
Cleanup and add missing early return
Browse files Browse the repository at this point in the history
  • Loading branch information
Zorbatron committed Dec 4, 2024
1 parent 7d0ab01 commit e8c7fd7
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,12 @@ public abstract class MetaTileEntity implements ISyncedTileEntity, CoverHolder,
@Nullable
private UUID owner = null;

private final Set<CreativeTabs> additionalCreativeTabs = new ObjectArraySet<>();
private boolean showsInSearchTab = true;
private boolean showsInGTCreativeTab = true;
private final Set<CreativeTabs> creativeTabs = new ObjectArraySet<>();

{
creativeTabs.add(CreativeTabs.SEARCH);
creativeTabs.add(GTCreativeTabs.TAB_GREGTECH_MACHINES);
}

protected MetaTileEntity(@NotNull ResourceLocation metaTileEntityId) {
this.metaTileEntityId = metaTileEntityId;
Expand Down Expand Up @@ -368,9 +371,7 @@ public void getSubItems(CreativeTabs creativeTab, NonNullList<ItemStack> subItem
* MachineItemBlock#addCreativeTab(CreativeTabs)
*/
public boolean isInCreativeTab(CreativeTabs creativeTab) {
return (showsInSearchTab && creativeTab == CreativeTabs.SEARCH) ||
(showsInGTCreativeTab && creativeTab == GTCreativeTabs.TAB_GREGTECH_MACHINES) ||
additionalCreativeTabs.contains(creativeTab);
return creativeTabs.contains(creativeTab);
}

public String getItemSubTypeId(ItemStack itemStack) {
Expand Down Expand Up @@ -1677,23 +1678,27 @@ public void gridChanged() {}
*/
public void addAdditionalCreativeTabs(CreativeTabs creativeTab) {
Preconditions.checkNotNull(creativeTab, "creativeTab");
if (creativeTab == GTCreativeTabs.TAB_GREGTECH_MACHINES || creativeTab == CreativeTabs.SEARCH) {
GTLog.logger.error("Adding {} as additional creative tab is redundant.", creativeTab.tabLabel,
if (creativeTabs.contains(creativeTab)) {
GTLog.logger.error("{} is already in the creative tab {}.", this, creativeTab.tabLabel,
new IllegalArgumentException());
return;
}

additionalCreativeTabs.add(creativeTab);
creativeTabs.add(creativeTab);
}

public Set<CreativeTabs> getAdditionalCreativeTabs() {
return Collections.unmodifiableSet(additionalCreativeTabs);
}
public void removeFromCreativeTab(CreativeTabs creativeTab) {
Preconditions.checkNotNull(creativeTab, "creativeTab");
if (!creativeTabs.contains(creativeTab)) {
GTLog.logger.error("{} is not in the creative tab {}.", this, creativeTab.tabLabel,
new IllegalArgumentException());
return;
}

public void removeFromSearchTab() {
showsInSearchTab = false;
creativeTabs.remove(creativeTab);
}

public void removeFromGTCreativeTab() {
showsInGTCreativeTab = false;
public Set<CreativeTabs> getCreativeTabs() {
return Collections.unmodifiableSet(creativeTabs);
}
}

0 comments on commit e8c7fd7

Please sign in to comment.