From 67b4b7f9b1735fbd62348eb36daf68691724e4bf Mon Sep 17 00:00:00 2001 From: Nicholas Ignoffo Date: Fri, 15 Dec 2017 00:10:13 -0800 Subject: [PATCH] More Sigil work --- .../core/RegistrarBloodMagicItems.java | 11 +- .../item/sigil/ItemSigilGreenGrove.java | 94 ------------ .../bloodmagic/item/sigil/ItemSigilHaste.java | 22 --- .../bloodmagic/item/sigil/ItemSigilLava.java | 115 -------------- .../item/sigil/ItemSigilTeleposition.java | 90 ----------- .../item/sigil/ItemSigilTransposition.java | 143 ----------------- .../bloodmagic/item/sigil/ItemSigilWater.java | 132 ---------------- .../sigil/sigil/ItemSigilTeleposition.java | 90 +++++++++++ .../sigil/sigil/ItemSigilTransposition.java | 145 ++++++++++++++++++ .../item/sigil/sigil/SigilFluid.java | 79 ++++++++++ .../item/sigil/sigil/SigilGreenGrove.java | 91 +++++++++++ .../item/sigil/sigil/SigilHaste.java | 22 +++ .../util/handler/event/GenericHandler.java | 51 ++++-- .../bloodmagic/blockstates/sigil_lava.json | 10 +- .../blockstates/sigil_teleposition.json | 10 +- .../blockstates/sigil_transposition.json | 10 +- .../bloodmagic/blockstates/sigil_water.json | 10 +- 17 files changed, 485 insertions(+), 640 deletions(-) delete mode 100644 src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilGreenGrove.java delete mode 100644 src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilHaste.java delete mode 100644 src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilLava.java delete mode 100644 src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilTeleposition.java delete mode 100644 src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilTransposition.java delete mode 100644 src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilWater.java create mode 100644 src/main/java/WayofTime/bloodmagic/item/sigil/sigil/ItemSigilTeleposition.java create mode 100644 src/main/java/WayofTime/bloodmagic/item/sigil/sigil/ItemSigilTransposition.java create mode 100644 src/main/java/WayofTime/bloodmagic/item/sigil/sigil/SigilFluid.java create mode 100644 src/main/java/WayofTime/bloodmagic/item/sigil/sigil/SigilGreenGrove.java create mode 100644 src/main/java/WayofTime/bloodmagic/item/sigil/sigil/SigilHaste.java diff --git a/src/main/java/WayofTime/bloodmagic/core/RegistrarBloodMagicItems.java b/src/main/java/WayofTime/bloodmagic/core/RegistrarBloodMagicItems.java index f43433ee..79f1dcd3 100644 --- a/src/main/java/WayofTime/bloodmagic/core/RegistrarBloodMagicItems.java +++ b/src/main/java/WayofTime/bloodmagic/core/RegistrarBloodMagicItems.java @@ -16,6 +16,8 @@ import WayofTime.bloodmagic.item.routing.ItemNodeRouter; import WayofTime.bloodmagic.item.routing.ItemRouterFilter; import WayofTime.bloodmagic.item.sigil.*; import WayofTime.bloodmagic.item.sigil.sigil.*; +import WayofTime.bloodmagic.item.sigil.sigil.ItemSigilTeleposition; +import WayofTime.bloodmagic.item.sigil.sigil.ItemSigilTransposition; import WayofTime.bloodmagic.item.soul.*; import WayofTime.bloodmagic.item.types.ComponentType; import WayofTime.bloodmagic.item.types.ReagentType; @@ -29,6 +31,7 @@ import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.common.util.EnumHelper; +import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -144,15 +147,15 @@ public class RegistrarBloodMagicItems { new ItemBoundShovel().setRegistryName("bound_shovel"), new ItemSigilDivination().setRegistryName("sigil_divination"), new ItemSigil(new SigilAir(), "air").setRegistryName("sigil_air"), - new ItemSigilWater().setRegistryName("sigil_water"), - new ItemSigilLava().setRegistryName("sigil_lava"), + new ItemSigil(new SigilFluid(FluidRegistry.WATER), "water").setRegistryName("sigil_water"), + new ItemSigil(new SigilFluid(FluidRegistry.LAVA), "lava").setRegistryName("sigil_lava"), new ItemSigilVoid().setRegistryName("sigil_void"), - new ItemSigilGreenGrove().setRegistryName("sigil_green_grove"), + new ItemSigil(new SigilGreenGrove(), "green_grove").setRegistryName("sigil_green_grove"), new ItemSigil(new SigilBloodLight(), "blood_light").setRegistryName("sigil_blood_light"), new ItemSigil(new SigilElementalAffinity(), "elemental_affinity").setRegistryName("sigil_elemental_affinity"), new ItemSigilMagnetism().setRegistryName("sigil_magnetism"), new ItemSigilSuppression().setRegistryName("sigil_suppression"), - new ItemSigilHaste().setRegistryName("sigil_haste"), + new ItemSigil(new SigilHaste(), "haste").setRegistryName("sigil_haste"), new ItemSigil(new SigilFastMiner(), "fast_miner").setRegistryName("sigil_fast_miner"), new ItemSigilSeer().setRegistryName("sigil_seer"), new ItemSigilPhantomBridge().setRegistryName("sigil_phantom_bridge"), diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilGreenGrove.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilGreenGrove.java deleted file mode 100644 index 842b69ad..00000000 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilGreenGrove.java +++ /dev/null @@ -1,94 +0,0 @@ -package WayofTime.bloodmagic.item.sigil; - -import WayofTime.bloodmagic.api.util.helper.PlayerHelper; -import WayofTime.bloodmagic.api_impl.BloodMagicAPI; -import net.minecraft.block.IGrowable; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.entity.player.BonemealEvent; -import net.minecraftforge.fml.common.eventhandler.Event.Result; - -public class ItemSigilGreenGrove extends ItemSigilToggleableBase { - public ItemSigilGreenGrove() { - super("green_grove", 150); - } - - @Override - public boolean onSigilUse(ItemStack stack, EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ) { - if (PlayerHelper.isFakePlayer(player)) - return false; - - if (applyBonemeal(world, blockPos, player, stack)) { - if (!world.isRemote) { - world.playEvent(2005, blockPos, 0); - } - return true; - } - - return false; - } - - @Override - public void onSigilUpdate(ItemStack stack, World worldIn, EntityPlayer player, int itemSlot, boolean isSelected) { - if (PlayerHelper.isFakePlayer(player)) - return; - - int range = 3; - int verticalRange = 2; - int posX = (int) Math.round(player.posX - 0.5f); - int posY = (int) player.posY; - int posZ = (int) Math.round(player.posZ - 0.5f); - - for (int ix = posX - range; ix <= posX + range; ix++) { - for (int iz = posZ - range; iz <= posZ + range; iz++) { - for (int iy = posY - verticalRange; iy <= posY + verticalRange; iy++) { - BlockPos blockPos = new BlockPos(ix, iy, iz); - IBlockState state = worldIn.getBlockState(blockPos); - - if (!BloodMagicAPI.INSTANCE.getBlacklist().getGreenGrove().contains(state)) { - if (state.getBlock() instanceof IGrowable) { - if (worldIn.rand.nextInt(50) == 0) { - IBlockState preBlockState = worldIn.getBlockState(blockPos); - state.getBlock().updateTick(worldIn, blockPos, state, worldIn.rand); - - IBlockState newState = worldIn.getBlockState(blockPos); - if (!newState.equals(preBlockState) && !worldIn.isRemote) - worldIn.playEvent(2005, blockPos, 0); - } - } - } - } - } - } - } - - private boolean applyBonemeal(World worldIn, BlockPos target, EntityPlayer player, ItemStack sigilStack) { - IBlockState iblockstate = worldIn.getBlockState(target); - - BonemealEvent event = new BonemealEvent(player, worldIn, target, iblockstate, EnumHand.MAIN_HAND, sigilStack); - if (MinecraftForge.EVENT_BUS.post(event)) - return false; - else if (event.getResult() == Result.ALLOW) - return true; - - if (iblockstate.getBlock() instanceof IGrowable) { - IGrowable igrowable = (IGrowable) iblockstate.getBlock(); - - if (igrowable.canGrow(worldIn, target, iblockstate, worldIn.isRemote)) { - if (!worldIn.isRemote) { - if (igrowable.canUseBonemeal(worldIn, worldIn.rand, target, iblockstate)) - igrowable.grow(worldIn, worldIn.rand, target, iblockstate); - } - return true; - } - } - - return false; - } -} diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilHaste.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilHaste.java deleted file mode 100644 index 02559204..00000000 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilHaste.java +++ /dev/null @@ -1,22 +0,0 @@ -package WayofTime.bloodmagic.item.sigil; - -import WayofTime.bloodmagic.api.util.helper.PlayerHelper; -import WayofTime.bloodmagic.core.RegistrarBloodMagic; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.potion.PotionEffect; -import net.minecraft.world.World; - -public class ItemSigilHaste extends ItemSigilToggleableBase { - public ItemSigilHaste() { - super("haste", 250); - } - - @Override - public void onSigilUpdate(ItemStack stack, World world, EntityPlayer player, int itemSlot, boolean isSelected) { - if (PlayerHelper.isFakePlayer(player)) - return; - - player.addPotionEffect(new PotionEffect(RegistrarBloodMagic.BOOST, 2, 0, true, false)); - } -} diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilLava.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilLava.java deleted file mode 100644 index 919b2dab..00000000 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilLava.java +++ /dev/null @@ -1,115 +0,0 @@ -package WayofTime.bloodmagic.item.sigil; - -import WayofTime.bloodmagic.api.iface.ISigil; -import WayofTime.bloodmagic.api.util.helper.NetworkHelper; -import WayofTime.bloodmagic.api.util.helper.PlayerHelper; -import net.minecraft.block.material.Material; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.world.World; -import net.minecraftforge.event.ForgeEventFactory; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.CapabilityFluidHandler; -import net.minecraftforge.fluids.capability.IFluidHandler; - -public class ItemSigilLava extends ItemSigilBase { - public ItemSigilLava() { - super("lava", 1000); - } - - @Override - public ActionResult onItemRightClick(World world, EntityPlayer player, EnumHand hand) { - ItemStack stack = player.getHeldItem(hand); - if (stack.getItem() instanceof ISigil.Holding) - stack = ((Holding) stack.getItem()).getHeldItem(stack, player); - if (PlayerHelper.isFakePlayer(player)) - return ActionResult.newResult(EnumActionResult.FAIL, stack); - - if (!world.isRemote && !isUnusable(stack)) { - RayTraceResult rayTrace = this.rayTrace(world, player, false); - - if (rayTrace != null) { - ActionResult ret = ForgeEventFactory.onBucketUse(player, world, stack, rayTrace); - if (ret != null) - return ret; - - if (rayTrace.typeOfHit == RayTraceResult.Type.BLOCK) { - BlockPos blockpos = rayTrace.getBlockPos(); - - if (!world.isBlockModifiable(player, blockpos)) { - return super.onItemRightClick(world, player, hand); - } - - if (!player.canPlayerEdit(blockpos.offset(rayTrace.sideHit), rayTrace.sideHit, stack)) { - return super.onItemRightClick(world, player, hand); - } - - BlockPos blockpos1 = blockpos.offset(rayTrace.sideHit); - - if (!player.canPlayerEdit(blockpos1, rayTrace.sideHit, stack)) { - return super.onItemRightClick(world, player, hand); - } - - if (this.canPlaceLava(world, blockpos1) && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed()) && this.tryPlaceLava(world, blockpos1)) { - return super.onItemRightClick(world, player, hand); - } - } - } - } - - return super.onItemRightClick(world, player, hand); - } - - @Override - public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos blockPos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { - ItemStack stack = player.getHeldItem(hand); - if (world.isRemote || player.isSneaking() || isUnusable(stack)) { - return EnumActionResult.FAIL; - } - if (!world.canMineBlockBody(player, blockPos)) { - return EnumActionResult.FAIL; - } - - TileEntity tile = world.getTileEntity(blockPos); - if (tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) { - IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side); - FluidStack fluid = new FluidStack(FluidRegistry.LAVA, 1000); - int amount = handler.fill(fluid, false); - - if (amount > 0 && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed())) { - handler.fill(fluid, true); - return EnumActionResult.SUCCESS; - } - - return EnumActionResult.FAIL; - } - - return EnumActionResult.FAIL; - } - - public boolean canPlaceLava(World world, BlockPos blockPos) { - if (!world.isAirBlock(blockPos) && world.getBlockState(blockPos).getBlock().getMaterial(world.getBlockState(blockPos)).isSolid()) { - return false; - } else if ((world.getBlockState(blockPos).getBlock() == Blocks.LAVA || world.getBlockState(blockPos).getBlock() == Blocks.FLOWING_LAVA) && world.getBlockState(blockPos).getBlock().getMetaFromState(world.getBlockState(blockPos)) == 0) { - return false; - } else { - world.setBlockState(blockPos, Blocks.FLOWING_LAVA.getBlockState().getBaseState(), 3); - return true; - } - } - - public boolean tryPlaceLava(World world, BlockPos pos) { - Material material = world.getBlockState(pos).getBlock().getMaterial(world.getBlockState(pos)); - - return world.isAirBlock(pos) && !material.isSolid(); - } -} diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilTeleposition.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilTeleposition.java deleted file mode 100644 index e4fd869f..00000000 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilTeleposition.java +++ /dev/null @@ -1,90 +0,0 @@ -package WayofTime.bloodmagic.item.sigil; - -import WayofTime.bloodmagic.api.Constants; -import WayofTime.bloodmagic.api.iface.ISigil; -import WayofTime.bloodmagic.api.teleport.TeleportQueue; -import WayofTime.bloodmagic.api.util.helper.NBTHelper; -import WayofTime.bloodmagic.api.util.helper.PlayerHelper; -import WayofTime.bloodmagic.ritual.portal.Teleports; -import WayofTime.bloodmagic.tile.TileTeleposer; -import WayofTime.bloodmagic.util.helper.TextHelper; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ActionResult; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -import java.util.List; - -public class ItemSigilTeleposition extends ItemSigilBase { - public ItemSigilTeleposition() { - super("teleposition"); - } - - @Override - @SideOnly(Side.CLIENT) - public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { - super.addInformation(stack, world, tooltip, flag); - - if (!stack.hasTagCompound()) - return; - NBTTagCompound tag = stack.getTagCompound(); - - if (tag != null && stack.getTagCompound().hasKey(Constants.NBT.DIMENSION_ID) && stack.getTagCompound().hasKey(Constants.NBT.X_COORD) && stack.getTagCompound().hasKey(Constants.NBT.Y_COORD) && stack.getTagCompound().hasKey(Constants.NBT.Z_COORD)) { - tooltip.add(" "); - tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.telepositionFocus.coords", getValue(tag, Constants.NBT.X_COORD), getValue(tag, Constants.NBT.Y_COORD), getValue(tag, Constants.NBT.Z_COORD))); - tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.telepositionFocus.dimension", getValue(tag, Constants.NBT.DIMENSION_ID))); - } - } - - @Override - public ActionResult onItemRightClick(World world, EntityPlayer player, EnumHand hand) { - ItemStack stack = player.getHeldItem(hand); - if (stack.getItem() instanceof ISigil.Holding) - stack = ((Holding) stack.getItem()).getHeldItem(stack, player); - if (PlayerHelper.isFakePlayer(player)) - return ActionResult.newResult(EnumActionResult.FAIL, stack); - - if (!world.isRemote && NBTHelper.checkNBT(stack) != null && stack.getTagCompound().hasKey(Constants.NBT.DIMENSION_ID) && stack.getTagCompound().hasKey(Constants.NBT.X_COORD) && stack.getTagCompound().hasKey(Constants.NBT.Y_COORD) && stack.getTagCompound().hasKey(Constants.NBT.Z_COORD)) { - BlockPos blockPos = new BlockPos(getValue(stack.getTagCompound(), Constants.NBT.X_COORD), getValue(stack.getTagCompound(), Constants.NBT.Y_COORD), getValue(stack.getTagCompound(), Constants.NBT.Z_COORD)).up(); - if (world.provider.getDimension() == getValue(stack.getTagCompound(), Constants.NBT.DIMENSION_ID)) { - TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(blockPos, player, getOwnerUUID(stack), true)); - } else { - TeleportQueue.getInstance().addITeleport(new Teleports.TeleportToDim(blockPos, player, getOwnerUUID(stack), world, getValue(stack.getTagCompound(), Constants.NBT.DIMENSION_ID), true)); - } - } - return super.onItemRightClick(world, player, hand); - } - - @Override - public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { - ItemStack stack = player.getHeldItem(hand); - if (stack.getItem() instanceof ISigil.Holding) - stack = ((Holding) stack.getItem()).getHeldItem(stack, player); - if (PlayerHelper.isFakePlayer(player)) - return EnumActionResult.FAIL; - - if (!world.isRemote && player.isSneaking() && NBTHelper.checkNBT(stack) != null) { - if (world.getTileEntity(pos) != null && world.getTileEntity(pos) instanceof TileTeleposer) { - stack.getTagCompound().setInteger(Constants.NBT.DIMENSION_ID, world.provider.getDimension()); - stack.getTagCompound().setInteger(Constants.NBT.X_COORD, pos.getX()); - stack.getTagCompound().setInteger(Constants.NBT.Y_COORD, pos.getY()); - stack.getTagCompound().setInteger(Constants.NBT.Z_COORD, pos.getZ()); - - return EnumActionResult.SUCCESS; - } - } - return EnumActionResult.FAIL; - } - - public int getValue(NBTTagCompound tag, String key) { - return tag.getInteger(key); - } -} diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilTransposition.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilTransposition.java deleted file mode 100644 index ac8429f4..00000000 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilTransposition.java +++ /dev/null @@ -1,143 +0,0 @@ -package WayofTime.bloodmagic.item.sigil; - -import WayofTime.bloodmagic.api.BlockStack; -import WayofTime.bloodmagic.api.Constants; -import WayofTime.bloodmagic.api.iface.ISigil; -import WayofTime.bloodmagic.api.util.helper.NBTHelper; -import WayofTime.bloodmagic.api.util.helper.NetworkHelper; -import WayofTime.bloodmagic.api.util.helper.PlayerHelper; -import WayofTime.bloodmagic.api_impl.BloodMagicAPI; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntityMobSpawner; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.fml.common.registry.ForgeRegistries; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -import java.util.List; - -public class ItemSigilTransposition extends ItemSigilBase { - public ItemSigilTransposition() { - super("transposition", 1000); - } - - @Override - @SideOnly(Side.CLIENT) - public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { - super.addInformation(stack, world, tooltip, flag); - - if (!stack.hasTagCompound()) - return; - NBTTagCompound tag = stack.getTagCompound(); - - if (tag.hasKey(Constants.NBT.CONTAINED_BLOCK_NAME) && tag.hasKey(Constants.NBT.CONTAINED_BLOCK_META)) { - tooltip.add(" "); - BlockStack blockStack = new BlockStack(Block.getBlockFromName(tag.getString(Constants.NBT.CONTAINED_BLOCK_NAME)), tag.getByte(Constants.NBT.CONTAINED_BLOCK_META)); - tooltip.add(blockStack.getItemStack().getDisplayName()); - } - } - - @Override - public String getItemStackDisplayName(ItemStack stack) { - stack = NBTHelper.checkNBT(stack); - NBTTagCompound tag = stack.getTagCompound(); - - if (tag.hasKey(Constants.NBT.CONTAINED_BLOCK_NAME) && tag.hasKey(Constants.NBT.CONTAINED_BLOCK_META)) { - BlockStack blockStack = new BlockStack(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(tag.getString(Constants.NBT.CONTAINED_BLOCK_NAME))), tag.getByte(Constants.NBT.CONTAINED_BLOCK_META)); - if (blockStack.getItemStack() != null && blockStack.getItemStack().getItem() != null) //TODO: Figure out why it's a null item. This is a patchwork solution. - { - return super.getItemStackDisplayName(stack) + " (" + blockStack.getItemStack().getDisplayName() + ")"; - } - - } - return super.getItemStackDisplayName(stack); - } - - @Override - public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos blockPos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { - ItemStack stack = player.getHeldItem(hand); - if (stack.getItem() instanceof ISigil.Holding) - stack = ((Holding) stack.getItem()).getHeldItem(stack, player); - if (PlayerHelper.isFakePlayer(player)) - return EnumActionResult.FAIL; - - stack = NBTHelper.checkNBT(stack); - - IBlockState state = world.getBlockState(blockPos); - if (!world.isRemote) { - if (BloodMagicAPI.INSTANCE.getBlacklist().getTransposition().contains(state)) - return EnumActionResult.FAIL; - - if (player.isSneaking() && (!stack.getTagCompound().hasKey(Constants.NBT.CONTAINED_BLOCK_NAME) || !stack.getTagCompound().hasKey(Constants.NBT.CONTAINED_BLOCK_META))) { - if (state.getPlayerRelativeBlockHardness(player, world, blockPos) >= 0 && state.getBlockHardness(world, blockPos) >= 0) { - int cost = getLpUsed(); - - NBTTagCompound tileNBTTag = new NBTTagCompound(); - String blockName = state.getBlock().getRegistryName().toString(); - byte metadata = (byte) state.getBlock().getMetaFromState(state); - - if (world.getTileEntity(blockPos) != null) { - cost *= 5; - world.getTileEntity(blockPos).writeToNBT(tileNBTTag); - - if (world.getTileEntity(blockPos) instanceof TileEntityMobSpawner) { - cost *= 6; - } - } - - stack.getTagCompound().setString(Constants.NBT.CONTAINED_BLOCK_NAME, blockName); - stack.getTagCompound().setByte(Constants.NBT.CONTAINED_BLOCK_META, metadata); - stack.getTagCompound().setTag(Constants.NBT.CONTAINED_TILE_ENTITY, tileNBTTag); - - NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, cost); - - world.removeTileEntity(blockPos); - world.setBlockToAir(blockPos); - - return EnumActionResult.SUCCESS; - } - } else if (stack.getTagCompound().hasKey(Constants.NBT.CONTAINED_BLOCK_NAME) && stack.getTagCompound().hasKey(Constants.NBT.CONTAINED_BLOCK_META)) { - IBlockState iblockstate = world.getBlockState(blockPos); - Block block = iblockstate.getBlock(); - BlockStack blockToPlace = new BlockStack(Block.getBlockFromName(stack.getTagCompound().getString(Constants.NBT.CONTAINED_BLOCK_NAME)), stack.getTagCompound().getByte(Constants.NBT.CONTAINED_BLOCK_META)); - - if (!block.isReplaceable(world, blockPos)) { - blockPos = blockPos.offset(side); - } - - if (!stack.isEmpty() && player.canPlayerEdit(blockPos, side, stack) && world.mayPlace(blockToPlace.getBlock(), blockPos, false, side, player)) { - if (world.setBlockState(blockPos, blockToPlace.getState(), 3)) { - blockToPlace.getBlock().onBlockPlacedBy(world, blockPos, blockToPlace.getState(), player, blockToPlace.getItemStack()); -// world.playSound((double) ((float) blockPos.getX() + 0.5F), (double) ((float) blockPos.getY() + 0.5F), (double) ((float) blockPos.getZ() + 0.5F), blockToPlace.getBlock().getStepSound().getPlaceSound(), (blockToPlace.getBlock().getStepSound().getVolume() + 1.0F) / 2.0F, blockToPlace.getBlock().getStepSound().getPitch() * 0.8F); - - if (stack.getTagCompound().hasKey(Constants.NBT.CONTAINED_TILE_ENTITY) && blockToPlace.getBlock().hasTileEntity(blockToPlace.getState())) { - NBTTagCompound tag = stack.getTagCompound().getCompoundTag(Constants.NBT.CONTAINED_TILE_ENTITY); - tag.setInteger("x", blockPos.getX()); - tag.setInteger("y", blockPos.getY()); - tag.setInteger("z", blockPos.getZ()); - world.getTileEntity(blockPos).readFromNBT(tag); - } - world.notifyBlockUpdate(blockPos, state, state, 3); - - stack.getTagCompound().removeTag(Constants.NBT.CONTAINED_BLOCK_NAME); - stack.getTagCompound().removeTag(Constants.NBT.CONTAINED_BLOCK_META); - stack.getTagCompound().removeTag(Constants.NBT.CONTAINED_TILE_ENTITY); - - return EnumActionResult.SUCCESS; - } - } - } - } - return EnumActionResult.FAIL; - } -} diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilWater.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilWater.java deleted file mode 100644 index 8fa03754..00000000 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilWater.java +++ /dev/null @@ -1,132 +0,0 @@ -package WayofTime.bloodmagic.item.sigil; - -import WayofTime.bloodmagic.api.iface.ISigil; -import WayofTime.bloodmagic.api.util.helper.NetworkHelper; -import WayofTime.bloodmagic.api.util.helper.PlayerHelper; -import net.minecraft.block.BlockCauldron; -import net.minecraft.block.material.Material; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.init.SoundEvents; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.*; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.world.World; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.CapabilityFluidHandler; -import net.minecraftforge.fluids.capability.IFluidHandler; - -public class ItemSigilWater extends ItemSigilBase { - public ItemSigilWater() { - super("water", 100); - } - - @Override - public ActionResult onItemRightClick(World world, EntityPlayer player, EnumHand hand) { - ItemStack stack = player.getHeldItem(hand); - if (stack.getItem() instanceof ISigil.Holding) - stack = ((Holding) stack.getItem()).getHeldItem(stack, player); - if (PlayerHelper.isFakePlayer(player)) - return ActionResult.newResult(EnumActionResult.FAIL, stack); - - if (!world.isRemote && !isUnusable(stack)) { - RayTraceResult rayTrace = this.rayTrace(world, player, false); - - if (rayTrace != null) { - ActionResult ret = net.minecraftforge.event.ForgeEventFactory.onBucketUse(player, world, stack, rayTrace); - if (ret != null) - return ret; - - if (rayTrace.typeOfHit == RayTraceResult.Type.BLOCK) { - BlockPos blockpos = rayTrace.getBlockPos(); - - if (!world.isBlockModifiable(player, blockpos)) - return super.onItemRightClick(world, player, hand); - - if (!player.canPlayerEdit(blockpos.offset(rayTrace.sideHit), rayTrace.sideHit, stack)) - return super.onItemRightClick(world, player, hand); - - BlockPos blockpos1 = blockpos.offset(rayTrace.sideHit); - - if (!player.canPlayerEdit(blockpos1, rayTrace.sideHit, stack)) - return super.onItemRightClick(world, player, hand); - - if (this.canPlaceWater(world, blockpos1) && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed()) && this.tryPlaceWater(world, blockpos1)) - return super.onItemRightClick(world, player, hand); - } - } - } - - return super.onItemRightClick(world, player, hand); - } - - @Override - public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos blockPos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { - ItemStack stack = player.getHeldItem(hand); - if (world.isRemote || player.isSneaking() || isUnusable(stack)) - return EnumActionResult.FAIL; - - if (!world.canMineBlockBody(player, blockPos)) - return EnumActionResult.FAIL; - - TileEntity tile = world.getTileEntity(blockPos); - if (tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) { - IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side); - FluidStack fluid = new FluidStack(FluidRegistry.WATER, 1000); - int amount = handler.fill(fluid, false); - - if (amount > 0 && NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, getLpUsed())) { - handler.fill(fluid, true); - return EnumActionResult.SUCCESS; - } - - return EnumActionResult.FAIL; - } - - if (world.getBlockState(blockPos).getBlock() == Blocks.CAULDRON && NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, getLpUsed())) { - world.setBlockState(blockPos, Blocks.CAULDRON.getDefaultState().withProperty(BlockCauldron.LEVEL, 3)); - return EnumActionResult.SUCCESS; - } - - return EnumActionResult.FAIL; - } - - public boolean canPlaceWater(World world, BlockPos blockPos) { - if (!world.isAirBlock(blockPos) && world.getBlockState(blockPos).getBlock().getMaterial(world.getBlockState(blockPos)).isSolid()) - return false; - else if ((world.getBlockState(blockPos).getBlock() == Blocks.WATER || world.getBlockState(blockPos).getBlock() == Blocks.FLOWING_WATER) && world.getBlockState(blockPos).getBlock().getMetaFromState(world.getBlockState(blockPos)) == 0) - return false; - else - return true; - } - - public boolean tryPlaceWater(World worldIn, BlockPos pos) { - - Material material = worldIn.getBlockState(pos).getBlock().getMaterial(worldIn.getBlockState(pos)); - boolean notSolid = !material.isSolid(); - - if (!worldIn.isAirBlock(pos) && !notSolid) { - return false; - } else { - if (worldIn.provider.doesWaterVaporize()) { - int i = pos.getX(); - int j = pos.getY(); - int k = pos.getZ(); - worldIn.playSound(null, i, j, k, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F); - - for (int l = 0; l < 8; ++l) - worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0D, 0.0D, 0.0D, 0); - } else { - if (!worldIn.isRemote && notSolid && !material.isLiquid()) - worldIn.destroyBlock(pos, true); - - worldIn.setBlockState(pos, Blocks.FLOWING_WATER.getDefaultState(), 3); - } - - return true; - } - } -} diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/sigil/ItemSigilTeleposition.java b/src/main/java/WayofTime/bloodmagic/item/sigil/sigil/ItemSigilTeleposition.java new file mode 100644 index 00000000..c3228ab2 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/sigil/ItemSigilTeleposition.java @@ -0,0 +1,90 @@ +package WayofTime.bloodmagic.item.sigil.sigil; + +import WayofTime.bloodmagic.api.teleport.ITeleport; +import WayofTime.bloodmagic.api.teleport.TeleportQueue; +import WayofTime.bloodmagic.ritual.portal.Teleports; +import WayofTime.bloodmagic.tile.TileTeleposer; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.List; + +public class ItemSigilTeleposition extends ItemSigil { + + public ItemSigilTeleposition() { + super(new SigilTeleposition(), "teleposition"); + } + + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, @Nullable World worldIn, List tooltip, ITooltipFlag flagIn) { + super.addInformation(stack, worldIn, tooltip, flagIn); + + if (!stack.hasTagCompound() || !stack.getTagCompound().hasKey("dim")) + return; + + NBTTagCompound tag = stack.getTagCompound(); + BlockPos pos = BlockPos.fromLong(tag.getLong("pos")); + + tooltip.add(""); + tooltip.add(I18n.format("tooltip.bloodmagic.telepositionFocus.coords", pos.getX(), pos.getY(), pos.getZ())); + tooltip.add(I18n.format("tooltip.bloodmagic.telepositionFocus.dimension", tag.getInteger("dim"))); + } + + public static class SigilTeleposition implements ISigil { + + @Override + public int getCost() { + return 0; + } + + @Nonnull + @Override + public EnumActionResult onRightClick(@Nonnull ItemStack stack, @Nonnull EntityPlayer player, @Nonnull World world, @Nonnull EnumHand hand) { + if (world.isRemote || !stack.hasTagCompound() || !stack.getTagCompound().hasKey("dim")) + return EnumActionResult.PASS; + + NBTTagCompound tag = stack.getTagCompound(); + BlockPos pos = BlockPos.fromLong(tag.getLong("pos")); + int dimension = tag.getInteger("dim"); + + ITeleport teleport; + if (world.provider.getDimension() == dimension) + teleport = new Teleports.TeleportSameDim(pos, player, getOwnerUUID(stack), true); + else + teleport = new Teleports.TeleportToDim(pos, player, getOwnerUUID(stack), world, dimension, true); + + TeleportQueue.getInstance().addITeleport(teleport); + + return EnumActionResult.SUCCESS; + } + + @Override + public EnumActionResult onInteract(@Nonnull ItemStack stack, @Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side, @Nonnull EnumHand hand) { + if (!stack.hasTagCompound()) + stack.setTagCompound(new NBTTagCompound()); + + if (!(world.getTileEntity(pos) instanceof TileTeleposer)) + return EnumActionResult.FAIL; + + NBTTagCompound tag = stack.getTagCompound(); + tag.setLong("pos", pos.toLong()); + tag.setInteger("dim", world.provider.getDimension()); + + + return EnumActionResult.SUCCESS; + } + } +} diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/sigil/ItemSigilTransposition.java b/src/main/java/WayofTime/bloodmagic/item/sigil/sigil/ItemSigilTransposition.java new file mode 100644 index 00000000..58120ac2 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/sigil/ItemSigilTransposition.java @@ -0,0 +1,145 @@ +package WayofTime.bloodmagic.item.sigil.sigil; + +import WayofTime.bloodmagic.api.util.helper.NetworkHelper; +import WayofTime.bloodmagic.api_impl.BloodMagicAPI; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTUtil; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityMobSpawner; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.List; + +public class ItemSigilTransposition extends ItemSigil { + + public ItemSigilTransposition() { + super(new SigilTransposition(), "transposition"); + } + + @Override + public void addInformation(ItemStack stack, @Nullable World worldIn, List tooltip, ITooltipFlag flagIn) { + super.addInformation(stack, worldIn, tooltip, flagIn); + + if (!stack.hasTagCompound()) + return; + + NBTTagCompound tag = stack.getTagCompound(); + if (!tag.hasKey("stored")) + return; + + IBlockState state = NBTUtil.readBlockState(tag.getCompoundTag("stored")); + ItemStack blockStack = new ItemStack(state.getBlock().getItemDropped(state, null, 0), 1, state.getBlock().damageDropped(state)); + tooltip.add(blockStack.isEmpty() ? I18n.format(state.getBlock().getUnlocalizedName()) : blockStack.getDisplayName()); + } + + @Override + public String getItemStackDisplayName(ItemStack stack) { + if (!stack.hasTagCompound()) + return super.getItemStackDisplayName(stack); + + NBTTagCompound tag = stack.getTagCompound(); + if (!tag.hasKey("stored")) + return super.getItemStackDisplayName(stack); + + IBlockState state = NBTUtil.readBlockState(tag.getCompoundTag("stored")); + ItemStack blockStack = new ItemStack(state.getBlock().getItemDropped(state, null, 0), 1, state.getBlock().damageDropped(state)); + String blockName = blockStack.isEmpty() ? net.minecraft.util.text.translation.I18n.translateToLocal(state.getBlock().getUnlocalizedName()) : blockStack.getDisplayName(); + + return super.getItemStackDisplayName(stack) + " (" + blockName + ")"; + } + + @Nullable + @Override + public NBTTagCompound getNBTShareTag(ItemStack stack) { + if (!stack.hasTagCompound() || !stack.getTagCompound().hasKey("stored")) + return null; + + NBTTagCompound justTheState = stack.getTagCompound().copy(); + justTheState.getCompoundTag("stored").removeTag("tile"); + return justTheState; + } + + public static class SigilTransposition implements ISigil { + + @Override + public int getCost() { + return 1000; + } + + @Override + public EnumActionResult onInteract(@Nonnull ItemStack stack, @Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side, @Nonnull EnumHand hand) { + IBlockState state = world.getBlockState(pos); + if (world.isRemote || BloodMagicAPI.INSTANCE.getBlacklist().getTransposition().contains(state)) + return EnumActionResult.FAIL; + + NBTTagCompound tag = stack.getTagCompound(); + if (player.isSneaking() && (!stack.hasTagCompound() || !tag.hasKey("stored"))) { + if (state.getPlayerRelativeBlockHardness(player, world, pos) >= 0 && state.getBlockHardness(world, pos) >= 0) { + int cost = getCost(); + + NBTTagCompound stored = new NBTTagCompound(); + NBTUtil.writeBlockState(stored, state); + + TileEntity tile = world.getTileEntity(pos); + if (tile != null) { + NBTTagCompound tileTag = new NBTTagCompound(); + tile.writeToNBT(tileTag); + stored.setTag("tile", tileTag); + cost *= 5; + + if (tile instanceof TileEntityMobSpawner) + cost *= 6; + } + + tag.setTag("stored", stored); + + NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, cost); + world.setBlockToAir(pos); + world.removeTileEntity(pos); + } + } else if (stack.hasTagCompound() && stack.getTagCompound().hasKey("stored")) { + IBlockState placeAtState = world.getBlockState(pos); + + // If the block we clicked isn't replaceable, try to offset to the side we clicked on + if (!placeAtState.getBlock().isReplaceable(world, pos)) + placeAtState = world.getBlockState(pos = pos.offset(side)); + + // If we still can't place here, just cancel out. + if (!placeAtState.getBlock().isReplaceable(world, pos)) + return EnumActionResult.FAIL; + + NBTTagCompound stored = stack.getTagCompound().getCompoundTag("stored"); + IBlockState toPlace = NBTUtil.readBlockState(stored); + if (player.canPlayerEdit(pos, side, stack) && world.mayPlace(toPlace.getBlock(), pos, false, side, player)) { + ItemStack placeStack = new ItemStack(state.getBlock().getItemDropped(state, null, 0), 1, state.getBlock().damageDropped(state)); + toPlace.getBlock().onBlockPlacedBy(world, pos, toPlace, player, placeStack); + + if (stored.hasKey("tile")) { + NBTTagCompound tileTag = stored.getCompoundTag("tile"); + tileTag.setInteger("x", pos.getX()); + tileTag.setInteger("y", pos.getY()); + tileTag.setInteger("z", pos.getZ()); + world.getTileEntity(pos).readFromNBT(tileTag); + } + + world.notifyBlockUpdate(pos, state, state, 3); + + stack.getTagCompound().removeTag("stored"); + } + } + + return EnumActionResult.SUCCESS; + } + } +} diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/sigil/SigilFluid.java b/src/main/java/WayofTime/bloodmagic/item/sigil/sigil/SigilFluid.java new file mode 100644 index 00000000..82bc1aaf --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/sigil/SigilFluid.java @@ -0,0 +1,79 @@ +package WayofTime.bloodmagic.item.sigil.sigil; + +import WayofTime.bloodmagic.api.util.helper.NetworkHelper; +import net.minecraft.block.Block; +import net.minecraft.block.BlockLiquid; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidBlock; +import net.minecraftforge.fluids.capability.CapabilityFluidHandler; +import net.minecraftforge.fluids.capability.IFluidHandler; +import net.minecraftforge.fluids.capability.wrappers.BlockLiquidWrapper; +import net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper; + +import javax.annotation.Nonnull; + +public class SigilFluid implements ISigil { + + private final Fluid fluid; + + public SigilFluid(Fluid fluid) { + this.fluid = fluid; + } + + @Override + public int getCost() { + return 1000; + } + + @Override + public EnumActionResult onInteract(@Nonnull ItemStack stack, @Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side, @Nonnull EnumHand hand) { + if (world.isRemote) + return EnumActionResult.FAIL; + + TileEntity tile = world.getTileEntity(pos); + if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) { + IFluidHandler fluidHandler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side); + FluidStack fluid = new FluidStack(this.fluid, 1000); + int amount = fluidHandler.fill(fluid, false); + if (amount > 0 && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getCost())) { + fluidHandler.fill(fluid, true); + return EnumActionResult.SUCCESS; + } + } + + if (fluid.getBlock() == null) + return EnumActionResult.FAIL; + + IBlockState placeAtState = world.getBlockState(pos); + if (!placeAtState.getBlock().isReplaceable(world, pos)) + placeAtState = world.getBlockState(pos = pos.offset(side)); + + if (!placeAtState.getBlock().isReplaceable(world, pos)) + return EnumActionResult.FAIL; + + Block fluidBlock = fluid.getBlock(); + IFluidHandler fluidHandler = null; + if (fluidBlock instanceof IFluidBlock) + fluidHandler = new FluidBlockWrapper((IFluidBlock) fluidBlock, world, pos); + else if (fluidBlock instanceof BlockLiquid) + fluidHandler = new BlockLiquidWrapper((BlockLiquid) fluidBlock, world, pos); + + if (fluidHandler != null) { + fluidHandler.fill(new FluidStack(fluid, Fluid.BUCKET_VOLUME), true); + NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getCost()); + return EnumActionResult.SUCCESS; + } + + return EnumActionResult.FAIL; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/sigil/SigilGreenGrove.java b/src/main/java/WayofTime/bloodmagic/item/sigil/sigil/SigilGreenGrove.java new file mode 100644 index 00000000..19fb9f2f --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/sigil/SigilGreenGrove.java @@ -0,0 +1,91 @@ +package WayofTime.bloodmagic.item.sigil.sigil; + +import WayofTime.bloodmagic.api_impl.BloodMagicAPI; +import net.minecraft.block.IGrowable; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.player.BonemealEvent; +import net.minecraftforge.fml.common.eventhandler.Event; + +import javax.annotation.Nonnull; + +public class SigilGreenGrove implements ISigil.Toggle { + + private static final int RANGE_HORIZONTAL = 3; + private static final int RANGE_VERTICAL = 2; + + @Override + public int getCost() { + return 150; + } + + @Override + public EnumActionResult onInteract(@Nonnull ItemStack stack, @Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side, @Nonnull EnumHand hand) { + if (applyBonemeal(world, pos, player, stack, hand)) { + if (!world.isRemote) + world.playEvent(2005, pos, 0); + + return EnumActionResult.SUCCESS; + } + + return EnumActionResult.FAIL; + } + + @Override + public void onUpdate(@Nonnull ItemStack stack, @Nonnull EntityPlayer player, @Nonnull World world, int itemSlot, boolean isHeld) { + int posX = (int) Math.round(player.posX - 0.5f); + int posY = (int) player.posY; + int posZ = (int) Math.round(player.posZ - 0.5f); + + for (int ix = posX - RANGE_HORIZONTAL; ix <= posX + RANGE_HORIZONTAL; ix++) { + for (int iz = posZ - RANGE_HORIZONTAL; iz <= posZ + RANGE_HORIZONTAL; iz++) { + for (int iy = posY - RANGE_VERTICAL; iy <= posY + RANGE_VERTICAL; iy++) { + BlockPos blockPos = new BlockPos(ix, iy, iz); + IBlockState state = world.getBlockState(blockPos); + + if (!BloodMagicAPI.INSTANCE.getBlacklist().getGreenGrove().contains(state)) { + if (state.getBlock() instanceof IGrowable) { + if (world.rand.nextInt(50) == 0) { + state.getBlock().updateTick(world, blockPos, state, world.rand); + IBlockState newState = world.getBlockState(blockPos); + + if (!newState.equals(state) && !world.isRemote) + world.playEvent(2005, blockPos, 0); + } + } + } + } + } + } + } + + private boolean applyBonemeal(World world, BlockPos target, EntityPlayer player, ItemStack sigilStack, EnumHand hand) { + IBlockState state = world.getBlockState(target); + + BonemealEvent event = new BonemealEvent(player, world, target, state, hand, sigilStack); + if (MinecraftForge.EVENT_BUS.post(event)) + return false; + else if (event.getResult() == Event.Result.ALLOW) + return true; + + if (state.getBlock() instanceof IGrowable) { + IGrowable growable = (IGrowable) state.getBlock(); + + if (growable.canGrow(world, target, state, world.isRemote)) { + if (!world.isRemote && growable.canUseBonemeal(world, world.rand, target, state)) + growable.grow(world, world.rand, target, state); + + return true; + } + } + + return false; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/sigil/SigilHaste.java b/src/main/java/WayofTime/bloodmagic/item/sigil/sigil/SigilHaste.java new file mode 100644 index 00000000..4486ebfa --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/sigil/SigilHaste.java @@ -0,0 +1,22 @@ +package WayofTime.bloodmagic.item.sigil.sigil; + +import WayofTime.bloodmagic.core.RegistrarBloodMagic; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.PotionEffect; +import net.minecraft.world.World; + +import javax.annotation.Nonnull; + +public class SigilHaste implements ISigil.Toggle { + + @Override + public int getCost() { + return 250; + } + + @Override + public void onUpdate(@Nonnull ItemStack stack, @Nonnull EntityPlayer player, @Nonnull World world, int itemSlot, boolean isHeld) { + player.addPotionEffect(new PotionEffect(RegistrarBloodMagic.BOOST, 2, 0, true, false)); + } +} diff --git a/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java b/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java index 72c9fb45..6e1f3098 100644 --- a/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java +++ b/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java @@ -55,6 +55,7 @@ import net.minecraft.init.MobEffects; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; import net.minecraft.util.EnumHand; import net.minecraft.util.EnumParticleTypes; @@ -342,22 +343,8 @@ public class GenericHandler { return; ItemStack held = event.getItemStack(); - if (!held.isEmpty() && held.getItem() instanceof IBindable) { - held = NBTHelper.checkNBT(held); - IBindable bindable = (IBindable) held.getItem(); - if (Strings.isNullOrEmpty(bindable.getOwnerUUID(held))) { - if (bindable.onBind(player, held)) { - String uuid = PlayerHelper.getUUIDFromPlayer(player).toString(); - ItemBindEvent toPost = new ItemBindEvent(player, uuid, held); - if (MinecraftForge.EVENT_BUS.post(toPost) || toPost.getResult() == Result.DENY) - return; - - BindableHelper.setItemOwnerUUID(held, uuid); - BindableHelper.setItemOwnerName(held, player.getDisplayNameString()); - } - } else if (bindable.getOwnerUUID(held).equals(PlayerHelper.getUUIDFromPlayer(player).toString()) && !bindable.getOwnerName(held).equals(player.getDisplayNameString())) - BindableHelper.setItemOwnerName(held, player.getDisplayNameString()); - } + if (!held.isEmpty() && held.getItem() instanceof IBindable) + bindItem(held, player); if (!held.isEmpty() && held.getItem() instanceof IBloodOrb) { held = NBTHelper.checkNBT(held); @@ -373,6 +360,38 @@ public class GenericHandler { } } + // Handles binding of IBindable's + @SubscribeEvent + public static void onInteractBlock(PlayerInteractEvent.RightClickBlock event) { + if (event.getWorld().isRemote) + return; + + if (PlayerHelper.isFakePlayer(event.getEntityPlayer())) + return; + + if (!event.getItemStack().isEmpty() && event.getItemStack().getItem() instanceof IBindable) + bindItem(event.getItemStack(), event.getEntityPlayer()); + } + + private static void bindItem(ItemStack stack, EntityPlayer player) { + IBindable bindable = (IBindable) stack.getItem(); + if (Strings.isNullOrEmpty(bindable.getOwnerUUID(stack))) { + if (!stack.hasTagCompound()) + stack.setTagCompound(new NBTTagCompound()); + + if (bindable.onBind(player, stack)) { + String uuid = PlayerHelper.getUUIDFromPlayer(player).toString(); + ItemBindEvent toPost = new ItemBindEvent(player, uuid, stack); + if (MinecraftForge.EVENT_BUS.post(toPost) || toPost.getResult() == Result.DENY) + return; + + BindableHelper.setItemOwnerUUID(stack, uuid); + BindableHelper.setItemOwnerName(stack, player.getDisplayNameString()); + } + } else if (bindable.getOwnerUUID(stack).equals(PlayerHelper.getUUIDFromPlayer(player).toString()) && !bindable.getOwnerName(stack).equals(player.getDisplayNameString())) + BindableHelper.setItemOwnerName(stack, player.getDisplayNameString()); + } + @SubscribeEvent(priority = EventPriority.HIGH) public static void onTooltip(ItemTooltipEvent event) { if (event.getItemStack().getItem() instanceof IBindable) diff --git a/src/main/resources/assets/bloodmagic/blockstates/sigil_lava.json b/src/main/resources/assets/bloodmagic/blockstates/sigil_lava.json index fde7dbbc..3e264e84 100644 --- a/src/main/resources/assets/bloodmagic/blockstates/sigil_lava.json +++ b/src/main/resources/assets/bloodmagic/blockstates/sigil_lava.json @@ -5,12 +5,10 @@ "transform": "forge:default-item" }, "variants": { - "type": { - "normal": { - "textures": { - "layer0": "bloodmagic:items/LavaSigil" - } + "inventory": [{ + "textures": { + "layer0": "bloodmagic:items/lavasigil" } - } + }] } } \ No newline at end of file diff --git a/src/main/resources/assets/bloodmagic/blockstates/sigil_teleposition.json b/src/main/resources/assets/bloodmagic/blockstates/sigil_teleposition.json index 84d1fe93..c46bdb91 100644 --- a/src/main/resources/assets/bloodmagic/blockstates/sigil_teleposition.json +++ b/src/main/resources/assets/bloodmagic/blockstates/sigil_teleposition.json @@ -5,12 +5,10 @@ "transform": "forge:default-item" }, "variants": { - "type": { - "normal": { - "textures": { - "layer0": "bloodmagic:items/TelepositionSigil" - } + "inventory": [{ + "textures": { + "layer0": "bloodmagic:items/telepositionsigil" } - } + }] } } \ No newline at end of file diff --git a/src/main/resources/assets/bloodmagic/blockstates/sigil_transposition.json b/src/main/resources/assets/bloodmagic/blockstates/sigil_transposition.json index bb09cc7d..616df1e8 100644 --- a/src/main/resources/assets/bloodmagic/blockstates/sigil_transposition.json +++ b/src/main/resources/assets/bloodmagic/blockstates/sigil_transposition.json @@ -5,12 +5,10 @@ "transform": "forge:default-item" }, "variants": { - "type": { - "normal": { - "textures": { - "layer0": "bloodmagic:items/TranspositionSigil" - } + "inventory": [{ + "textures": { + "layer0": "bloodmagic:items/transpositionsigil" } - } + }] } } \ No newline at end of file diff --git a/src/main/resources/assets/bloodmagic/blockstates/sigil_water.json b/src/main/resources/assets/bloodmagic/blockstates/sigil_water.json index 9f76d28b..81b7c857 100644 --- a/src/main/resources/assets/bloodmagic/blockstates/sigil_water.json +++ b/src/main/resources/assets/bloodmagic/blockstates/sigil_water.json @@ -5,12 +5,10 @@ "transform": "forge:default-item" }, "variants": { - "type": { - "normal": { - "textures": { - "layer0": "bloodmagic:items/WaterSigil" - } + "inventory": [{ + "textures": { + "layer0": "bloodmagic:items/watersigil" } - } + }] } } \ No newline at end of file