@Mod(modid = TotemMod.MODID, name = TotemMod.NAME, version = TotemMod.VERSION)
public class TotemMod {
public static final String
MODID = "totem",
NAME = "Totem Mod",
VERSION = "0.1";
@Mod.Instance(MODID)
public static TotemMod instance;
public static final SimpleNetworkWrapper network = NetworkRegistry.INSTANCE.newSimpleChannel(MODID);
public static Item my_totem;
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
network.registerMessage(EntityStatusMessage.Handler.class, EntityStatusMessage.class, 0, Side.CLIENT);
network.registerMessage(EntityStatusMessage.Handler.class, EntityStatusMessage.class, 0, Side.SERVER);
my_totem = new...
null
private boolean checkTotemDeathProtection(DamageSource damageSource, EntityPlayer pl)
{
if (damageSource.canHarmInCreative())
{
return false;
}
else
{
ItemStack itemstack = null;
for (EnumHand enumhand : EnumHand.values())
{
ItemStack itemstack1 = pl.getHeldItem(enumhand);
if (itemstack1.getItem() == ItemInit.CowardsTotem)
{
itemstack = itemstack1.copy();
itemstack1.shrink(1);
break;
}
}
if (itemstack != null)
{
if (pl instanceof EntityPlayerMP)
{
EntityPlayerMP entityplayermp = (EntityPlayerMP)pl;
entityplayermp.addStat(StatList.getObjectUseStats(ItemInit.CowardsTotem));
CriteriaTriggers.USED_TOTEM.trigger(entityplayermp, itemstack);
}
pl.setHealth(1.0F);
pl.clearActivePotions();
pl.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 900, 1));
pl.addPotionEffect(new PotionEffect(MobEffects.ABSORPTION, 100, 1));
pl.world.setEntityState(pl, (byte)35);
}
return itemstack != null;
}
}
Просто вставить куда-то что-то, это что-то не обязано работать.Сделал так но оно тоже не работает
К примеру использовать эвент смерти EntityLivingBase, проверять что этот EntityLivingBase является EntityPlayer (и использовать этого игрока) и если у него есть нужный предмет, то: убирается этот предмет, отменяется смерть, возможно давая всякие эффекты.
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onDeath(LivingDeathEvent event, EnumHand hd)
{
if(!event.isCanceled() && event.getEntityLiving() instanceof EntityPlayer)
{
EntityPlayer pl = (EntityPlayer) event.getEntityLiving();
if(pl.getHeldItem(hd) == new ItemStack(ItemInit.CowardsTotem)) {
pl.setHealth(1.0f);
pl.clearActivePotions();
pl.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 900, 1));
pl.addPotionEffect(new PotionEffect(MobEffects.ABSORPTION, 100, 1));
}
}
}
Нет, один аргумент должен и это эвент, а рука из игрока достаётся.(LivingDeathEvent event, EnumHand hd)
EntityPlayer player = Minecraft.getMinecraft().player;
рука из игрока.
player.getHeldItemOffhand();
player.getHeldItemMainhand();
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onDeath(LivingDeathEvent event)
{
if(!event.isCanceled() && event.getEntityLiving() instanceof EntityPlayer)
{
EntityPlayer pl = (EntityPlayer) event.getEntityLiving();
if(pl.getHeldItemOffhand() == new ItemStack(ItemInit.CowardsTotem) || pl.getHeldItemMainhand() == new ItemStack(ItemInit.CowardsTotem) ) {
pl.setHealth(1.0f);
pl.clearActivePotions();
pl.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 900, 1));
pl.addPotionEffect(new PotionEffect(MobEffects.ABSORPTION, 100, 1));
}
}
}
ItemStack itemstack = null;
for (EnumHand enumhand : EnumHand.values())
{
ItemStack itemstack1 = this.getHeldItem(enumhand);