2015-11-03 15:34:11 +00:00
|
|
|
package WayofTime.bloodmagic.item;
|
|
|
|
|
2016-06-28 15:55:58 +00:00
|
|
|
import WayofTime.bloodmagic.ConfigHandler;
|
2016-04-17 21:03:26 +00:00
|
|
|
import WayofTime.bloodmagic.client.IMeshProvider;
|
2018-02-14 07:32:15 +00:00
|
|
|
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
|
2018-03-08 03:43:00 +00:00
|
|
|
import WayofTime.bloodmagic.event.SacrificeKnifeUsedEvent;
|
2018-02-14 07:32:15 +00:00
|
|
|
import WayofTime.bloodmagic.item.types.ISubItem;
|
2017-08-16 04:30:48 +00:00
|
|
|
import WayofTime.bloodmagic.tile.TileAltar;
|
2018-03-08 03:43:00 +00:00
|
|
|
import WayofTime.bloodmagic.util.Constants;
|
2018-03-18 05:30:14 +00:00
|
|
|
import WayofTime.bloodmagic.util.DamageSourceBloodMagic;
|
2018-08-08 00:51:46 +00:00
|
|
|
import WayofTime.bloodmagic.util.helper.*;
|
2016-04-17 21:03:26 +00:00
|
|
|
import net.minecraft.client.renderer.ItemMeshDefinition;
|
|
|
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
2017-08-16 03:21:54 +00:00
|
|
|
import net.minecraft.client.util.ITooltipFlag;
|
2015-11-07 16:51:41 +00:00
|
|
|
import net.minecraft.entity.Entity;
|
2016-03-18 20:50:33 +00:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2015-11-07 16:51:41 +00:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2016-03-18 20:50:33 +00:00
|
|
|
import net.minecraft.init.SoundEvents;
|
2015-11-07 16:51:41 +00:00
|
|
|
import net.minecraft.item.EnumAction;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-04-11 23:57:23 +00:00
|
|
|
import net.minecraft.util.*;
|
2016-03-18 20:50:33 +00:00
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
2015-11-07 16:51:41 +00:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2016-03-18 20:08:06 +00:00
|
|
|
|
2018-02-14 07:32:15 +00:00
|
|
|
import javax.annotation.Nonnull;
|
2017-08-16 04:30:48 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
2018-02-14 07:32:15 +00:00
|
|
|
import java.util.Locale;
|
2018-03-08 03:43:00 +00:00
|
|
|
import java.util.function.Consumer;
|
2016-04-17 21:03:26 +00:00
|
|
|
|
2018-02-14 07:32:15 +00:00
|
|
|
public class ItemSacrificialDagger extends ItemEnum<ItemSacrificialDagger.DaggerType> implements IMeshProvider {
|
2015-11-07 16:51:41 +00:00
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public ItemSacrificialDagger() {
|
2018-02-14 07:32:15 +00:00
|
|
|
super(DaggerType.class, "sacrificial_dagger");
|
2015-11-07 16:51:41 +00:00
|
|
|
|
|
|
|
setHasSubtypes(true);
|
|
|
|
setMaxStackSize(1);
|
|
|
|
setFull3D();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public void addInformation(ItemStack stack, World world, List<String> list, ITooltipFlag flag) {
|
2017-01-02 09:18:29 +00:00
|
|
|
list.addAll(Arrays.asList(TextHelper.cutLongString(TextHelper.localizeEffect("tooltip.bloodmagic.sacrificialDagger.desc"))));
|
2016-06-28 22:01:53 +00:00
|
|
|
|
|
|
|
if (stack.getItemDamage() == 1)
|
2017-01-02 09:18:29 +00:00
|
|
|
list.add(TextHelper.localizeEffect("tooltip.bloodmagic.sacrificialDagger.creative"));
|
2015-11-07 16:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
|
2017-01-02 06:26:42 +00:00
|
|
|
if (entityLiving instanceof EntityPlayer && !entityLiving.getEntityWorld().isRemote)
|
2018-08-08 00:51:46 +00:00
|
|
|
if(PlayerSacrificeHelper.sacrificePlayerHealth((EntityPlayer) entityLiving))
|
|
|
|
IncenseHelper.setHasMaxIncense(stack, (EntityPlayer) entityLiving, false);
|
2015-11-07 16:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public int getMaxItemUseDuration(ItemStack stack) {
|
2015-11-07 16:51:41 +00:00
|
|
|
return 72000;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public EnumAction getItemUseAction(ItemStack stack) {
|
2015-11-07 16:51:41 +00:00
|
|
|
return EnumAction.BOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
2017-01-02 06:26:42 +00:00
|
|
|
ItemStack stack = player.getHeldItem(hand);
|
2015-12-02 07:35:09 +00:00
|
|
|
if (PlayerHelper.isFakePlayer(player))
|
2017-01-02 06:26:42 +00:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-12-02 07:35:09 +00:00
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
if (this.canUseForSacrifice(stack)) {
|
2016-03-18 20:50:33 +00:00
|
|
|
player.setActiveHand(hand);
|
2018-03-02 03:27:38 +00:00
|
|
|
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
|
2015-11-07 16:51:41 +00:00
|
|
|
}
|
|
|
|
|
2017-08-20 01:56:50 +00:00
|
|
|
int lpAdded = ConfigHandler.values.sacrificialDaggerConversion * 2;
|
2016-01-05 17:17:05 +00:00
|
|
|
|
2016-04-24 17:06:28 +00:00
|
|
|
RayTraceResult rayTrace = rayTrace(world, player, false);
|
2017-08-16 04:30:48 +00:00
|
|
|
if (rayTrace != null && rayTrace.typeOfHit == RayTraceResult.Type.BLOCK) {
|
2016-04-24 17:06:28 +00:00
|
|
|
TileEntity tile = world.getTileEntity(rayTrace.getBlockPos());
|
2016-03-15 01:58:13 +00:00
|
|
|
|
|
|
|
if (tile != null && tile instanceof TileAltar && stack.getItemDamage() == 1)
|
|
|
|
lpAdded = ((TileAltar) tile).getCapacity();
|
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
if (!player.capabilities.isCreativeMode) {
|
2017-08-20 01:56:50 +00:00
|
|
|
SacrificeKnifeUsedEvent evt = new SacrificeKnifeUsedEvent(player, true, true, 2, lpAdded);
|
2015-12-02 07:35:09 +00:00
|
|
|
if (MinecraftForge.EVENT_BUS.post(evt))
|
2017-01-02 06:26:42 +00:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-11-07 16:51:41 +00:00
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
if (evt.shouldDrainHealth) {
|
2015-12-02 07:35:09 +00:00
|
|
|
player.hurtResistantTime = 0;
|
2018-03-18 05:30:14 +00:00
|
|
|
player.attackEntityFrom(DamageSourceBloodMagic.INSTANCE, 0.001F);
|
2017-08-20 01:56:50 +00:00
|
|
|
player.setHealth(Math.max(player.getHealth() - 2, 0.0001f));
|
2017-08-16 04:30:48 +00:00
|
|
|
if (player.getHealth() <= 0.001f) {
|
2018-03-18 05:30:14 +00:00
|
|
|
player.onDeath(DamageSourceBloodMagic.INSTANCE);
|
2016-02-14 13:26:19 +00:00
|
|
|
player.setHealth(0);
|
|
|
|
}
|
|
|
|
// player.attackEntityFrom(BloodMagicAPI.getDamageSource(), 2.0F);
|
2015-11-07 16:51:41 +00:00
|
|
|
}
|
|
|
|
|
2015-12-02 07:35:09 +00:00
|
|
|
if (!evt.shouldFillAltar)
|
2017-01-02 06:26:42 +00:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2016-01-05 17:17:05 +00:00
|
|
|
|
|
|
|
lpAdded = evt.lpAdded;
|
2015-11-07 16:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double posX = player.posX;
|
|
|
|
double posY = player.posY;
|
|
|
|
double posZ = player.posZ;
|
2016-04-24 17:06:28 +00:00
|
|
|
world.playSound(null, posX, posY, posZ, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
|
2015-11-07 16:51:41 +00:00
|
|
|
|
2015-12-02 07:35:09 +00:00
|
|
|
for (int l = 0; l < 8; ++l)
|
2016-01-27 00:39:39 +00:00
|
|
|
world.spawnParticle(EnumParticleTypes.REDSTONE, posX + Math.random() - Math.random(), posY + Math.random() - Math.random(), posZ + Math.random() - Math.random(), 0, 0, 0);
|
2015-11-07 16:51:41 +00:00
|
|
|
|
2018-08-08 00:51:46 +00:00
|
|
|
if (!world.isRemote && PlayerHelper.isFakePlayer(player) || player.isPotionActive(PlayerSacrificeHelper.soulFrayId))
|
2017-01-02 06:26:42 +00:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-11-07 16:51:41 +00:00
|
|
|
|
2018-08-08 00:51:46 +00:00
|
|
|
|
2016-04-17 07:03:53 +00:00
|
|
|
PlayerSacrificeHelper.findAndFillAltar(world, player, lpAdded, false);
|
2015-11-07 16:51:41 +00:00
|
|
|
|
2017-01-02 06:26:42 +00:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-11-07 16:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) {
|
2018-08-08 00:51:46 +00:00
|
|
|
if (!world.isRemote && entity instanceof EntityPlayer) {
|
|
|
|
boolean prepared = this.isPlayerPreparedForSacrifice(world, (EntityPlayer) entity);
|
|
|
|
this.setUseForSacrifice(stack, prepared);
|
|
|
|
if(IncenseHelper.getHasMaxIncense(stack) && !prepared)
|
|
|
|
IncenseHelper.setHasMaxIncense(stack, (EntityPlayer) entity, false);
|
|
|
|
if(prepared) {
|
|
|
|
boolean isMax = IncenseHelper.getMaxIncense((EntityPlayer) entity) == IncenseHelper.getCurrentIncense((EntityPlayer) entity);
|
|
|
|
IncenseHelper.setHasMaxIncense(stack, (EntityPlayer) entity, isMax);
|
|
|
|
}
|
|
|
|
}
|
2015-11-07 16:51:41 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public boolean isPlayerPreparedForSacrifice(World world, EntityPlayer player) {
|
2015-11-07 16:51:41 +00:00
|
|
|
return !world.isRemote && (PlayerSacrificeHelper.getPlayerIncense(player) > 0);
|
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public boolean canUseForSacrifice(ItemStack stack) {
|
2015-12-02 07:35:09 +00:00
|
|
|
stack = NBTHelper.checkNBT(stack);
|
|
|
|
return stack.getTagCompound().getBoolean(Constants.NBT.SACRIFICE);
|
2015-11-07 16:51:41 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public void setUseForSacrifice(ItemStack stack, boolean sacrifice) {
|
2015-12-02 07:35:09 +00:00
|
|
|
stack = NBTHelper.checkNBT(stack);
|
|
|
|
stack.getTagCompound().setBoolean(Constants.NBT.SACRIFICE, sacrifice);
|
2015-11-07 16:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2017-08-16 04:30:48 +00:00
|
|
|
public ItemMeshDefinition getMeshDefinition() {
|
2017-08-16 23:39:57 +00:00
|
|
|
return stack -> {
|
|
|
|
String variant = "type=normal";
|
|
|
|
if (stack.getItemDamage() != 0)
|
|
|
|
variant = "type=creative";
|
2016-04-17 21:03:26 +00:00
|
|
|
|
2017-08-16 23:39:57 +00:00
|
|
|
if (canUseForSacrifice(stack))
|
|
|
|
variant = "type=ceremonial";
|
2016-04-17 21:03:26 +00:00
|
|
|
|
2017-08-16 23:39:57 +00:00
|
|
|
return new ModelResourceLocation(getRegistryName(), variant);
|
2016-04-17 21:03:26 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-08 03:43:00 +00:00
|
|
|
public void gatherVariants(Consumer<String> variants) {
|
|
|
|
variants.accept("type=normal");
|
|
|
|
variants.accept("type=creative");
|
|
|
|
variants.accept("type=ceremonial");
|
2016-04-17 21:03:26 +00:00
|
|
|
}
|
|
|
|
|
2018-08-08 00:51:46 +00:00
|
|
|
@Override
|
|
|
|
public boolean hasEffect(ItemStack stack)
|
|
|
|
{
|
|
|
|
return IncenseHelper.getHasMaxIncense(stack) || super.hasEffect(stack);
|
|
|
|
}
|
|
|
|
|
2018-02-14 07:32:15 +00:00
|
|
|
public enum DaggerType implements ISubItem {
|
|
|
|
|
|
|
|
NORMAL,
|
2018-02-15 07:38:57 +00:00
|
|
|
CREATIVE,;
|
2018-02-14 07:32:15 +00:00
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getInternalName() {
|
|
|
|
return name().toLowerCase(Locale.ROOT);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public ItemStack getStack(int count) {
|
|
|
|
return new ItemStack(RegistrarBloodMagicItems.SACRIFICIAL_DAGGER, count, ordinal());
|
|
|
|
}
|
2015-11-07 16:51:41 +00:00
|
|
|
}
|
|
|
|
}
|