From da6a4c4145c266b20d9411524ee0906a78c719d7 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 23 Oct 2018 11:49:35 +0200 Subject: [PATCH] bucket of infinite colors, still needs recipe, doc, sounds and aura draining --- .../naturesaura/items/ItemColorChanger.java | 129 ++++++++++++++++++ .../ellpeck/naturesaura/items/ModItems.java | 1 + .../assets/naturesaura/lang/en_US.lang | 1 + .../models/item/color_changer.json | 20 +++ .../models/item/color_changer_fill_mode.json | 7 + .../models/item/color_changer_filled.json | 7 + .../textures/items/color_changer.png | Bin 0 -> 282 bytes .../items/color_changer_fill_mode.png | Bin 0 -> 284 bytes .../items/color_changer_fill_mode_overlay.png | Bin 0 -> 233 bytes .../textures/items/color_changer_overlay.png | Bin 0 -> 229 bytes 10 files changed, 165 insertions(+) create mode 100644 src/main/java/de/ellpeck/naturesaura/items/ItemColorChanger.java create mode 100644 src/main/resources/assets/naturesaura/models/item/color_changer.json create mode 100644 src/main/resources/assets/naturesaura/models/item/color_changer_fill_mode.json create mode 100644 src/main/resources/assets/naturesaura/models/item/color_changer_filled.json create mode 100644 src/main/resources/assets/naturesaura/textures/items/color_changer.png create mode 100644 src/main/resources/assets/naturesaura/textures/items/color_changer_fill_mode.png create mode 100644 src/main/resources/assets/naturesaura/textures/items/color_changer_fill_mode_overlay.png create mode 100644 src/main/resources/assets/naturesaura/textures/items/color_changer_overlay.png diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemColorChanger.java b/src/main/java/de/ellpeck/naturesaura/items/ItemColorChanger.java new file mode 100644 index 00000000..d384e700 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemColorChanger.java @@ -0,0 +1,129 @@ +package de.ellpeck.naturesaura.items; + +import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.reg.IColorProvidingItem; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.color.IItemColor; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumDyeColor; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.*; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemColorChanger extends ItemImpl implements IColorProvidingItem { + + public ItemColorChanger() { + super("color_changer"); + this.addPropertyOverride(new ResourceLocation(NaturesAura.MOD_ID, "fill_mode"), + (stack, worldIn, entityIn) -> isFillMode(stack) ? 1F : 0F); + this.addPropertyOverride(new ResourceLocation(NaturesAura.MOD_ID, "has_color"), + (stack, worldIn, entityIn) -> getStoredColor(stack) != null ? 1F : 0F); + } + + @Override + public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { + ItemStack stack = player.getHeldItem(hand); + if (changeOrCopyColor(player, stack, worldIn, pos, null)) { + return EnumActionResult.SUCCESS; + } else { + return EnumActionResult.PASS; + } + } + + private static boolean changeOrCopyColor(EntityPlayer player, ItemStack stack, World world, BlockPos pos, EnumDyeColor firstColor) { + IBlockState state = world.getBlockState(pos); + for (IProperty prop : state.getProperties().keySet()) { + if (prop.getValueClass() == EnumDyeColor.class) { + EnumDyeColor color = (EnumDyeColor) state.getValue(prop); + if (firstColor == null || color == firstColor) { + EnumDyeColor stored = getStoredColor(stack); + if (player.isSneaking()) { + if (stored != color) { + if (!world.isRemote) + storeColor(stack, color); + return true; + } + } else { + if (stored != null && stored != color) { + if (!world.isRemote) { + world.setBlockState(pos, state.withProperty(prop, stored)); + + if (isFillMode(stack)) { + for (EnumFacing off : EnumFacing.VALUES) { + changeOrCopyColor(player, stack, world, pos.offset(off), color); + } + } + } + return true; + } + } + } + } + } + return false; + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + if (playerIn.isSneaking() && getStoredColor(stack) != null) { + if (!worldIn.isRemote) { + setFillMode(stack, !isFillMode(stack)); + } + return new ActionResult<>(EnumActionResult.SUCCESS, stack); + } else { + return new ActionResult<>(EnumActionResult.PASS, stack); + } + } + + + private static EnumDyeColor getStoredColor(ItemStack stack) { + if (!stack.hasTagCompound()) { + return null; + } else { + int color = stack.getTagCompound().getInteger("color"); + return EnumDyeColor.byMetadata(color); + } + } + + private static void storeColor(ItemStack stack, EnumDyeColor color) { + if (!stack.hasTagCompound()) { + stack.setTagCompound(new NBTTagCompound()); + } + stack.getTagCompound().setInteger("color", color.getMetadata()); + } + + private static boolean isFillMode(ItemStack stack) { + if (!stack.hasTagCompound()) { + return false; + } else { + return stack.getTagCompound().getBoolean("fill"); + } + } + + private static void setFillMode(ItemStack stack, boolean fill) { + if (!stack.hasTagCompound()) { + stack.setTagCompound(new NBTTagCompound()); + } + stack.getTagCompound().setBoolean("fill", fill); + } + + @Override + @SideOnly(Side.CLIENT) + public IItemColor getItemColor() { + return (stack, tintIndex) -> { + if (tintIndex > 0) { + EnumDyeColor color = getStoredColor(stack); + if (color != null) { + return color.getColorValue(); + } + } + return 0xFFFFFF; + }; + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/items/ModItems.java b/src/main/java/de/ellpeck/naturesaura/items/ModItems.java index 9d626815..c077928f 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ModItems.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ModItems.java @@ -14,6 +14,7 @@ public final class ModItems { public static final Item GOLD_LEAF = new ItemImpl("gold_leaf"); public static final Item INFUSED_IRON = new ItemImpl("infused_iron"); public static final Item ANCIENT_STICK = new ItemImpl("ancient_stick"); + public static final Item COLOR_CHANGER = new ItemColorChanger(); public static final Item.ToolMaterial TOOL_MATERIAL_INFUSED_IRON = EnumHelper.addToolMaterial(NaturesAura.MOD_ID.toUpperCase(Locale.ROOT) + "_INFUSED_IRON", 3, 300, 6.25F, 2.25F, 16); diff --git a/src/main/resources/assets/naturesaura/lang/en_US.lang b/src/main/resources/assets/naturesaura/lang/en_US.lang index c5815cc8..ce70283f 100644 --- a/src/main/resources/assets/naturesaura/lang/en_US.lang +++ b/src/main/resources/assets/naturesaura/lang/en_US.lang @@ -23,6 +23,7 @@ item.naturesaura.infused_iron_sword.name=Botanist's Blade item.naturesaura.infused_iron_hoe.name=Botanist's Hoe item.naturesaura.ancient_stick.name=Ancient Wood Rod item.naturesaura.aura_cache.name=Aura Cache +item.naturesaura.color_changer.name=Bucket of Infinite Colors container.naturesaura.tree_ritual.name=Ritual of the Forest container.naturesaura.altar.name=Natural Altar Infusion diff --git a/src/main/resources/assets/naturesaura/models/item/color_changer.json b/src/main/resources/assets/naturesaura/models/item/color_changer.json new file mode 100644 index 00000000..e3ecb252 --- /dev/null +++ b/src/main/resources/assets/naturesaura/models/item/color_changer.json @@ -0,0 +1,20 @@ +{ + "parent": "item/handheld", + "textures": { + "layer0": "naturesaura:items/color_changer" + }, + "overrides": [ + { + "predicate": { + "naturesaura:has_color": 1 + }, + "model": "naturesaura:item/color_changer_filled" + }, + { + "predicate": { + "naturesaura:fill_mode": 1 + }, + "model": "naturesaura:item/color_changer_fill_mode" + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/models/item/color_changer_fill_mode.json b/src/main/resources/assets/naturesaura/models/item/color_changer_fill_mode.json new file mode 100644 index 00000000..b5f9ddb3 --- /dev/null +++ b/src/main/resources/assets/naturesaura/models/item/color_changer_fill_mode.json @@ -0,0 +1,7 @@ +{ + "parent": "item/handheld", + "textures": { + "layer0": "naturesaura:items/color_changer_fill_mode", + "layer1": "naturesaura:items/color_changer_fill_mode_overlay" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/models/item/color_changer_filled.json b/src/main/resources/assets/naturesaura/models/item/color_changer_filled.json new file mode 100644 index 00000000..8c74c5b4 --- /dev/null +++ b/src/main/resources/assets/naturesaura/models/item/color_changer_filled.json @@ -0,0 +1,7 @@ +{ + "parent": "item/handheld", + "textures": { + "layer0": "naturesaura:items/color_changer", + "layer1": "naturesaura:items/color_changer_overlay" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/textures/items/color_changer.png b/src/main/resources/assets/naturesaura/textures/items/color_changer.png new file mode 100644 index 0000000000000000000000000000000000000000..b94c2fbcf716367f475bc47b46efb3e7aaba050c GIT binary patch literal 282 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=Dj`K$uZ}o?v(;)J1ZE@ns1g<=qVn7!??d zS*9~qm^L%$g$txwa|Glta4cX~+r-EM6gt5$A!!Dq!C4n+1}25p8wMe>W;HZ2GVn^A VnHSL7#R7CAgQu&X%Q~loCICiiRt^9F literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/naturesaura/textures/items/color_changer_fill_mode.png b/src/main/resources/assets/naturesaura/textures/items/color_changer_fill_mode.png new file mode 100644 index 0000000000000000000000000000000000000000..b9a9cfd33f1dee89bf4a8bbaf025dad6282ce9ba GIT binary patch literal 284 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=Dj`L74IQk1J+CL5ULAh?3y^w370~qEv>0#LT=By}Z;C1rt3(J;P+JIo?1uvpiiK zLoEE0C2AZlggvphYV#6gbNaUEf9R{N|36D||C`=5tvPuSZ?hzWv5T26XU|4SwyRAH zCuUvbJJe24L3<_`tBgHp3xw^=}3Z9Nt#r%VH|UU z)I`(8*(`|@Y}yzV7%s7N>!sYDxN*jM5eet53z%jwzL=Fbt02pTP2ubbsg6q~4GoQq Z4870K%sbT3a|7r~22WQ%mvv4FO#q?yVL<=@ literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/naturesaura/textures/items/color_changer_fill_mode_overlay.png b/src/main/resources/assets/naturesaura/textures/items/color_changer_fill_mode_overlay.png new file mode 100644 index 0000000000000000000000000000000000000000..670804b09167840391e61b461b5f172762687ac0 GIT binary patch literal 233 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=DibL6~s|oA`d9phSslL`iUdT1k0gQ7S`0VrE{6US4X6f{C7?o?)`q9B-hSbWaz@ z5DWji6EE@}P~c#_Td%z>L3$ONP#mN3%Xm+}rvX0`I!>qu-Bg?^+m!HZ=R#}2BflCt zo(a~ns@%HElqEVLBV9h=e8ZD^d55)!)T?Xqg!Y9cwg0^lP<}M(o}k`bkJR>%d&-X) YpIAzKeDro}1kg$bPgg&ebxsLQ0Oj;g0{{R3 literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/naturesaura/textures/items/color_changer_overlay.png b/src/main/resources/assets/naturesaura/textures/items/color_changer_overlay.png new file mode 100644 index 0000000000000000000000000000000000000000..e5734134f89fab6bfad62ef26f8fec053652d798 GIT binary patch literal 229 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=Dj`L74IQk1J+CL5ULAh?3y^w370~qEv>0#LT=By}Z;C1rt3(J;P+JIo?1u$(}Bb zAr}5iCmiHFV8Fw?`G43wrQ179w**9H1qB|otr4rMNO`8eq-4S+$5S0A&dvE8Qz+i% z9=NRRuYk;s8?3(!OsYbTS3Q#bV34z7g8Ie