Rewrite Binding system to be fully automated
No more manual handling of binding items to players. Retains all previous functionality. I have tested on both the Client and Server and it seems to work just fine. If any issues arise from this, do not hesitate to yell at me. The deprecated methods will be removed after beta.
This commit is contained in:
parent
e219b50589
commit
8c1eaddb97
|
@ -8,43 +8,107 @@ import net.minecraftforge.common.MinecraftForge;
|
||||||
import WayofTime.bloodmagic.api.Constants;
|
import WayofTime.bloodmagic.api.Constants;
|
||||||
import WayofTime.bloodmagic.api.event.ItemBindEvent;
|
import WayofTime.bloodmagic.api.event.ItemBindEvent;
|
||||||
import WayofTime.bloodmagic.api.iface.IBindable;
|
import WayofTime.bloodmagic.api.iface.IBindable;
|
||||||
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||||
|
|
||||||
public class BindableHelper
|
public class BindableHelper
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Bind an item to a player. Handles checking if the player was an
|
* Sets the Owner Name of the item without checking if it is already bound. Also
|
||||||
* instanceof {@link net.minecraftforge.common.util.FakePlayer} or other
|
* bypasses {@link ItemBindEvent}.
|
||||||
* type of Fake Player.
|
*
|
||||||
*
|
* @param stack
|
||||||
|
* - The ItemStack to bind
|
||||||
|
* @param ownerName
|
||||||
|
* - The username to bind the ItemStack to
|
||||||
|
*/
|
||||||
|
public static void setItemOwnerName(ItemStack stack, String ownerName)
|
||||||
|
{
|
||||||
|
stack = NBTHelper.checkNBT(stack);
|
||||||
|
|
||||||
|
stack.getTagCompound().setString(Constants.NBT.OWNER_NAME, ownerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Owner UUID of the item without checking if it is already bound. Also
|
||||||
|
* bypasses {@link ItemBindEvent}.
|
||||||
|
*
|
||||||
|
* @param stack
|
||||||
|
* - The ItemStack to bind
|
||||||
|
* @param ownerUUID
|
||||||
|
* - The UUID to bind the ItemStack to
|
||||||
|
*/
|
||||||
|
public static void setItemOwnerUUID(ItemStack stack, String ownerUUID)
|
||||||
|
{
|
||||||
|
stack = NBTHelper.checkNBT(stack);
|
||||||
|
|
||||||
|
stack.getTagCompound().setString(Constants.NBT.OWNER_UUID, ownerUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to safely obtain the username of the ItemStack's owner
|
||||||
|
*
|
||||||
|
* @param stack
|
||||||
|
* - The ItemStack to check the owner of
|
||||||
|
*
|
||||||
|
* @return - The username of the ItemStack's owner
|
||||||
|
*/
|
||||||
|
public static String getOwnerName(ItemStack stack)
|
||||||
|
{
|
||||||
|
stack = NBTHelper.checkNBT(stack);
|
||||||
|
|
||||||
|
return PlayerHelper.getUsernameFromStack(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to safely obtain the UUID of the ItemStack's owner
|
||||||
|
*
|
||||||
|
* @param stack
|
||||||
|
* - The ItemStack to check the owner of
|
||||||
|
*
|
||||||
|
* @return - The UUID of the ItemStack's owner
|
||||||
|
*/
|
||||||
|
public static String getOwnerUUID(ItemStack stack)
|
||||||
|
{
|
||||||
|
stack = NBTHelper.checkNBT(stack);
|
||||||
|
|
||||||
|
return stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Everything below is to be removed.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deprecated.
|
||||||
|
*
|
||||||
|
* Now handled automatically with {@link WayofTime.bloodmagic.util.handler.EventHandler#interactEvent(PlayerInteractEvent)}
|
||||||
|
*
|
||||||
* @param stack
|
* @param stack
|
||||||
* - The ItemStack to bind
|
* - The ItemStack to bind
|
||||||
* @param player
|
* @param player
|
||||||
* - The Player to bind the ItemStack to
|
* - The Player to bind the ItemStack to
|
||||||
*
|
*
|
||||||
* @return - Whether binding was successful
|
* @return - Whether binding was successful
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static boolean checkAndSetItemOwner(ItemStack stack, EntityPlayer player)
|
public static boolean checkAndSetItemOwner(ItemStack stack, EntityPlayer player)
|
||||||
{
|
{
|
||||||
return !PlayerHelper.isFakePlayer(player) && checkAndSetItemOwner(stack, PlayerHelper.getUUIDFromPlayer(player), player.getName());
|
return !PlayerHelper.isFakePlayer(player) && checkAndSetItemOwner(stack, PlayerHelper.getUUIDFromPlayer(player), player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bind an item to a username.
|
* Deprecated.
|
||||||
*
|
*
|
||||||
* Requires the Item contained in the ItemStack to be an instanceof
|
* Now handled automatically with {@link WayofTime.bloodmagic.util.handler.EventHandler#interactEvent(PlayerInteractEvent)}
|
||||||
* {@link IBindable}
|
*
|
||||||
*
|
|
||||||
* Fires {@link ItemBindEvent}.
|
|
||||||
*
|
|
||||||
* @param stack
|
* @param stack
|
||||||
* - The ItemStack to bind
|
* - The ItemStack to bind
|
||||||
* @param uuid
|
* @param uuid
|
||||||
* - The username to bind the ItemStack to
|
* - The username to bind the ItemStack to
|
||||||
* @param currentUsername
|
* @param currentUsername
|
||||||
* - The current name of the player.
|
* - The current name of the player.
|
||||||
*
|
*
|
||||||
* @return - Whether the binding was successful
|
* @return - Whether the binding was successful
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static boolean checkAndSetItemOwner(ItemStack stack, String uuid, String currentUsername)
|
public static boolean checkAndSetItemOwner(ItemStack stack, String uuid, String currentUsername)
|
||||||
{
|
{
|
||||||
stack = NBTHelper.checkNBT(stack);
|
stack = NBTHelper.checkNBT(stack);
|
||||||
|
@ -70,8 +134,10 @@ public class BindableHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see BindableHelper#checkAndSetItemOwner(ItemStack, String)
|
* Deprecated.
|
||||||
*
|
*
|
||||||
|
* Now handled automatically with {@link WayofTime.bloodmagic.util.handler.EventHandler#interactEvent(PlayerInteractEvent)}
|
||||||
|
*
|
||||||
* @param stack
|
* @param stack
|
||||||
* - ItemStack to check
|
* - ItemStack to check
|
||||||
* @param uuid
|
* @param uuid
|
||||||
|
@ -79,54 +145,25 @@ public class BindableHelper
|
||||||
* @param currentUsername
|
* @param currentUsername
|
||||||
* - The current name of the player.
|
* - The current name of the player.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static boolean checkAndSetItemOwner(ItemStack stack, UUID uuid, String currentUsername)
|
public static boolean checkAndSetItemOwner(ItemStack stack, UUID uuid, String currentUsername)
|
||||||
{
|
{
|
||||||
return checkAndSetItemOwner(stack, uuid.toString(), currentUsername);
|
return checkAndSetItemOwner(stack, uuid.toString(), currentUsername);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the Owner of the item without checking if it is already bound. Also
|
* Deprecated.
|
||||||
* bypasses {@link ItemBindEvent}.
|
*
|
||||||
*
|
* @see #setItemOwnerName(ItemStack, String)
|
||||||
|
*
|
||||||
* @param stack
|
* @param stack
|
||||||
* - The ItemStack to bind
|
* - The ItemStack to bind
|
||||||
* @param ownerName
|
* @param ownerName
|
||||||
* - The username to bind the ItemStack to
|
* - The username to bind the ItemStack to
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static void setItemOwner(ItemStack stack, String ownerName)
|
public static void setItemOwner(ItemStack stack, String ownerName)
|
||||||
{
|
{
|
||||||
stack = NBTHelper.checkNBT(stack);
|
setItemOwnerName(stack, ownerName);
|
||||||
|
|
||||||
stack.getTagCompound().setString(Constants.NBT.OWNER_UUID, ownerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to safely obtain the username of the ItemStack's owner
|
|
||||||
*
|
|
||||||
* @param stack
|
|
||||||
* - The ItemStack to check the owner of
|
|
||||||
*
|
|
||||||
* @return - The username of the ItemStack's owner
|
|
||||||
*/
|
|
||||||
public static String getOwnerName(ItemStack stack)
|
|
||||||
{
|
|
||||||
stack = NBTHelper.checkNBT(stack);
|
|
||||||
|
|
||||||
return PlayerHelper.getUsernameFromStack(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to safely obtain the UUID of the ItemStack's owner
|
|
||||||
*
|
|
||||||
* @param stack
|
|
||||||
* - The ItemStack to check the owner of
|
|
||||||
*
|
|
||||||
* @return - The UUID of the ItemStack's owner
|
|
||||||
*/
|
|
||||||
public static String getOwnerUUID(ItemStack stack)
|
|
||||||
{
|
|
||||||
stack = NBTHelper.checkNBT(stack);
|
|
||||||
|
|
||||||
return stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,13 +41,9 @@ public class BlockTeleposer extends BlockContainer
|
||||||
ItemStack playerItem = player.getCurrentEquippedItem();
|
ItemStack playerItem = player.getCurrentEquippedItem();
|
||||||
|
|
||||||
if (playerItem != null && playerItem.getItem() instanceof ItemTelepositionFocus)
|
if (playerItem != null && playerItem.getItem() instanceof ItemTelepositionFocus)
|
||||||
{
|
|
||||||
BindableHelper.checkAndSetItemOwner(playerItem, player);
|
|
||||||
((ItemTelepositionFocus) playerItem.getItem()).setBlockPos(playerItem, world, pos);
|
((ItemTelepositionFocus) playerItem.getItem()).setBlockPos(playerItem, world, pos);
|
||||||
} else if (world.getTileEntity(pos) instanceof TileTeleposer)
|
else if (world.getTileEntity(pos) instanceof TileTeleposer)
|
||||||
{
|
|
||||||
player.openGui(BloodMagic.instance, Constants.Gui.TELEPOSER_GUI, world, pos.getX(), pos.getY(), pos.getZ());
|
player.openGui(BloodMagic.instance, Constants.Gui.TELEPOSER_GUI, world, pos.getX(), pos.getY(), pos.getZ());
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,52 +154,6 @@ public class ItemBindable extends Item implements IBindable
|
||||||
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.currentOwner", PlayerHelper.getUsernameFromStack(stack)));
|
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.currentOwner", PlayerHelper.getUsernameFromStack(stack)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
|
||||||
{
|
|
||||||
BindableHelper.checkAndSetItemOwner(stack, player);
|
|
||||||
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
|
|
||||||
{
|
|
||||||
BindableHelper.checkAndSetItemOwner(stack, player);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void damagePlayer(World world, EntityPlayer player, int damage)
|
|
||||||
{
|
|
||||||
if (world != null)
|
|
||||||
{
|
|
||||||
double posX = player.posX;
|
|
||||||
double posY = player.posY;
|
|
||||||
double posZ = player.posZ;
|
|
||||||
world.playSoundEffect((double) ((float) posX + 0.5F), (double) ((float) posY + 0.5F), (double) ((float) posZ + 0.5F), "random.fizz", 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
|
|
||||||
float f = 1.0F;
|
|
||||||
float f1 = f * 0.6F + 0.4F;
|
|
||||||
float f2 = f * f * 0.7F - 0.5F;
|
|
||||||
float f3 = f * f * 0.6F - 0.7F;
|
|
||||||
for (int l = 0; l < 8; ++l)
|
|
||||||
world.spawnParticle(EnumParticleTypes.REDSTONE, posX + Math.random() - Math.random(), posY + Math.random() - Math.random(), posZ + Math.random() - Math.random(), f1, f2, f3);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < damage; i++)
|
|
||||||
{
|
|
||||||
player.attackEntityFrom(BloodMagicAPI.getDamageSource(), 0F); // Emulate
|
|
||||||
// an
|
|
||||||
// attack
|
|
||||||
player.setHealth(player.getHealth() - 1);
|
|
||||||
|
|
||||||
if (player.getHealth() <= 0.0005)
|
|
||||||
{
|
|
||||||
player.inventory.dropAllItems();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLPUsed()
|
public int getLPUsed()
|
||||||
{
|
{
|
||||||
return this.lpUsed;
|
return this.lpUsed;
|
||||||
|
|
|
@ -45,8 +45,6 @@ public class ItemBloodOrb extends ItemBindable implements IBloodOrb, IBindable
|
||||||
@Override
|
@Override
|
||||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||||
{
|
{
|
||||||
super.onItemRightClick(stack, world, player);
|
|
||||||
|
|
||||||
if (world == null)
|
if (world == null)
|
||||||
return stack;
|
return stack;
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,6 @@ public class ItemBoundSword extends ItemSword implements IBindable
|
||||||
@Override
|
@Override
|
||||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||||
{
|
{
|
||||||
BindableHelper.checkAndSetItemOwner(stack, player);
|
|
||||||
|
|
||||||
if (!player.isSneaking() && getActivated(stack))
|
if (!player.isSneaking() && getActivated(stack))
|
||||||
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
||||||
|
|
||||||
|
|
|
@ -110,8 +110,6 @@ public class ItemBoundTool extends ItemBindable
|
||||||
@Override
|
@Override
|
||||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||||
{
|
{
|
||||||
BindableHelper.checkAndSetItemOwner(stack, player);
|
|
||||||
|
|
||||||
// if (!world.isRemote)
|
// if (!world.isRemote)
|
||||||
{
|
{
|
||||||
if (player.isSneaking())
|
if (player.isSneaking())
|
||||||
|
@ -136,15 +134,6 @@ public class ItemBoundTool extends ItemBindable
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ)
|
|
||||||
{
|
|
||||||
if (BindableHelper.checkAndSetItemOwner(stack, player) && ItemBindable.syphonNetwork(stack, player, getLPUsed()))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
|
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,16 +52,13 @@ public class ItemTelepositionFocus extends ItemBindable
|
||||||
@Override
|
@Override
|
||||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||||
{
|
{
|
||||||
if (BindableHelper.checkAndSetItemOwner(stack, player))
|
if (player.isSneaking())
|
||||||
{
|
{
|
||||||
if (player.isSneaking())
|
MovingObjectPosition mop = getMovingObjectPositionFromPlayer(world, player, false);
|
||||||
{
|
|
||||||
MovingObjectPosition mop = getMovingObjectPositionFromPlayer(world, player, false);
|
|
||||||
|
|
||||||
if (mop != null && mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
|
if (mop != null && mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
|
||||||
{
|
{
|
||||||
setBlockPos(stack, world, mop.getBlockPos());
|
setBlockPos(stack, world, mop.getBlockPos());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,14 +48,6 @@ public class ItemSigilBase extends ItemBindable implements ISigil
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
|
|
||||||
{
|
|
||||||
super.onItemRightClick(stack, world, player);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced)
|
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced)
|
||||||
|
|
|
@ -23,22 +23,17 @@ public class ItemSigilBloodLight extends ItemSigilBase
|
||||||
@Override
|
@Override
|
||||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||||
{
|
{
|
||||||
if (BindableHelper.checkAndSetItemOwner(stack, player) && ItemBindable.syphonNetwork(stack, player, getLPUsed() * 5) && !world.isRemote)
|
MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(world, player, false);
|
||||||
|
|
||||||
|
if (mop != null && mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
|
||||||
{
|
{
|
||||||
MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(world, player, false);
|
BlockPos blockPos = mop.getBlockPos().offset(mop.sideHit);
|
||||||
|
|
||||||
if (mop != null && mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
|
if (world.isAirBlock(blockPos))
|
||||||
{
|
world.setBlockState(blockPos, ModBlocks.bloodLight.getDefaultState());
|
||||||
BlockPos blockPos = mop.getBlockPos().offset(mop.sideHit);
|
} else
|
||||||
|
{
|
||||||
if (world.isAirBlock(blockPos))
|
world.spawnEntityInWorld(new EntityBloodLight(world, player));
|
||||||
{
|
|
||||||
world.setBlockState(blockPos, ModBlocks.bloodLight.getDefaultState());
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
world.spawnEntityInWorld(new EntityBloodLight(world, player));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
|
@ -52,15 +47,10 @@ public class ItemSigilBloodLight extends ItemSigilBase
|
||||||
if (world.isRemote)
|
if (world.isRemote)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (BindableHelper.checkAndSetItemOwner(stack, player) && ItemBindable.syphonNetwork(stack, player, getLPUsed()))
|
BlockPos newPos = blockPos.offset(side);
|
||||||
{
|
|
||||||
BlockPos newPos = blockPos.offset(side);
|
|
||||||
|
|
||||||
if (world.isAirBlock(newPos))
|
if (world.isAirBlock(newPos))
|
||||||
{
|
world.setBlockState(newPos, ModBlocks.bloodLight.getDefaultState());
|
||||||
world.setBlockState(newPos, ModBlocks.bloodLight.getDefaultState());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class ItemSigilLava extends ItemSigilBase
|
||||||
{
|
{
|
||||||
super.onItemUse(stack, player, world, blockPos, side, hitX, hitY, hitZ);
|
super.onItemUse(stack, player, world, blockPos, side, hitX, hitY, hitZ);
|
||||||
|
|
||||||
if (world.isRemote || !BindableHelper.checkAndSetItemOwner(stack, player) || player.isSneaking() || isUnusable(stack))
|
if (world.isRemote || player.isSneaking() || isUnusable(stack))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@ public class ItemSigilToggleable extends ItemSigilBase
|
||||||
@Override
|
@Override
|
||||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||||
{
|
{
|
||||||
BindableHelper.checkAndSetItemOwner(stack, player);
|
|
||||||
if (!world.isRemote && !isUnusable(stack))
|
if (!world.isRemote && !isUnusable(stack))
|
||||||
{
|
{
|
||||||
if (player.isSneaking())
|
if (player.isSneaking())
|
||||||
|
@ -52,12 +51,7 @@ public class ItemSigilToggleable extends ItemSigilBase
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ)
|
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ)
|
||||||
{
|
{
|
||||||
super.onItemUse(stack, player, world, blockPos, side, hitX, hitY, hitZ);
|
return ItemBindable.syphonNetwork(stack, player, getLPUsed()) && onSigilUse(stack, player, world, blockPos, side, hitX, hitY, hitZ);
|
||||||
|
|
||||||
if (BindableHelper.checkAndSetItemOwner(stack, player) && ItemBindable.syphonNetwork(stack, player, getLPUsed()))
|
|
||||||
return onSigilUse(stack, player, world, blockPos, side, hitX, hitY, hitZ);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onSigilUse(ItemStack itemStack, EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ)
|
public boolean onSigilUse(ItemStack itemStack, EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ)
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class ItemSigilVoid extends ItemSigilBase
|
||||||
{
|
{
|
||||||
super.onItemUse(stack, player, world, blockPos, side, hitX, hitY, hitZ);
|
super.onItemUse(stack, player, world, blockPos, side, hitX, hitY, hitZ);
|
||||||
|
|
||||||
if (world.isRemote || !BindableHelper.checkAndSetItemOwner(stack, player) || player.isSneaking() || isUnusable(stack))
|
if (world.isRemote || player.isSneaking() || isUnusable(stack))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class ItemSigilWater extends ItemSigilBase
|
||||||
{
|
{
|
||||||
super.onItemUse(stack, player, world, blockPos, side, hitX, hitY, hitZ);
|
super.onItemUse(stack, player, world, blockPos, side, hitX, hitY, hitZ);
|
||||||
|
|
||||||
if (world.isRemote || !BindableHelper.checkAndSetItemOwner(stack, player) || player.isSneaking() || isUnusable(stack))
|
if (world.isRemote || player.isSneaking() || isUnusable(stack))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,13 @@ package WayofTime.bloodmagic.util.handler;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import WayofTime.bloodmagic.api.event.ItemBindEvent;
|
||||||
|
import WayofTime.bloodmagic.api.iface.IBindable;
|
||||||
|
import WayofTime.bloodmagic.api.util.helper.BindableHelper;
|
||||||
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
|
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.enchantment.Enchantment;
|
import net.minecraft.enchantment.Enchantment;
|
||||||
import net.minecraft.enchantment.EnchantmentHelper;
|
import net.minecraft.enchantment.EnchantmentHelper;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
@ -19,6 +24,7 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.potion.PotionEffect;
|
import net.minecraft.potion.PotionEffect;
|
||||||
import net.minecraft.util.DamageSource;
|
import net.minecraft.util.DamageSource;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.event.AnvilUpdateEvent;
|
import net.minecraftforge.event.AnvilUpdateEvent;
|
||||||
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
||||||
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
||||||
|
@ -182,6 +188,42 @@ public class EventHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void interactEvent(PlayerInteractEvent event)
|
||||||
|
{
|
||||||
|
if (event.world.isRemote)
|
||||||
|
return;
|
||||||
|
|
||||||
|
EntityPlayer player = event.entityPlayer;
|
||||||
|
|
||||||
|
if (PlayerHelper.isFakePlayer(player))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (event.useBlock == Result.DENY && event.useItem != Result.DENY)
|
||||||
|
{
|
||||||
|
ItemStack held = player.getHeldItem();
|
||||||
|
if (held != null && held.getItem() instanceof IBindable)
|
||||||
|
{
|
||||||
|
held = NBTHelper.checkNBT(held);
|
||||||
|
if (Strings.isNullOrEmpty(BindableHelper.getOwnerUUID(held)))
|
||||||
|
{
|
||||||
|
IBindable bindable = (IBindable) held.getItem();
|
||||||
|
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 (BindableHelper.getOwnerUUID(held).equals(PlayerHelper.getUUIDFromPlayer(player).toString()) && !BindableHelper.getOwnerName(held).equals(player.getDisplayNameString()))
|
||||||
|
BindableHelper.setItemOwnerName(held, player.getDisplayNameString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void selfSacrificeEvent(SacrificeKnifeUsedEvent event)
|
public void selfSacrificeEvent(SacrificeKnifeUsedEvent event)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue