Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArraySet;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -166,6 +168,13 @@ public abstract class MetaTileEntity implements ISyncedTileEntity, CoverHolder,
@Nullable
private UUID owner = null;

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;
this.registry = GregTechAPI.mteManager.getRegistry(metaTileEntityId.getNamespace());
Expand Down Expand Up @@ -362,7 +371,7 @@ public void getSubItems(CreativeTabs creativeTab, NonNullList<ItemStack> subItem
* MachineItemBlock#addCreativeTab(CreativeTabs)
*/
public boolean isInCreativeTab(CreativeTabs creativeTab) {
return creativeTab == CreativeTabs.SEARCH || creativeTab == GTCreativeTabs.TAB_GREGTECH_MACHINES;
return creativeTabs.contains(creativeTab);
}

public String getItemSubTypeId(ItemStack itemStack) {
Expand Down Expand Up @@ -1661,4 +1670,45 @@ public AENetworkProxy getProxy() {

@Method(modid = Mods.Names.APPLIED_ENERGISTICS2)
public void gridChanged() {}

/**
* Add MTE to a creative tab. Ensure that the creative tab has been registered via
* {@link gregtech.api.block.machines.MachineItemBlock#addCreativeTab(CreativeTabs)
* MachineItemBlock#addCreativeTab(CreativeTabs)} beforehand.
*/
public void addAdditionalCreativeTabs(CreativeTabs creativeTab) {
Preconditions.checkNotNull(creativeTab, "creativeTab");
if (creativeTabs.contains(creativeTab)) {
GTLog.logger.error("{} is already in the creative tab {}.", this, creativeTab.tabLabel,
new IllegalArgumentException());
return;
}

creativeTabs.add(creativeTab);
}

public void removeFromCreativeTab(CreativeTabs creativeTab) {
Preconditions.checkNotNull(creativeTab, "creativeTab");
if (creativeTab == CreativeTabs.SEARCH) {
GTLog.logger.error("Cannot remove MTEs from the creative search tab.",
new IllegalArgumentException());
return;
}
if (creativeTab == GTCreativeTabs.TAB_GREGTECH_MACHINES &&
metaTileEntityId.getNamespace().equals(GTValues.MODID)) {
GTLog.logger.error("Cannot remove GT MTEs from the GT machines tab.", new IllegalArgumentException());
return;
}
if (!creativeTabs.contains(creativeTab)) {
GTLog.logger.error("{} is not in the creative tab {}.", this, creativeTab.tabLabel,
new IllegalArgumentException());
return;
}

creativeTabs.remove(creativeTab);
}

public Set<CreativeTabs> getCreativeTabs() {
return Collections.unmodifiableSet(creativeTabs);
}
}
Loading