Made hard drives have customizable color.
This commit is contained in:
@@ -37,7 +37,8 @@ public final class CustomItemColors {
|
||||
|
||||
public static void initialize() {
|
||||
final ItemColors itemColors = Minecraft.getInstance().getItemColors();
|
||||
itemColors.register((stack, layer) -> layer == 1 ? getColor(stack) : NO_TINT, Items.FLOPPY.get());
|
||||
itemColors.register((stack, layer) -> layer == 1 ? getColor(stack) : NO_TINT,
|
||||
Items.HARD_DRIVE.get(), Items.FLOPPY.get());
|
||||
}
|
||||
|
||||
public static int getColorByDye(final DyeColor dye) {
|
||||
@@ -88,6 +89,10 @@ public final class CustomItemColors {
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack withColor(final ItemStack stack, final DyeColor color) {
|
||||
return withColor(stack, getColorByDye(color));
|
||||
}
|
||||
|
||||
public static ItemStack withColor(final ItemStack stack, final int color) {
|
||||
ItemStackUtils.getOrCreateModDataTag(stack).putInt(COLOR_TAG_NAME, color);
|
||||
return stack;
|
||||
|
||||
@@ -2,48 +2,23 @@ package li.cil.oc2.client.item;
|
||||
|
||||
import li.cil.oc2.api.API;
|
||||
import li.cil.oc2.common.item.AbstractStorageItem;
|
||||
import li.cil.oc2.common.item.AbstractBlockDeviceItem;
|
||||
import li.cil.oc2.common.item.Items;
|
||||
import li.cil.oc2.common.util.ItemStackUtils;
|
||||
import net.minecraft.item.ItemModelsProperties;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
public final class CustomItemModelProperties {
|
||||
public static final ResourceLocation CAPACITY_PROPERTY = new ResourceLocation(API.MOD_ID, "capacity");
|
||||
public static final ResourceLocation COLOR_PROPERTY = new ResourceLocation(API.MOD_ID, "color");
|
||||
|
||||
private static final String COLOR_TAG_NAME = "color";
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void initialize() {
|
||||
ItemModelsProperties.registerProperty(Items.MEMORY.get(), CustomItemModelProperties.CAPACITY_PROPERTY,
|
||||
(stack, world, entity) -> AbstractStorageItem.getCapacity(stack));
|
||||
ItemModelsProperties.registerProperty(Items.HARD_DRIVE.get(), CustomItemModelProperties.CAPACITY_PROPERTY,
|
||||
(stack, world, entity) -> AbstractBlockDeviceItem.getData(stack) != null ? Integer.MAX_VALUE : AbstractStorageItem.getCapacity(stack));
|
||||
|
||||
ItemModelsProperties.registerProperty(Items.HARD_DRIVE.get(), CustomItemModelProperties.COLOR_PROPERTY,
|
||||
(stack, world, entity) -> CustomItemColors.getColor(stack));
|
||||
ItemModelsProperties.registerProperty(Items.FLOPPY.get(), CustomItemModelProperties.COLOR_PROPERTY,
|
||||
(stack, world, entity) -> getColor(stack));
|
||||
}
|
||||
|
||||
public static float getColor(final ItemStack stack) {
|
||||
final CompoundNBT modTag = ItemStackUtils.getModDataTag(stack);
|
||||
if (modTag == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return modTag.getInt("color");
|
||||
}
|
||||
|
||||
public static ItemStack withColor(final ItemStack stack, final TextFormatting color) {
|
||||
return withColor(stack, color.getColorIndex());
|
||||
}
|
||||
|
||||
public static ItemStack withColor(final ItemStack stack, final int color) {
|
||||
ItemStackUtils.getOrCreateModDataTag(stack).putInt(COLOR_TAG_NAME, color);
|
||||
return stack;
|
||||
(stack, world, entity) -> CustomItemColors.getColor(stack));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@ package li.cil.oc2.common.item;
|
||||
|
||||
import li.cil.oc2.common.Constants;
|
||||
import li.cil.oc2.common.bus.device.data.BlockDeviceDataRegistration;
|
||||
import net.minecraft.item.DyeColor;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
import static li.cil.oc2.client.item.CustomItemColors.withColor;
|
||||
|
||||
public final class HardDriveItem extends AbstractBlockDeviceItem {
|
||||
private static final int DEFAULT_CAPACITY = 2 * Constants.MEGABYTE;
|
||||
|
||||
@@ -20,10 +23,10 @@ public final class HardDriveItem extends AbstractBlockDeviceItem {
|
||||
@Override
|
||||
public void fillItemGroup(final ItemGroup group, final NonNullList<ItemStack> items) {
|
||||
if (isInGroup(group)) {
|
||||
items.add(withCapacity(2 * Constants.MEGABYTE));
|
||||
items.add(withCapacity(4 * Constants.MEGABYTE));
|
||||
items.add(withCapacity(8 * Constants.MEGABYTE));
|
||||
items.add(withData(BlockDeviceDataRegistration.BUILDROOT.get()));
|
||||
items.add(withColor(withCapacity(2 * Constants.MEGABYTE), DyeColor.LIGHT_GRAY));
|
||||
items.add(withColor(withCapacity(4 * Constants.MEGABYTE), DyeColor.GREEN));
|
||||
items.add(withColor(withCapacity(8 * Constants.MEGABYTE), DyeColor.CYAN));
|
||||
items.add(withColor(withData(BlockDeviceDataRegistration.BUILDROOT.get()), DyeColor.BROWN));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,15 +32,8 @@ public final class ModItemModelProvider extends ItemModelProvider {
|
||||
.predicate(CustomItemModelProperties.CAPACITY_PROPERTY, 8 * Constants.MEGABYTE)
|
||||
.model(simple(Items.MEMORY, "item/memory3", "3"))
|
||||
.end();
|
||||
simple(Items.HARD_DRIVE, "item/hard_drive1")
|
||||
.override()
|
||||
.predicate(CustomItemModelProperties.CAPACITY_PROPERTY, 4 * Constants.MEGABYTE)
|
||||
.model(simple(Items.HARD_DRIVE, "item/hard_drive2", "2"))
|
||||
.end()
|
||||
.override()
|
||||
.predicate(CustomItemModelProperties.CAPACITY_PROPERTY, 8 * Constants.MEGABYTE)
|
||||
.model(simple(Items.HARD_DRIVE, "item/hard_drive3", "3"))
|
||||
.end();
|
||||
simple(Items.HARD_DRIVE, "item/hard_drive_base")
|
||||
.texture("layer1", "item/hard_drive_tint");
|
||||
simple(Items.FLASH_MEMORY, "item/flash_memory");
|
||||
simple(Items.REDSTONE_INTERFACE_CARD, "item/redstone_interface_card");
|
||||
simple(Items.NETWORK_INTERFACE_CARD, "item/network_interface_card");
|
||||
|
||||
@@ -1,20 +1,7 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"parent": "minecraft:item/generated",
|
||||
"textures": {
|
||||
"layer0": "oc2:item/hard_drive1"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"oc2:capacity": 4194304.0
|
||||
},
|
||||
"model": "oc2:item/hard_drive2"
|
||||
},
|
||||
{
|
||||
"predicate": {
|
||||
"oc2:capacity": 8388608.0
|
||||
},
|
||||
"model": "oc2:item/hard_drive3"
|
||||
}
|
||||
]
|
||||
"layer0": "oc2:item/hard_drive_base",
|
||||
"layer1": "oc2:item/hard_drive_tint"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "oc2:item/hard_drive2"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "oc2:item/hard_drive3"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 425 B |
Binary file not shown.
|
Before Width: | Height: | Size: 429 B |
Binary file not shown.
|
Before Width: | Height: | Size: 429 B |
BIN
src/main/resources/assets/oc2/textures/item/hard_drive_base.png
Normal file
BIN
src/main/resources/assets/oc2/textures/item/hard_drive_base.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
BIN
src/main/resources/assets/oc2/textures/item/hard_drive_tint.png
Normal file
BIN
src/main/resources/assets/oc2/textures/item/hard_drive_tint.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
Reference in New Issue
Block a user