Also list all extra custom hard drives in the creative tab.
This commit is contained in:
@@ -12,6 +12,7 @@ import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class BlockDeviceDataRegistry {
|
||||
private static final DeferredRegister<BlockDeviceData> INITIALIZER = RegistryUtils.create(BlockDeviceData.class);
|
||||
@@ -38,4 +39,8 @@ public final class BlockDeviceDataRegistry {
|
||||
public static BlockDeviceData getValue(final ResourceLocation location) {
|
||||
return REGISTRY.get().getValue(location);
|
||||
}
|
||||
|
||||
public static Stream<BlockDeviceData> values() {
|
||||
return REGISTRY.get().getValues().stream();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,4 +85,10 @@ public abstract class AbstractBlockDeviceItem extends ModItem {
|
||||
return super.getName(stack);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
protected ResourceLocation getDefaultData() {
|
||||
return defaultData;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,18 @@
|
||||
package li.cil.oc2.common.item;
|
||||
|
||||
import li.cil.oc2.api.API;
|
||||
import li.cil.oc2.common.bus.device.data.BlockDeviceDataRegistry;
|
||||
import li.cil.oc2.common.util.ColorUtils;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.item.DyeableLeatherItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class HardDriveWithExternalDataItem extends AbstractBlockDeviceItem implements DyeableLeatherItem {
|
||||
private final int defaultColor;
|
||||
@@ -25,6 +29,20 @@ public final class HardDriveWithExternalDataItem extends AbstractBlockDeviceItem
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void fillItemCategory(final CreativeModeTab tab, final NonNullList<ItemStack> items) {
|
||||
super.fillItemCategory(tab, items);
|
||||
|
||||
BlockDeviceDataRegistry.values().forEach(data -> {
|
||||
if (!Objects.equals(BlockDeviceDataRegistry.getKey(data), getDefaultData())) {
|
||||
final ItemStack stack = withData(data);
|
||||
if (!stack.isEmpty()) {
|
||||
items.add(stack);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor(final ItemStack stack) {
|
||||
return hasCustomColor(stack) ? DyeableLeatherItem.super.getColor(stack) : defaultColor;
|
||||
|
||||
Reference in New Issue
Block a user