From bd81afa74e4878a2d25ce74086b9fc86ffe64456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Wed, 27 Jan 2021 18:14:47 +0100 Subject: [PATCH] Made hard drives have customizable color. --- .../cil/oc2/client/item/CustomItemColors.java | 7 +++- .../item/CustomItemModelProperties.java | 31 ++---------------- .../li/cil/oc2/common/item/HardDriveItem.java | 11 ++++--- .../li/cil/oc2/data/ModItemModelProvider.java | 11 ++----- .../assets/oc2/models/item/hard_drive.json | 21 +++--------- .../assets/oc2/models/item/hard_drive2.json | 6 ---- .../assets/oc2/models/item/hard_drive3.json | 6 ---- .../assets/oc2/textures/item/hard_drive1.png | Bin 425 -> 0 bytes .../assets/oc2/textures/item/hard_drive2.png | Bin 429 -> 0 bytes .../assets/oc2/textures/item/hard_drive3.png | Bin 429 -> 0 bytes .../oc2/textures/item/hard_drive_base.png | Bin 0 -> 2103 bytes .../oc2/textures/item/hard_drive_tint.png | Bin 0 -> 2175 bytes 12 files changed, 22 insertions(+), 71 deletions(-) delete mode 100644 src/main/resources/assets/oc2/models/item/hard_drive2.json delete mode 100644 src/main/resources/assets/oc2/models/item/hard_drive3.json delete mode 100644 src/main/resources/assets/oc2/textures/item/hard_drive1.png delete mode 100644 src/main/resources/assets/oc2/textures/item/hard_drive2.png delete mode 100644 src/main/resources/assets/oc2/textures/item/hard_drive3.png create mode 100644 src/main/resources/assets/oc2/textures/item/hard_drive_base.png create mode 100644 src/main/resources/assets/oc2/textures/item/hard_drive_tint.png diff --git a/src/main/java/li/cil/oc2/client/item/CustomItemColors.java b/src/main/java/li/cil/oc2/client/item/CustomItemColors.java index c93e54a6..93745196 100644 --- a/src/main/java/li/cil/oc2/client/item/CustomItemColors.java +++ b/src/main/java/li/cil/oc2/client/item/CustomItemColors.java @@ -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; diff --git a/src/main/java/li/cil/oc2/client/item/CustomItemModelProperties.java b/src/main/java/li/cil/oc2/client/item/CustomItemModelProperties.java index e15f6e2c..5809f557 100644 --- a/src/main/java/li/cil/oc2/client/item/CustomItemModelProperties.java +++ b/src/main/java/li/cil/oc2/client/item/CustomItemModelProperties.java @@ -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)); } } diff --git a/src/main/java/li/cil/oc2/common/item/HardDriveItem.java b/src/main/java/li/cil/oc2/common/item/HardDriveItem.java index b07880c8..50b44355 100644 --- a/src/main/java/li/cil/oc2/common/item/HardDriveItem.java +++ b/src/main/java/li/cil/oc2/common/item/HardDriveItem.java @@ -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 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)); } } } diff --git a/src/main/java/li/cil/oc2/data/ModItemModelProvider.java b/src/main/java/li/cil/oc2/data/ModItemModelProvider.java index ca8a2098..dbe9055d 100644 --- a/src/main/java/li/cil/oc2/data/ModItemModelProvider.java +++ b/src/main/java/li/cil/oc2/data/ModItemModelProvider.java @@ -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"); diff --git a/src/main/resources/assets/oc2/models/item/hard_drive.json b/src/main/resources/assets/oc2/models/item/hard_drive.json index 91c512ab..327b1241 100644 --- a/src/main/resources/assets/oc2/models/item/hard_drive.json +++ b/src/main/resources/assets/oc2/models/item/hard_drive.json @@ -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" + } } \ No newline at end of file diff --git a/src/main/resources/assets/oc2/models/item/hard_drive2.json b/src/main/resources/assets/oc2/models/item/hard_drive2.json deleted file mode 100644 index 39ce7a99..00000000 --- a/src/main/resources/assets/oc2/models/item/hard_drive2.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "minecraft:item/handheld", - "textures": { - "layer0": "oc2:item/hard_drive2" - } -} \ No newline at end of file diff --git a/src/main/resources/assets/oc2/models/item/hard_drive3.json b/src/main/resources/assets/oc2/models/item/hard_drive3.json deleted file mode 100644 index 2bc764f6..00000000 --- a/src/main/resources/assets/oc2/models/item/hard_drive3.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "minecraft:item/handheld", - "textures": { - "layer0": "oc2:item/hard_drive3" - } -} \ No newline at end of file diff --git a/src/main/resources/assets/oc2/textures/item/hard_drive1.png b/src/main/resources/assets/oc2/textures/item/hard_drive1.png deleted file mode 100644 index ef3ca624617161b16eb8fab838af96378bbd8f15..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 425 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!WQl7;NpOBzNqJ&XDuZK6ep0G} zXKrG8YEWuoN@d~6R2!h8#sHrX*Z=?j^YQV?%F6!u@x##2(8$Q>&Ye5=@87q!wqCbx zotc@Ll$6xIefzw| zMkYBqxwW-*)22;x=FHL4(_6DDb%DO()LhUMlg`caC(vM?f3tg zoLSRe&3<_Nx6Fgj<{Q>`zdhycEyezE^9g>=xhx+ym>zht@Q$<(!|k1Hhi&G(iOoJ0 z$9V1k6xm?@*p1&KtulTdUZZQo-g3Vp>N*p%&S3?qP6^8s&%WPSJVlG4@2}`ou7dTe iGNj8tY+ld6%rH|{@^04RrhPysF?hQAxvXb^4o! zTeMWT-K>S~pQ#J;6st;?`~CCN%|k(P0TQ;RBIf#hukNmDEmXX5FvVDh_uNJ|HASum z=UVjCdFFIzc-jeD81T7R2|c?$=kCc$T{RvH1EI&4C*3}l_u|%~{1|Cf1uiKuwv+$~ zpaXuLbe{)wk4{ODUoenMEMPc(jk5=+uiewdF{I*F%&C_`O$s7y50zz3x|p3cJ?nM* z{r`VXtZA=iKRo_h=D}z44eR^gep;!vwE0J<%5Pa&mX90E4m?o2FBQUYyOZsx&73!} z*{9wyPWwMa)`-7$P2!7 kE^fQHYkTwjT2={$bCFUxZ(j1B2Rezt)78&qol`;+0C|bWw*UYD diff --git a/src/main/resources/assets/oc2/textures/item/hard_drive3.png b/src/main/resources/assets/oc2/textures/item/hard_drive3.png deleted file mode 100644 index fcaffb1e47a5125ffc1c9e3b816039d604d98e45..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 429 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!WQl7;NpOBzNqJ&XDuZK6ep0G} zXKrG8YEWuoN@d~6R2!h8mH?j+*Z=?jvx|s)`Tbi!OIz8|Ny^RR(%biEUccS-^ckO; zx*Guo6CUVj;>Vt_moRnKqoPHy85}Sb4q9e01#=&F8}}l diff --git a/src/main/resources/assets/oc2/textures/item/hard_drive_base.png b/src/main/resources/assets/oc2/textures/item/hard_drive_base.png new file mode 100644 index 0000000000000000000000000000000000000000..21f3fd7a3ebd0739e53fa8c98679125eba00e3a6 GIT binary patch literal 2103 zcmah~c~BE)6kiG|qE@6jb*!Utv1-+1lRyx*2{a@T7)XqW5D>v7yGgb=HtcRlU|Pqf z+Jb^st+azUPMIEv7g{ZhR!}^OiYKi{#}O5$RE1_BoyyRT^xFhEMB6_$+4ue4`@Q$Q zYfH46gh?SYLLdm5l$5AU1^=Pk6Fe6D&i3|W5Hw~PnWkfP>J(H@Sp^tQ3+G13$wpWS*`wWb*pv6H5gV^01`J)gb^`4 zcfh0-+6g3;U?>NzCsYL>9pS#rad||OteBBVA#6t0B!fj!F8~=N{^B`DWN~nnTWKSK zYw?hYZU~dXOT?gOxO)2BWWE&QQjKa!7h%yUNl+&SuntBs1ZKVhR8SU*UIE5{07gDv zgLOcCn3}=?6!8L-q)=#S%0OBG#-t|1^O97GC{avQ6kjax(}1F(z?L)=DlryliG^Yj zUnt^>m!yfJQDF=k5wS=pLWTYd`n199;24YjpFTGMJSnb6S(3F7KFL23atrI1{Gx^A z#sIZoHlqx7@o~a{IV>z3Yr<$e7pKVrLW*#MV<87PeA06gDKf%?6hx?2qlqNLQgq=k zrz?p3kxqT{$K(0B3dQtXm1VGCqDwn2cM{|sy-9kxMyQb=_O={TxYkq%LE1jKj^7;a4 zO?6g|E7esbIau){|IW8xS6yuSuF0krEcn3u_)u8mmz9gVzc`;2JsmP{s$G7b`+#f^hY<&i=NB$0c%V&#}{!CoTJ=`$pgo{NB5frB@WE zdt=?l66%}Ndzf*;e*}F7)sws9I?&41=|^t8UP-<8_s27SscKB!m12ei4$i+i^P?N) zTBN)vJ+`BFR+G7BWk&7saVNq&*?j>87mQtx%<0@0aJ)S+lYyWKZ*WflR8ct{ln6>v z%G09DE^U)-c5A0@h&!;p>D=ZS<@e}2uT97coVRb?nx8@vO`T=m-1kW0bLQO46K{wW zZhvQB%F2h?y>&XXV`f6vG0onZ>ylk{hK4pzaWLeSGAD9wd!BC2DQ{_woC8Oy zPj?jr@;1UfQfEbUKwG3*QBHhLloa19oVD}Pxoa^2t&!a>X|Q{paN=!SU2ntWlfsFb zb^UAWvju1JTWodh_UO={fSTM(Wg_#2+&xdS%0%y%UTg3iwXRaPviT)vr$HO5t~Pk4 zOeq!3O*&lTsJ(IEk7t)3lzOG!M}@ItE3X*$9aSzr^N8)s-~MKg^k#c^@4MdJ-k{&+ Vy4QcmC)>F1eUeI}JP^Oe{V%1<@}K|! literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/oc2/textures/item/hard_drive_tint.png b/src/main/resources/assets/oc2/textures/item/hard_drive_tint.png new file mode 100644 index 0000000000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