From 48a48d277f973fd6dc351519a6e6a072c06ed03d Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 23 Oct 2018 19:23:02 +0200 Subject: [PATCH] finish the bucket of whateveritscalled --- .../java/de/ellpeck/naturesaura/Helper.java | 30 +++++++++++++++++++ .../naturesaura/items/ItemColorChanger.java | 25 ++++++++++++---- .../assets/naturesaura/lang/en_US.lang | 2 +- .../en_us/entries/items/color_changer.json | 21 +++++++++++++ .../naturesaura/recipes/color_changer.json | 28 +++++++++++++++++ 5 files changed, 99 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/assets/naturesaura/patchouli_books/en_us/entries/items/color_changer.json create mode 100644 src/main/resources/assets/naturesaura/recipes/color_changer.json diff --git a/src/main/java/de/ellpeck/naturesaura/Helper.java b/src/main/java/de/ellpeck/naturesaura/Helper.java index c1ab3a21..4ee568f9 100644 --- a/src/main/java/de/ellpeck/naturesaura/Helper.java +++ b/src/main/java/de/ellpeck/naturesaura/Helper.java @@ -1,8 +1,10 @@ package de.ellpeck.naturesaura; +import baubles.api.BaublesApi; import de.ellpeck.naturesaura.aura.Capabilities; import de.ellpeck.naturesaura.aura.item.IAuraRecharge; import de.ellpeck.naturesaura.blocks.tiles.TileEntityImpl; +import de.ellpeck.naturesaura.compat.Compat; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; @@ -19,6 +21,7 @@ import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandlerModifiable; import org.lwjgl.opengl.GL11; @@ -150,4 +153,31 @@ public final class Helper { } }; } + + public static boolean extractAuraFromPlayer(EntityPlayer player, int amount, boolean simulate) { + if (Compat.baubles) { + IItemHandler baubles = BaublesApi.getBaublesHandler(player); + for (int i = 0; i < baubles.getSlots(); i++) { + ItemStack stack = baubles.getStackInSlot(i); + if (!stack.isEmpty() && stack.hasCapability(Capabilities.auraContainer, null)) { + amount -= stack.getCapability(Capabilities.auraContainer, null).drainAura(amount, simulate); + if (amount <= 0) { + return true; + } + } + } + } + + for (int i = 0; i < player.inventory.getSizeInventory(); i++) { + ItemStack stack = player.inventory.getStackInSlot(i); + if (!stack.isEmpty() && stack.hasCapability(Capabilities.auraContainer, null)) { + amount -= stack.getCapability(Capabilities.auraContainer, null).drainAura(amount, simulate); + if (amount <= 0) { + return true; + } + } + } + + return false; + } } diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemColorChanger.java b/src/main/java/de/ellpeck/naturesaura/items/ItemColorChanger.java index d384e700..7510e7b6 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ItemColorChanger.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemColorChanger.java @@ -1,11 +1,13 @@ package de.ellpeck.naturesaura.items; +import de.ellpeck.naturesaura.Helper; 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.init.SoundEvents; import net.minecraft.item.EnumDyeColor; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -19,6 +21,8 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem { public ItemColorChanger() { super("color_changer"); + this.setMaxStackSize(1); + 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"), @@ -44,22 +48,30 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem { EnumDyeColor stored = getStoredColor(stack); if (player.isSneaking()) { if (stored != color) { + world.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, + SoundEvents.ITEM_BUCKET_FILL, SoundCategory.PLAYERS, 0.65F, 1F); 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 (Helper.extractAuraFromPlayer(player, 10, world.isRemote)) { + if (firstColor == null) { + world.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, + SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.PLAYERS, 0.65F, 1F); + } + 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); + if (isFillMode(stack)) { + for (EnumFacing off : EnumFacing.VALUES) { + changeOrCopyColor(player, stack, world, pos.offset(off), color); + } } } + return true; } - return true; } } } @@ -72,6 +84,7 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem { public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { ItemStack stack = playerIn.getHeldItem(handIn); if (playerIn.isSneaking() && getStoredColor(stack) != null) { + worldIn.playSound(playerIn, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ITEM_BUCKET_FILL_LAVA, SoundCategory.PLAYERS, 0.65F, 1F); if (!worldIn.isRemote) { setFillMode(stack, !isFillMode(stack)); } diff --git a/src/main/resources/assets/naturesaura/lang/en_US.lang b/src/main/resources/assets/naturesaura/lang/en_US.lang index ce70283f..9675a953 100644 --- a/src/main/resources/assets/naturesaura/lang/en_US.lang +++ b/src/main/resources/assets/naturesaura/lang/en_US.lang @@ -23,7 +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 +item.naturesaura.color_changer.name=Bucket of Infinite Color container.naturesaura.tree_ritual.name=Ritual of the Forest container.naturesaura.altar.name=Natural Altar Infusion diff --git a/src/main/resources/assets/naturesaura/patchouli_books/en_us/entries/items/color_changer.json b/src/main/resources/assets/naturesaura/patchouli_books/en_us/entries/items/color_changer.json new file mode 100644 index 00000000..90d67ec3 --- /dev/null +++ b/src/main/resources/assets/naturesaura/patchouli_books/en_us/entries/items/color_changer.json @@ -0,0 +1,21 @@ +{ + "name": "Bucket of Infinite Color", + "icon": "naturesaura:color_changer", + "category": "naturesaura:items", + "advancement": "naturesaura:infused_materials", + "pages": [ + { + "type": "text", + "text": "Using $(thing)colors$() as a means of making buildings look nice is a recognized technique among builders. However, sometimes it can be difficult to find all the colors one requires. The $(item)Bucket of Infinite Colors$(), merely using the three primary shades of the world, can create any color so long as it came in contact with them, and then tranfer it onto any dyeable block." + }, + { + "type": "text", + "text": "To use the bucket, simply sneak and interact with any dyeable block. To then transfer that color onto a block, simply interact with it.$(br)Sneaking and interacting with the item itself will cause it to switch into $(thing)fill mode$(), meaning that, upon dyeing a block, all surrounding blocks with the same color will also be changed.$(br)Of course, this comes with the cost of some $(thing)Aura$(), which needs to be supplied in the form of an $(l:naturesaura:items/aura_cache)Aura Cache$() in one's inventory." + }, + { + "type": "crafting", + "text": "Creating the $(item)Bucket of Infinite Color$()", + "recipe": "naturesaura:color_changer" + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/recipes/color_changer.json b/src/main/resources/assets/naturesaura/recipes/color_changer.json new file mode 100644 index 00000000..8b8b6b3a --- /dev/null +++ b/src/main/resources/assets/naturesaura/recipes/color_changer.json @@ -0,0 +1,28 @@ +{ + "type": "forge:ore_shaped", + "pattern": [ + "RYB", + "I I", + " I " + ], + "key": { + "I": { + "item": "naturesaura:infused_iron" + }, + "R": { + "type": "forge:ore_dict", + "ore": "dyeRed" + }, + "Y": { + "type": "forge:ore_dict", + "ore": "dyeYellow" + }, + "B": { + "type": "forge:ore_dict", + "ore": "dyeBlue" + } + }, + "result": { + "item": "naturesaura:color_changer" + } +} \ No newline at end of file