diff options
| author | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2014-04-15 22:41:43 +0300 |
|---|---|---|
| committer | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2014-04-15 22:41:43 +0300 |
| commit | 4b8b13b34d7a8fd0ee7c7b13f11be9c2bf3b5d18 (patch) | |
| tree | b49bc483d576ec3abeb2e18523e4511ecce353d3 /eclipse/Jewelrycraft/common/darkknight/jewelrycraft/events | |
| parent | 86398ed60db321f86e8d98f191107fdac2c93760 (diff) | |
More 1.7 stuff
Diffstat (limited to 'eclipse/Jewelrycraft/common/darkknight/jewelrycraft/events')
| -rw-r--r-- | eclipse/Jewelrycraft/common/darkknight/jewelrycraft/events/BucketHandler.java | 55 | ||||
| -rw-r--r-- | eclipse/Jewelrycraft/common/darkknight/jewelrycraft/events/EntityEventHandler.java | 63 |
2 files changed, 91 insertions, 27 deletions
diff --git a/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/events/BucketHandler.java b/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/events/BucketHandler.java new file mode 100644 index 0000000..64a02c3 --- /dev/null +++ b/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/events/BucketHandler.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public License + * 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package darkknight.jewelrycraft.events; + +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.player.FillBucketEvent; +import cpw.mods.fml.common.eventhandler.Event.Result; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; + +public class BucketHandler { + + public static BucketHandler INSTANCE = new BucketHandler(); + public Map<Block, Item> buckets = new HashMap<Block, Item>(); + + private BucketHandler() { + } + + @SubscribeEvent + public void onBucketFill(FillBucketEvent event) { + + ItemStack result = fillCustomBucket(event.world, event.target); + + if (result == null) + return; + + event.result = result; + event.setResult(Result.ALLOW); + } + + + private ItemStack fillCustomBucket(World world, MovingObjectPosition pos) { + + Block block = world.getBlock(pos.blockX, pos.blockY, pos.blockZ); + + Item bucket = buckets.get(block); + if (bucket != null && world.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ) == 0) { + world.setBlockToAir(pos.blockX, pos.blockY, pos.blockZ); + return new ItemStack(bucket); + } else + return null; + + } +}
\ No newline at end of file diff --git a/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/events/EntityEventHandler.java b/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/events/EntityEventHandler.java index acc37cf..d8d49a2 100644 --- a/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/events/EntityEventHandler.java +++ b/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/events/EntityEventHandler.java @@ -1,46 +1,55 @@ package darkknight.jewelrycraft.events; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; + import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.WorldServer; import net.minecraftforge.event.entity.EntityJoinWorldEvent; +import net.minecraftforge.event.world.WorldEvent; +import darkknight.jewelrycraft.JewelrycraftMod; import darkknight.jewelrycraft.item.ItemList; import darkknight.jewelrycraft.util.BlockUtils; import darkknight.jewelrycraft.util.PlayerUtils; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; /** * Code taken from OpenBlocks */ public class EntityEventHandler { + public static final String OPENBLOCKS_PERSIST_TAG = "Jewelrycraft"; + public static final String GIVEN_GUIDE_TAG = "givenGuive"; - public static final String OPENBLOCKS_PERSIST_TAG = "Jewelrycraft"; - public static final String GIVEN_GUIDE_TAG = "givenGuive"; - - public void onEntityJoinWorld(EntityJoinWorldEvent event) - { - - final Entity entity = event.entity; - /** - * If the player hasn't been given a manual, we'll give him one! (or - * throw it on the floor..) - */ - if (!event.world.isRemote && entity instanceof EntityPlayer) - { - EntityPlayer player = (EntityPlayer)entity; - NBTTagCompound persistTag = PlayerUtils.getModPlayerPersistTag(player, "Jewelrycraft"); + @SubscribeEvent + public void onEntityJoinWorld(EntityJoinWorldEvent event) + { + final Entity entity = event.entity; + /** + * If the player hasn't been given a manual, we'll give him one! (or + * throw it on the floor..) + */ + if (!event.world.isRemote && entity instanceof EntityPlayer) + { + EntityPlayer player = (EntityPlayer)entity; + NBTTagCompound persistTag = PlayerUtils.getModPlayerPersistTag(player, "Jewelrycraft"); - boolean shouldGiveManual = ItemList.guide != null && !persistTag.getBoolean(GIVEN_GUIDE_TAG); - if (shouldGiveManual) - { - ItemStack manual = new ItemStack(ItemList.guide); - if (!player.inventory.addItemStackToInventory(manual)) - { - BlockUtils.dropItemStackInWorld(player.worldObj, player.posX, player.posY, player.posZ, manual); - } - persistTag.setBoolean(GIVEN_GUIDE_TAG, true); - } - } - } + boolean shouldGiveManual = ItemList.guide != null && !persistTag.getBoolean(GIVEN_GUIDE_TAG); + if (shouldGiveManual) + { + ItemStack manual = new ItemStack(ItemList.guide); + if (!player.inventory.addItemStackToInventory(manual)) + { + BlockUtils.dropItemStackInWorld(player.worldObj, player.posX, player.posY, player.posZ, manual); + } + persistTag.setBoolean(GIVEN_GUIDE_TAG, true); + } + } + } }
\ No newline at end of file |
