Run formatter
This commit is contained in:
parent
61c44a831b
commit
08258fd6ef
606 changed files with 13464 additions and 22975 deletions
|
@ -1,17 +1,22 @@
|
|||
package WayofTime.bloodmagic.item;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.api.ItemStackWrapper;
|
||||
import WayofTime.bloodmagic.api.event.BoundToolEvent;
|
||||
import WayofTime.bloodmagic.api.iface.IActivatable;
|
||||
import WayofTime.bloodmagic.api.iface.IBindable;
|
||||
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
|
||||
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
|
||||
import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
|
||||
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
|
||||
import WayofTime.bloodmagic.util.Utils;
|
||||
import WayofTime.bloodmagic.util.helper.TextHelper;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Multiset;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
|
@ -23,7 +28,6 @@ import net.minecraft.entity.item.EntityItem;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemTool;
|
||||
import net.minecraft.util.ActionResult;
|
||||
|
@ -35,30 +39,20 @@ import net.minecraft.world.World;
|
|||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.api.ItemStackWrapper;
|
||||
import WayofTime.bloodmagic.api.event.BoundToolEvent;
|
||||
import WayofTime.bloodmagic.api.iface.IActivatable;
|
||||
import WayofTime.bloodmagic.api.iface.IBindable;
|
||||
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
|
||||
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
|
||||
import WayofTime.bloodmagic.util.helper.TextHelper;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multiset;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ItemBoundTool extends ItemTool implements IBindable, IActivatable
|
||||
{
|
||||
public class ItemBoundTool extends ItemTool implements IBindable, IActivatable {
|
||||
public final int chargeTime = 30;
|
||||
protected final String tooltipBase;
|
||||
private final String name;
|
||||
|
||||
public Map<ItemStack, Boolean> heldDownMap = new HashMap<ItemStack, Boolean>();
|
||||
public Map<ItemStack, Integer> heldDownCountMap = new HashMap<ItemStack, Integer>();
|
||||
|
||||
public final int chargeTime = 30;
|
||||
|
||||
public ItemBoundTool(String name, float damage, Set<Block> effectiveBlocks)
|
||||
{
|
||||
public ItemBoundTool(String name, float damage, Set<Block> effectiveBlocks) {
|
||||
super(damage, 1, RegistrarBloodMagicItems.BOUND_TOOL_MATERIAL, effectiveBlocks);
|
||||
setUnlocalizedName(BloodMagic.MODID + ".bound." + name);
|
||||
setCreativeTab(BloodMagic.TAB_BM);
|
||||
|
@ -69,20 +63,17 @@ public class ItemBoundTool extends ItemTool implements IBindable, IActivatable
|
|||
}
|
||||
|
||||
@Override
|
||||
public float getStrVsBlock(ItemStack stack, IBlockState state)
|
||||
{
|
||||
public float getStrVsBlock(ItemStack stack, IBlockState state) {
|
||||
return getActivated(stack) ? toolMaterial.getEfficiencyOnProperMaterial() : 1.0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged)
|
||||
{
|
||||
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
|
||||
return slotChanged;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> subItems)
|
||||
{
|
||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> subItems) {
|
||||
if (isInCreativeTab(tab))
|
||||
return;
|
||||
|
||||
|
@ -90,19 +81,16 @@ public class ItemBoundTool extends ItemTool implements IBindable, IActivatable
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected)
|
||||
{
|
||||
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) {
|
||||
if (Strings.isNullOrEmpty(getOwnerUUID(stack))) {
|
||||
setActivatedState(stack, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity instanceof EntityPlayer && getActivated(stack) && isSelected && getBeingHeldDown(stack) && stack == ((EntityPlayer) entity).getActiveItemStack())
|
||||
{
|
||||
if (entity instanceof EntityPlayer && getActivated(stack) && isSelected && getBeingHeldDown(stack) && stack == ((EntityPlayer) entity).getActiveItemStack()) {
|
||||
EntityPlayer player = (EntityPlayer) entity;
|
||||
setHeldDownCount(stack, Math.min(player.getItemInUseCount(), chargeTime));
|
||||
} else if (!isSelected)
|
||||
{
|
||||
} else if (!isSelected) {
|
||||
setBeingHeldDown(stack, false);
|
||||
}
|
||||
|
||||
|
@ -110,41 +98,35 @@ public class ItemBoundTool extends ItemTool implements IBindable, IActivatable
|
|||
NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage((EntityPlayer) entity, 20);
|
||||
}
|
||||
|
||||
protected int getHeldDownCount(ItemStack stack)
|
||||
{
|
||||
protected int getHeldDownCount(ItemStack stack) {
|
||||
if (!heldDownCountMap.containsKey(stack))
|
||||
return 0;
|
||||
|
||||
return heldDownCountMap.get(stack);
|
||||
}
|
||||
|
||||
protected void setHeldDownCount(ItemStack stack, int count)
|
||||
{
|
||||
protected void setHeldDownCount(ItemStack stack, int count) {
|
||||
heldDownCountMap.put(stack, count);
|
||||
}
|
||||
|
||||
protected boolean getBeingHeldDown(ItemStack stack)
|
||||
{
|
||||
protected boolean getBeingHeldDown(ItemStack stack) {
|
||||
if (!heldDownMap.containsKey(stack))
|
||||
return false;
|
||||
|
||||
return heldDownMap.get(stack);
|
||||
}
|
||||
|
||||
protected void setBeingHeldDown(ItemStack stack, boolean heldDown)
|
||||
{
|
||||
protected void setBeingHeldDown(ItemStack stack, boolean heldDown) {
|
||||
heldDownMap.put(stack, heldDown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
|
||||
{
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
||||
ItemStack stack = player.getHeldItem(hand);
|
||||
if (player.isSneaking())
|
||||
setActivatedState(stack, !getActivated(stack));
|
||||
|
||||
if (!player.isSneaking() && getActivated(stack))
|
||||
{
|
||||
if (!player.isSneaking() && getActivated(stack)) {
|
||||
BoundToolEvent.Charge event = new BoundToolEvent.Charge(player, stack);
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
return new ActionResult<>(EnumActionResult.FAIL, event.result);
|
||||
|
@ -157,13 +139,10 @@ public class ItemBoundTool extends ItemTool implements IBindable, IActivatable
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft)
|
||||
{
|
||||
if (entityLiving instanceof EntityPlayer)
|
||||
{
|
||||
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
|
||||
if (entityLiving instanceof EntityPlayer) {
|
||||
EntityPlayer player = (EntityPlayer) entityLiving;
|
||||
if (!player.isSneaking() && getActivated(stack))
|
||||
{
|
||||
if (!player.isSneaking() && getActivated(stack)) {
|
||||
int i = this.getMaxItemUseDuration(stack) - timeLeft;
|
||||
BoundToolEvent.Release event = new BoundToolEvent.Release(player, stack, i);
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
|
@ -177,39 +156,33 @@ public class ItemBoundTool extends ItemTool implements IBindable, IActivatable
|
|||
}
|
||||
}
|
||||
|
||||
protected void onBoundRelease(ItemStack stack, World world, EntityPlayer player, int charge)
|
||||
{
|
||||
protected void onBoundRelease(ItemStack stack, World world, EntityPlayer player, int charge) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase entityLiving)
|
||||
{
|
||||
public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase entityLiving) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxItemUseDuration(ItemStack stack)
|
||||
{
|
||||
public int getMaxItemUseDuration(ItemStack stack) {
|
||||
return 72000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumAction getItemUseAction(ItemStack stack)
|
||||
{
|
||||
public EnumAction getItemUseAction(ItemStack stack) {
|
||||
return EnumAction.BOW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
public int getItemEnchantability() {
|
||||
return 50;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag)
|
||||
{
|
||||
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag) {
|
||||
if (TextHelper.canTranslate(tooltipBase + "desc"))
|
||||
tooltip.add(TextHelper.localizeEffect(tooltipBase + "desc"));
|
||||
|
||||
|
@ -225,80 +198,51 @@ public class ItemBoundTool extends ItemTool implements IBindable, IActivatable
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getToolClasses(ItemStack stack)
|
||||
{
|
||||
public Set<String> getToolClasses(ItemStack stack) {
|
||||
return ImmutableSet.of(name);
|
||||
}
|
||||
|
||||
public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot)
|
||||
{
|
||||
public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot) {
|
||||
return ArrayListMultimap.create(); // No-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showDurabilityBar(ItemStack stack)
|
||||
{
|
||||
public boolean showDurabilityBar(ItemStack stack) {
|
||||
return getActivated(stack) && getBeingHeldDown(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDurabilityForDisplay(ItemStack stack)
|
||||
{
|
||||
public double getDurabilityForDisplay(ItemStack stack) {
|
||||
return ((double) -Math.min(getHeldDownCount(stack), chargeTime) / chargeTime) + 1;
|
||||
}
|
||||
|
||||
protected static void dropStacks(Multiset<ItemStackWrapper> drops, World world, BlockPos posToDrop)
|
||||
{
|
||||
for (Multiset.Entry<ItemStackWrapper> entry : drops.entrySet())
|
||||
{
|
||||
int count = entry.getCount();
|
||||
ItemStackWrapper stack = entry.getElement();
|
||||
int maxStackSize = stack.item.getItemStackLimit(stack.toStack(1));
|
||||
|
||||
while (count >= maxStackSize)
|
||||
{
|
||||
world.spawnEntity(new EntityItem(world, posToDrop.getX(), posToDrop.getY(), posToDrop.getZ(), stack.toStack(maxStackSize)));
|
||||
count -= maxStackSize;
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
world.spawnEntity(new EntityItem(world, posToDrop.getX(), posToDrop.getY(), posToDrop.getZ(), stack.toStack(count)));
|
||||
}
|
||||
@Override
|
||||
public String getOwnerName(ItemStack stack) {
|
||||
return stack != null ? NBTHelper.checkNBT(stack).getTagCompound().getString(Constants.NBT.OWNER_NAME) : null;
|
||||
}
|
||||
|
||||
// IBindable
|
||||
|
||||
@Override
|
||||
public String getOwnerName(ItemStack stack)
|
||||
{
|
||||
return stack != null ? NBTHelper.checkNBT(stack).getTagCompound().getString(Constants.NBT.OWNER_NAME) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOwnerUUID(ItemStack stack)
|
||||
{
|
||||
public String getOwnerUUID(ItemStack stack) {
|
||||
return stack != null ? NBTHelper.checkNBT(stack).getTagCompound().getString(Constants.NBT.OWNER_UUID) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBind(EntityPlayer player, ItemStack stack)
|
||||
{
|
||||
public boolean onBind(EntityPlayer player, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getActivated(ItemStack stack) {
|
||||
return stack != null && NBTHelper.checkNBT(stack).getTagCompound().getBoolean(Constants.NBT.ACTIVATED);
|
||||
}
|
||||
|
||||
// IActivatable
|
||||
|
||||
@Override
|
||||
public boolean getActivated(ItemStack stack)
|
||||
{
|
||||
return stack != null && NBTHelper.checkNBT(stack).getTagCompound().getBoolean(Constants.NBT.ACTIVATED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack setActivatedState(ItemStack stack, boolean activated)
|
||||
{
|
||||
if (stack != null)
|
||||
{
|
||||
public ItemStack setActivatedState(ItemStack stack, boolean activated) {
|
||||
if (stack != null) {
|
||||
NBTHelper.checkNBT(stack).getTagCompound().setBoolean(Constants.NBT.ACTIVATED, activated);
|
||||
return stack;
|
||||
}
|
||||
|
@ -325,4 +269,20 @@ public class ItemBoundTool extends ItemTool implements IBindable, IActivatable
|
|||
public int getChargeTime() {
|
||||
return chargeTime;
|
||||
}
|
||||
|
||||
protected static void dropStacks(Multiset<ItemStackWrapper> drops, World world, BlockPos posToDrop) {
|
||||
for (Multiset.Entry<ItemStackWrapper> entry : drops.entrySet()) {
|
||||
int count = entry.getCount();
|
||||
ItemStackWrapper stack = entry.getElement();
|
||||
int maxStackSize = stack.item.getItemStackLimit(stack.toStack(1));
|
||||
|
||||
while (count >= maxStackSize) {
|
||||
world.spawnEntity(new EntityItem(world, posToDrop.getX(), posToDrop.getY(), posToDrop.getZ(), stack.toStack(maxStackSize)));
|
||||
count -= maxStackSize;
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
world.spawnEntity(new EntityItem(world, posToDrop.getX(), posToDrop.getY(), posToDrop.getZ(), stack.toStack(count)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue