mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-12 23:37:29 +01:00
Server-friendly Item Groups
This commit is contained in:
parent
be66f2b77a
commit
104985d9ed
2 changed files with 25 additions and 9 deletions
|
@ -8,7 +8,7 @@ mod_version = 0.5.1.d
|
||||||
artifact_minecraft_version = 1.20.1
|
artifact_minecraft_version = 1.20.1
|
||||||
|
|
||||||
minecraft_version = 1.20.1
|
minecraft_version = 1.20.1
|
||||||
forge_version = 47.0.43
|
forge_version = 47.1.43
|
||||||
|
|
||||||
# build dependency versions
|
# build dependency versions
|
||||||
forgegradle_version = 6.0.6
|
forgegradle_version = 6.0.6
|
||||||
|
|
|
@ -7,6 +7,8 @@ import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.mutable.MutableBoolean;
|
||||||
|
|
||||||
import com.simibubi.create.content.contraptions.actors.seat.SeatBlock;
|
import com.simibubi.create.content.contraptions.actors.seat.SeatBlock;
|
||||||
import com.simibubi.create.content.decoration.palettes.AllPaletteBlocks;
|
import com.simibubi.create.content.decoration.palettes.AllPaletteBlocks;
|
||||||
import com.simibubi.create.content.equipment.armor.BacktankUtil;
|
import com.simibubi.create.content.equipment.armor.BacktankUtil;
|
||||||
|
@ -40,7 +42,10 @@ import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Items;
|
import net.minecraft.world.item.Items;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
|
import net.minecraftforge.fml.DistExecutor;
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
||||||
import net.minecraftforge.registries.DeferredRegister;
|
import net.minecraftforge.registries.DeferredRegister;
|
||||||
|
@ -141,6 +146,22 @@ public class AllCreativeModeTabs {
|
||||||
return exclusions::contains;
|
return exclusions::contains;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Predicate<Item> make3DPredicate(boolean model3d) {
|
||||||
|
return item -> {
|
||||||
|
MutableBoolean result = new MutableBoolean(false);
|
||||||
|
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> result.setValue(isItem3d(item) == model3d));
|
||||||
|
return result.getValue();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
private static boolean isItem3d(Item item) {
|
||||||
|
ItemRenderer itemRenderer = Minecraft.getInstance()
|
||||||
|
.getItemRenderer();
|
||||||
|
BakedModel model = itemRenderer.getModel(new ItemStack(item), null, null, 0);
|
||||||
|
return model.isGui3d();
|
||||||
|
}
|
||||||
|
|
||||||
private static List<ItemOrdering> makeOrderings() {
|
private static List<ItemOrdering> makeOrderings() {
|
||||||
List<ItemOrdering> orderings = new ReferenceArrayList<>();
|
List<ItemOrdering> orderings = new ReferenceArrayList<>();
|
||||||
|
|
||||||
|
@ -233,7 +254,6 @@ public class AllCreativeModeTabs {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ItemDisplayParameters pParameters, Output output) {
|
public void accept(ItemDisplayParameters pParameters, Output output) {
|
||||||
ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer();
|
|
||||||
Predicate<Item> exclusionPredicate = makeExclusionPredicate();
|
Predicate<Item> exclusionPredicate = makeExclusionPredicate();
|
||||||
List<ItemOrdering> orderings = makeOrderings();
|
List<ItemOrdering> orderings = makeOrderings();
|
||||||
Function<Item, ItemStack> stackFunc = makeStackFunc();
|
Function<Item, ItemStack> stackFunc = makeStackFunc();
|
||||||
|
@ -241,9 +261,9 @@ public class AllCreativeModeTabs {
|
||||||
RegistryObject<CreativeModeTab> tab = mainTab ? MAIN_TAB : BUILDING_BLOCKS_TAB;
|
RegistryObject<CreativeModeTab> tab = mainTab ? MAIN_TAB : BUILDING_BLOCKS_TAB;
|
||||||
|
|
||||||
List<Item> items = new LinkedList<>();
|
List<Item> items = new LinkedList<>();
|
||||||
items.addAll(collectItems(tab, itemRenderer, true, exclusionPredicate));
|
items.addAll(collectItems(tab, exclusionPredicate.or(make3DPredicate(false))));
|
||||||
items.addAll(collectBlocks(tab, exclusionPredicate));
|
items.addAll(collectBlocks(tab, exclusionPredicate));
|
||||||
items.addAll(collectItems(tab, itemRenderer, false, exclusionPredicate));
|
items.addAll(collectItems(tab, exclusionPredicate.or(make3DPredicate(true))));
|
||||||
|
|
||||||
applyOrderings(items, orderings);
|
applyOrderings(items, orderings);
|
||||||
outputAll(output, items, stackFunc, visibilityFunc);
|
outputAll(output, items, stackFunc, visibilityFunc);
|
||||||
|
@ -265,8 +285,7 @@ public class AllCreativeModeTabs {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Item> collectItems(RegistryObject<CreativeModeTab> tab, ItemRenderer itemRenderer, boolean special,
|
private List<Item> collectItems(RegistryObject<CreativeModeTab> tab, Predicate<Item> exclusionPredicate) {
|
||||||
Predicate<Item> exclusionPredicate) {
|
|
||||||
List<Item> items = new ReferenceArrayList<>();
|
List<Item> items = new ReferenceArrayList<>();
|
||||||
|
|
||||||
if (!mainTab)
|
if (!mainTab)
|
||||||
|
@ -278,9 +297,6 @@ public class AllCreativeModeTabs {
|
||||||
Item item = entry.get();
|
Item item = entry.get();
|
||||||
if (item instanceof BlockItem)
|
if (item instanceof BlockItem)
|
||||||
continue;
|
continue;
|
||||||
BakedModel model = itemRenderer.getModel(new ItemStack(item), null, null, 0);
|
|
||||||
if (model.isGui3d() != special)
|
|
||||||
continue;
|
|
||||||
if (!exclusionPredicate.test(item))
|
if (!exclusionPredicate.test(item))
|
||||||
items.add(item);
|
items.add(item);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue