<commit_before>package ganymedes01.etfuturum.entities;

import ganymedes01.etfuturum.ModItems;
import ganymedes01.etfuturum.items.TippedArrow;
import io.netty.buffer.ByteBuf;

import java.awt.Color;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
import cpw.mods.fml.relauncher.ReflectionHelper;

public class EntityTippedArrow extends EntityArrow implements IEntityAdditionalSpawnData {

	private PotionEffect effect;

	public EntityTippedArrow(World world) {
		super(world);
	}

	public EntityTippedArrow(World world, EntityLivingBase entity, float f0) {
		super(world, entity, f0);
	}

	public EntityTippedArrow(World world, double x, double y, double z) {
		super(world, x, y, z);
	}

	public EntityTippedArrow(World world, EntityLivingBase entity, EntityLivingBase target, float f0, float f1) {
		super(world, entity, target, f0, f1);
	}

	public void setEffect(PotionEffect effect) {
		this.effect = effect;
	}

	public PotionEffect getEffect() {
		return effect;
	}

	@Override
	public void onUpdate() {
		super.onUpdate();
		if (effect != null) {
			Color colour = new Color(Potion.potionTypes[effect.getPotionID()].getLiquidColor());
			worldObj.spawnParticle("mobSpell", posX, posY, posZ, colour.getRed() / 255F, colour.getGreen() / 255F, colour.getBlue() / 255F);
		}
	}

	@Override
	public void writeEntityToNBT(NBTTagCompound nbt) {
		super.writeEntityToNBT(nbt);
		NBTTagCompound effectNBT = new NBTTagCompound();
		effect.writeCustomPotionEffectToNBT(effectNBT);
		nbt.setTag("Effect", effectNBT);
	}

	@Override
	public void readEntityFromNBT(NBTTagCompound nbt) {
		super.readEntityFromNBT(nbt);
		effect = PotionEffect.readCustomPotionEffectFromNBT((NBTTagCompound) nbt.getTag("Effect"));
	}

	@Override
	public void onCollideWithPlayer(EntityPlayer entity) {
		boolean inGround = false;
		try {
			inGround = ReflectionHelper.getPrivateValue(EntityArrow.class, this, "inGround", "field_70254_i");
		} catch (Exception e) {
		}

		if (!worldObj.isRemote && inGround && arrowShake <= 0 && effect != null) {
			boolean flag = canBePickedUp == 1 || canBePickedUp == 2 && entity.capabilities.isCreativeMode;

			ItemStack stack = new ItemStack(ModItems.tipped_arrow);
			TippedArrow.setEffect(stack, Potion.potionTypes[effect.getPotionID()], effect.getDuration());

			if (canBePickedUp == 1 && !entity.inventory.addItemStackToInventory(stack))
				flag = false;

			if (flag) {<commit_msg>Prevent crash with invalid potion effects<commit_after>package ganymedes01.etfuturum.entities;

import ganymedes01.etfuturum.ModItems;
import ganymedes01.etfuturum.items.TippedArrow;
import io.netty.buffer.ByteBuf;

import java.awt.Color;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
import cpw.mods.fml.relauncher.ReflectionHelper;

public class EntityTippedArrow extends EntityArrow implements IEntityAdditionalSpawnData {

	private PotionEffect effect;

	public EntityTippedArrow(World world) {
		super(world);
	}

	public EntityTippedArrow(World world, EntityLivingBase entity, float f0) {
		super(world, entity, f0);
	}

	public EntityTippedArrow(World world, double x, double y, double z) {
		super(world, x, y, z);
	}

	public EntityTippedArrow(World world, EntityLivingBase entity, EntityLivingBase target, float f0, float f1) {
		super(world, entity, target, f0, f1);
	}

	public void setEffect(PotionEffect effect) {
		this.effect = effect;
	}

	public PotionEffect getEffect() {
		return effect;
	}

	private boolean isEffectValid() {
		return effect != null && Potion.potionTypes[effect.getPotionID()] != null;
	}

	@Override
	public void onUpdate() {
		super.onUpdate();
		if (isEffectValid()) {
			Color colour = new Color(Potion.potionTypes[effect.getPotionID()].getLiquidColor());
			worldObj.spawnParticle("mobSpell", posX, posY, posZ, colour.getRed() / 255F, colour.getGreen() / 255F, colour.getBlue() / 255F);
		}
	}

	@Override
	public void writeEntityToNBT(NBTTagCompound nbt) {
		super.writeEntityToNBT(nbt);
		NBTTagCompound effectNBT = new NBTTagCompound();
		effect.writeCustomPotionEffectToNBT(effectNBT);
		nbt.setTag("Effect", effectNBT);
	}

	@Override
	public void readEntityFromNBT(NBTTagCompound nbt) {
		super.readEntityFromNBT(nbt);
		effect = PotionEffect.readCustomPotionEffectFromNBT((NBTTagCompound) nbt.getTag("Effect"));
	}

	@Override
	public void onCollideWithPlayer(EntityPlayer entity) {
		boolean inGround = false;
		try {
			inGround = ReflectionHelper.getPrivateValue(EntityArrow.class, this, "inGround", "field_70254_i");
		} catch (Exception e) {
		}

		if (!worldObj.isRemote && inGround && arrowShake <= 0 && isEffectValid()) {
			boolean flag = canBePickedUp == 1 || canBePickedUp == 2 && entity.capabilities.isCreativeMode;

			ItemStack stack = new ItemStack(ModItems.tipped_arrow);
			TippedArrow.setEffect(stack, Potion.potionTypes[effect.getPotionID()], effect.getDuration());

			if (canBePickedUp == 1 && !entity.inventory.addItemStackToInventory(stack))
				flag = false;

			if (flag) {
{'fraction_non_alphanumeric': 0.11240850470547228, 'fraction_numerical': 0.010456605088881143, 'mean_word_length': 5.5364464692482915, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '375614', 'n_tokens_mistral': 2074, 'n_tokens_neox': 1958, 'n_words': 383}