From 78af31e8abb081c56d2523ca4933572163008a00 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 16 Nov 2018 13:06:33 +0100 Subject: [PATCH] added the ability to automate aura bottles --- .../naturesaura/items/ItemAuraBottle.java | 25 +++++++++++++++++++ .../en_us/entries/collecting/aura_bottle.json | 4 +++ 2 files changed, 29 insertions(+) diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemAuraBottle.java b/src/main/java/de/ellpeck/naturesaura/items/ItemAuraBottle.java index f5a3b256..d4eb70a9 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ItemAuraBottle.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemAuraBottle.java @@ -4,19 +4,25 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.reg.IColorProvidingItem; +import net.minecraft.block.BlockDispenser; +import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.color.IItemColor; import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.dispenser.BehaviorDefaultDispenseItem; +import net.minecraft.dispenser.IBlockSource; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.init.SoundEvents; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.text.translation.I18n; +import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -28,6 +34,25 @@ public class ItemAuraBottle extends ItemImpl implements IColorProvidingItem { public ItemAuraBottle() { super("aura_bottle"); MinecraftForge.EVENT_BUS.register(this); + + BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(Items.GLASS_BOTTLE, new BehaviorDefaultDispenseItem() { + @Override + protected ItemStack dispenseStack(IBlockSource source, ItemStack stack) { + World world = source.getWorld(); + IBlockState state = source.getBlockState(); + EnumFacing facing = state.getValue(BlockDispenser.FACING); + BlockPos offset = source.getBlockPos().offset(facing); + IBlockState offsetState = world.getBlockState(offset); + + ItemStack dispense = stack.splitStack(1); + if (offsetState.getBlock().isAir(offsetState, world, offset)) { + dispense = setType(new ItemStack(ItemAuraBottle.this), IAuraType.forWorld(world)); + } + + doDispense(world, dispense, 6, facing, BlockDispenser.getDispensePosition(source)); + return stack; + } + }); } @SubscribeEvent diff --git a/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/collecting/aura_bottle.json b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/collecting/aura_bottle.json index 1e1b5672..ba0b3e72 100644 --- a/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/collecting/aura_bottle.json +++ b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/collecting/aura_bottle.json @@ -13,6 +13,10 @@ "item": "naturesaura:aura_bottle{stored_type:'naturesaura:overworld'}", "link_recipe": true, "text": "Of course, based on the world that you are currently in, the type of $(aura) collected will slightly vary. For instance, in the normal world, $(aura) can be gathered in the form of sunlight, while in the Nether realm, $(aura) can be gathered in the form of ghosts." + }, + { + "type": "text", + "text": "Additionally, the collection of $(aura) in this manner can be automated easily using $(item)Dispensers$(): Putting empty bottles into them will cause them to be shot out with the cork slightly unscrewed, making them fill up with $(aura) in the process. As they are not sucked up by the Dispenser again afterwards, an additional tool like a $(item)Hopper$() is required." } ] } \ No newline at end of file