More entity patch work. ISpecialArmor deleted.

This commit is contained in:
LexManos committed 2018-12-10 22:19:43 -08:00
1 parent 7a77298a60
commit 7265900c62
54 files changed
+1066 -1911

No files matched your search

@@ -25,7 +25,6 @@ import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
@@ -54,11 +53,9 @@ import net.minecraft.util.StringUtils;
import net.minecraft.util.Util;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.GameType;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import org.lwjgl.opengl.GL11;
@@ -299,7 +296,7 @@ public class GuiIngameForge extends GuiIngame
int left = width / 2 - 91;
int top = height - left_height;
int level = ForgeHooks.getTotalArmorValue(mc.player);
int level = mc.player.getTotalArmorValue();
for (int i = 1; level > 0 && i < 20; i += 2)
{
if (i < level)
@@ -61,6 +61,7 @@ import net.minecraft.client.gui.GuiScreen;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityMinecartContainer;
@@ -101,6 +102,7 @@ import net.minecraft.resources.IResourceManager;
import net.minecraft.stats.StatList;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.Tag;
import net.minecraft.tileentity.MobSpawnerBaseLogic;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumActionResult;
@@ -124,6 +126,7 @@ import net.minecraft.world.World;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.GameType;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.storage.loot.LootEntry;
import net.minecraft.world.storage.loot.LootTable;
import net.minecraft.world.storage.loot.LootTableManager;
@@ -155,6 +158,7 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.AdvancementEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.NoteBlockEvent;
import net.minecraftforge.eventbus.api.Event.Result;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fml.ModContainer;
import net.minecraftforge.fml.ModList;
@@ -281,20 +285,6 @@ public class ForgeHooks
blockToolSetter.accept(block, ToolType.PICKAXE, 1);
}
public static int getTotalArmorValue(EntityPlayer player)
{
int ret = player.getTotalArmorValue();
for (int x = 0; x < player.inventory.armorInventory.size(); x++)
{
ItemStack stack = player.inventory.armorInventory.get(x);
if (stack.getItem() instanceof ISpecialArmor)
{
ret += ((ISpecialArmor)stack.getItem()).getArmorDisplay(player, stack, x);
}
}
return ret;
}
/**
* Called when a player uses 'pick block', calls new Entity and Block hooks.
*/
@@ -1162,4 +1152,9 @@ public class ForgeHooks
return -1;
return event.getVanillaNoteId();
}
public static int canEntitySpawn(EntityLiving entity, IWorld world, float x, float y, float z, MobSpawnerBaseLogic spawner) {
Result res = ForgeEventFactory.canEntitySpawn(entity, world, x, y, z, null);
return res == Result.DEFAULT ? 0 : res == Result.DENY ? -1 : 1;
}
}
@@ -1,396 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.common;
import java.util.ArrayList;
import java.util.Arrays;
import net.minecraft.util.CombatRules;
import net.minecraft.util.DamageSource;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import javax.annotation.Nonnull;
/**
* This interface is to be implemented by ItemArmor classes. It will allow to
* modify computation of damage and health loss. Computation will be called
* before the actual armor computation, which can then be cancelled.
*
* @see ItemArmor
*/
public interface ISpecialArmor
{
//TODO: Change 'int slot' to EnumArmorType
/**
* Retrieves the modifiers to be used when calculating armor damage.
*
* Armor will higher priority will have damage applied to them before
* lower priority ones. If there are multiple pieces of armor with the
* same priority, damage will be distributed between them based on there
* absorption ratio.
*
* @param player The entity wearing the armor.
* @param armor The ItemStack of the armor item itself.
* @param source The source of the damage, which can be used to alter armor
* properties based on the type or source of damage.
* @param damage The total damage being applied to the entity
* @param slot The armor slot the item is in.
* @return A ArmorProperties instance holding information about how the armor effects damage.
*/
ArmorProperties getProperties(EntityLivingBase player, @Nonnull ItemStack armor, DamageSource source, double damage, int slot);
/**
* Get the displayed effective armor.
*
* @param player The player wearing the armor.
* @param armor The ItemStack of the armor item itself.
* @param slot The armor slot the item is in.
* @return The number of armor points for display, 2 per shield.
*/
int getArmorDisplay(EntityPlayer player, @Nonnull ItemStack armor, int slot);
/**
* Applies damage to the ItemStack. The mod is responsible for reducing the
* item durability and stack size. If the stack is depleted it will be cleaned
* up automatically.
*
* @param entity The entity wearing the armor
* @param stack The ItemStack of the armor item itself.
* @param source The source of the damage, which can be used to alter armor
* properties based on the type or source of damage.
* @param damage The amount of damage being applied to the armor
* @param slot The armor slot the item is in.
*/
void damageArmor(EntityLivingBase entity, @Nonnull ItemStack stack, DamageSource source, int damage, int slot);
/**
* Simple check to see if the armor should interact with "Unblockable" damage
* sources. A fair number of vanilla damage sources have this tag, such as
* Anvils, Falling, Fire, and Magic.
*
* Returning true here means that the armor is able to meaningfully respond
* to this damage source. Otherwise, no interaction is allowed.
*/
default boolean handleUnblockableDamage(EntityLivingBase entity, @Nonnull ItemStack armor, DamageSource source, double damage, int slot)
{
return false;
}
public static class ArmorProperties implements Comparable<ArmorProperties>
{
public int Priority = 0;
public int AbsorbMax = Integer.MAX_VALUE;
public double AbsorbRatio = 0;
public double Armor = 0; //Additional armor, separate from the armor added by vanilla attributes.
public double Toughness = 0; //Additional toughness, separate from the armor added by vanilla attributes.
public int Slot = 0;
private static final boolean DEBUG = false; //Only enable this if you wish to be spammed with debugging information.
//Left it in because I figured it'd be useful for modders developing custom armor.
public ArmorProperties(int priority, double ratio, int max)
{
Priority = priority;
AbsorbRatio = ratio;
Armor = 0;
Toughness = 0;
AbsorbMax = max;
}
/**
* Gathers and applies armor reduction to damage being dealt to a entity.
*
* @param entity The Entity being damage
* @param inventory An array of armor items
* @param source The damage source type
* @param damage The total damage being done
* @return The left over damage that has not been absorbed by the armor
*/
public static float applyArmor(EntityLivingBase entity, NonNullList<ItemStack> inventory, DamageSource source, double damage)
{
if (DEBUG)
{
System.out.println("Start: " + damage);
}
double totalArmor = entity.getTotalArmorValue();
double totalToughness = entity.getAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS).getValue();
if (source.isUnblockable())
{
totalArmor = 0;
totalToughness = 0;
}
ArrayList<ArmorProperties> dmgVals = new ArrayList<ArmorProperties>();
for (int slot = 0; slot < inventory.size(); slot++)
{
ItemStack stack = inventory.get(slot);
if (stack.isEmpty())
{
continue;
}
ArmorProperties prop = null;
if (stack.getItem() instanceof ISpecialArmor)
{
if (!source.isUnblockable() || ((ISpecialArmor) stack.getItem()).handleUnblockableDamage(entity, stack, source, damage, slot)) {
ISpecialArmor armor = (ISpecialArmor)stack.getItem();
prop = armor.getProperties(entity, stack, source, damage, slot).copy();
totalArmor += prop.Armor;
totalToughness += prop.Toughness;
}
}
else if (stack.getItem() instanceof ItemArmor && !source.isUnblockable())
{
ItemArmor armor = (ItemArmor)stack.getItem();
prop = new ArmorProperties(0, 0, Integer.MAX_VALUE);
prop.Armor = armor.getDamageReduceAmount();
prop.Toughness = armor.getToughness();
}
if (prop != null)
{
prop.Slot = slot;
dmgVals.add(prop);
}
}
if (dmgVals.size() > 0)
{
ArmorProperties[] props = dmgVals.toArray(new ArmorProperties[dmgVals.size()]);
StandardizeList(props, damage);
int level = props[0].Priority;
double ratio = 0;
for (ArmorProperties prop : props)
{
if (level != prop.Priority)
{
damage -= (damage * ratio);
ratio = 0;
level = prop.Priority;
}
ratio += prop.AbsorbRatio;
double absorb = damage * prop.AbsorbRatio;
if (absorb > 0)
{
ItemStack stack = inventory.get(prop.Slot);
int itemDamage = (int)Math.max(1, absorb);
if (stack.getItem() instanceof ISpecialArmor)
{
((ISpecialArmor)stack.getItem()).damageArmor(entity, stack, source, itemDamage, prop.Slot);
}
else
{
if (DEBUG)
{
System.out.println("Item: " + stack.toString() + " Absorbed: " + absorb + " Damaged: " + itemDamage);
}
stack.damageItem(itemDamage, entity);
}
if (stack.isEmpty())
{
/*if (entity instanceof EntityPlayer)
{
stack.onItemDestroyedByUse((EntityPlayer)entity);
}*/
inventory.set(prop.Slot, ItemStack.EMPTY);
}
}
}
damage -= (damage * ratio);
}
if (damage > 0 && (totalArmor > 0 || totalToughness > 0))
{
double armorDamage = Math.max(1.0F, damage / 4.0F);
for (int i = 0; i < inventory.size(); i++)
{
if (inventory.get(i).getItem() instanceof ItemArmor)
{
inventory.get(i).damageItem((int)armorDamage, entity);
if (inventory.get(i).getCount() == 0)
{
inventory.set(i, ItemStack.EMPTY);
}
}
}
damage = CombatRules.getDamageAfterAbsorb((float)damage, (float)totalArmor, (float)totalToughness);
}
if (DEBUG)
{
System.out.println("Return: " + (int)(damage) + " " + damage);
}
return (float)(damage);
}
/**
* Sorts and standardizes the distribution of damage over armor.
*
* @param armor The armor information
* @param damage The total damage being received
*/
private static void StandardizeList(ArmorProperties[] armor, double damage)
{
Arrays.sort(armor);
int start = 0;
double total = 0;
int priority = armor[0].Priority;
int pStart = 0;
boolean pChange = false;
boolean pFinished = false;
if (DEBUG)
{
for (ArmorProperties prop : armor)
{
System.out.println(prop);
}
System.out.println("========================");
}
for (int x = 0; x < armor.length; x++)
{
total += armor[x].AbsorbRatio;
if (x == armor.length - 1 || armor[x].Priority != priority)
{
if (armor[x].Priority != priority)
{
total -= armor[x].AbsorbRatio;
x--;
pChange = true;
}
if (total > 1)
{
for (int y = start; y <= x; y++)
{
double newRatio = armor[y].AbsorbRatio / total;
if (newRatio * damage > armor[y].AbsorbMax)
{
armor[y].AbsorbRatio = (double)armor[y].AbsorbMax / damage;
total = 0;
for (int z = pStart; z <= y; z++)
{
total += armor[z].AbsorbRatio;
}
start = y + 1;
x = y;
break;
}
else
{
armor[y].AbsorbRatio = newRatio;
pFinished = true;
}
}
if (pChange && pFinished)
{
damage -= (damage * total);
total = 0;
start = x + 1;
priority = armor[start].Priority;
pStart = start;
pChange = false;
pFinished = false;
if (damage <= 0)
{
for (int y = x + 1; y < armor.length; y++)
{
armor[y].AbsorbRatio = 0;
}
break;
}
}
}
else
{
for (int y = start; y <= x; y++)
{
total -= armor[y].AbsorbRatio;
if (damage * armor[y].AbsorbRatio > armor[y].AbsorbMax)
{
armor[y].AbsorbRatio = (double)armor[y].AbsorbMax / damage;
}
total += armor[y].AbsorbRatio;
}
damage -= (damage * total);
total = 0;
if (x != armor.length - 1)
{
start = x + 1;
priority = armor[start].Priority;
pStart = start;
pChange = false;
if (damage <= 0)
{
for (int y = x + 1; y < armor.length; y++)
{
armor[y].AbsorbRatio = 0;
}
break;
}
}
}
}
}
if (DEBUG)
{
for (ArmorProperties prop : armor)
{
System.out.println(prop);
}
}
}
@Override
public int compareTo(ArmorProperties o)
{
if (o.Priority != Priority)
{
return o.Priority - Priority;
}
double left = ( AbsorbRatio == 0 ? 0 : AbsorbMax * 100.0D / AbsorbRatio);
double right = (o.AbsorbRatio == 0 ? 0 : o.AbsorbMax * 100.0D / o.AbsorbRatio);
return (int)(left - right);
}
@Override
public String toString()
{
return String.format("%d, %d, %f, %d", Priority, AbsorbMax, AbsorbRatio, (AbsorbRatio == 0 ? 0 : (int)(AbsorbMax * 100.0D / AbsorbRatio)));
}
public ArmorProperties copy()
{
ArmorProperties copy = new ArmorProperties(Priority, AbsorbRatio, AbsorbMax);
copy.Armor = Armor;
copy.Toughness = Toughness;
return copy;
}
}
}
@@ -31,8 +31,10 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.client.particle.ParticleManager;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EntitySpawnPlacementRegistry;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.boss.EntityDragon;
import net.minecraft.entity.boss.EntityWither;
import net.minecraft.entity.player.EntityPlayer;
@@ -258,9 +260,9 @@ public interface IForgeBlock
* @param player The player or camera entity, null in some cases.
* @return True to treat this as a bed
*/
default boolean isBed(IBlockState state, IWorldReader world, BlockPos pos, @Nullable EntityPlayer player)
default boolean isBed(IBlockState state, IBlockReader world, BlockPos pos, @Nullable EntityPlayer player)
{
return this.getBlock() instanceof BlockBed;
return this.getBlock() instanceof BlockBed; //TODO: Forge: Keep isBed function?
}
/**
@@ -273,9 +275,9 @@ public interface IForgeBlock
* @param type The Mob Category Type
* @return True to allow a mob of the specified category to spawn, false to prevent it.
*/
default boolean canCreatureSpawn(IBlockState state, IWorldReader world, BlockPos pos, EntitySpawnPlacementRegistry.SpawnPlacementType type)
default boolean canCreatureSpawn(IBlockState state, IWorldReaderBase world, BlockPos pos, EntitySpawnPlacementRegistry.SpawnPlacementType type, @Nullable EntityType<? extends EntityLiving> entityType)
{
return state.isTopSolid();
return state.isTopSolid() || entityType != null && EntitySpawnPlacementRegistry.func_209345_a(entityType, state);
}
/**
* Returns the position that the player is moved to upon
@@ -288,7 +290,7 @@ public interface IForgeBlock
* @return The spawn position
*/
@Nullable
default BlockPos getBedSpawnPosition(IBlockState state, IWorldReader world, BlockPos pos, @Nullable EntityPlayer player)
default BlockPos getBedSpawnPosition(IBlockState state, IBlockReader world, BlockPos pos, @Nullable EntityPlayer player)
{
if (world instanceof World)
{
@@ -27,16 +27,16 @@ import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.particle.ParticleManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EntitySpawnPlacementRegistry.SpawnPlacementType;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.fluid.IFluidState;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.pathfinding.PathNodeType;
import net.minecraft.tags.BlockTags;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
@@ -219,7 +219,7 @@ public interface IForgeBlockState
* @param player The player or camera entity, null in some cases.
* @return True to treat this as a bed
*/
default boolean isBed(IWorldReader world, BlockPos pos, @Nullable EntityPlayer player)
default boolean isBed(IBlockReader world, BlockPos pos, @Nullable EntityPlayer player)
{
return getBlockState().getBlock().isBed(getBlockState(), world, pos, player);
}
@@ -233,9 +233,9 @@ public interface IForgeBlockState
* @param type The Mob Category Type
* @return True to allow a mob of the specified category to spawn, false to prevent it.
*/
default boolean canCreatureSpawn(IWorldReader world, BlockPos pos, SpawnPlacementType type)
default boolean canCreatureSpawn(IWorldReaderBase world, BlockPos pos, SpawnPlacementType type, EntityType<? extends EntityLiving> entityType)
{
return getBlockState().getBlock().canCreatureSpawn(getBlockState(), world, pos, type);
return getBlockState().getBlock().canCreatureSpawn(getBlockState(), world, pos, type, entityType);
}
/**
* Returns the position that the player is moved to upon
@@ -247,7 +247,7 @@ public interface IForgeBlockState
* @return The spawn position
*/
@Nullable
default BlockPos getBedSpawnPosition(IWorldReader world, BlockPos pos, @Nullable EntityPlayer player)
default BlockPos getBedSpawnPosition(IBlockReader world, BlockPos pos, @Nullable EntityPlayer player)
{
return getBlockState().getBlock().getBedSpawnPosition(getBlockState(), world, pos, player);
}
@@ -26,7 +26,9 @@ import javax.annotation.Nullable;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLeashKnot;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.item.EntityArmorStand;
import net.minecraft.entity.item.EntityBoat;
import net.minecraft.entity.item.EntityEnderCrystal;
@@ -167,4 +169,16 @@ public interface IForgeEntity extends ICapabilitySerializable<NBTTagCompound>
* @return {@code true} if this entity can trample, {@code false} otherwise
*/
boolean canTrample(IBlockState state, BlockPos pos, float fallDistance);
/**
* Returns true if the entity is of the @link{EnumCreatureType} provided
* @param type The EnumCreatureType type this entity is evaluating
* @param forSpawnCount If this is being invoked to check spawn count caps.
* @return If the creature is of the type provided
*/
default boolean isCreatureType(EnumCreatureType type, boolean forSpawnCount)
{
if (forSpawnCount && (this instanceof EntityLiving) && ((EntityLiving)this).isNoDespawnRequired()) return false;
return type.getBaseClass().isAssignableFrom(this.getClass());
}
}
@@ -318,7 +318,7 @@ public interface IForgeItem
/**
* Called to tick armor in the armor slot. Override to do something
*/
default void onArmorTick(World world, EntityPlayer player, ItemStack itemStack)
default void onArmorTick(ItemStack stack, World world, EntityPlayer player)
{
}
@@ -287,6 +287,13 @@ public interface IForgeItemStack extends ICapabilitySerializable<NBTTagCompound>
return getStack().getItem().getHorseArmorType(getStack());
}
/**
* Called to tick armor in the armor slot. Override to do something
*/
default void onArmorTick(World world, EntityPlayer player)
{
getStack().getItem().onArmorTick(getStack(), world, player);
}
/**
* Called every tick from {@link EntityHorse#onUpdate()} on the item in the
@@ -334,4 +341,18 @@ public interface IForgeItemStack extends ICapabilitySerializable<NBTTagCompound>
{
return getStack().getItem().isBookEnchantable(getStack(), book);
}
/**
* Called when a player drops the item into the world, returning false from this
* will prevent the item from being removed from the players inventory and
* spawning in the world
*
* @param player The player that dropped the item
* @param item The item stack, before the item is removed.
*/
default boolean onDroppedByPlayer(EntityPlayer player)
{
return getStack().getItem().onDroppedByPlayer(getStack(), player);
}
}
@@ -0,0 +1,45 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.common.util;
import java.util.Objects;
/**
* A predicate that takes three arguments and returns a boolean.
*/
@FunctionalInterface
public interface TriPredicate<T, U, V>
{
boolean test(T t, U u, V v);
default TriPredicate<T, U, V> and(TriPredicate<? super T, ? super U, ? super V> other) {
Objects.requireNonNull(other);
return (T t, U u, V v) -> test(t, u, v) && other.test(t, u, v);
}
default TriPredicate<T, U, V> negate() {
return (T t, U u, V v) -> !test(t, u, v);
}
default TriPredicate<T, U, V> or(TriPredicate<? super T, ? super U, ? super V> other) {
Objects.requireNonNull(other);
return (T t, U u, V v) -> test(t, u, v) || other.test(t, u, v);
}
}
@@ -20,6 +20,7 @@
package net.minecraftforge.event;
import java.io.File;
import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
import java.util.Random;
@@ -180,7 +181,7 @@ public class ForgeEventFactory
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, stack, hand));
}
public static Result canEntitySpawn(EntityLiving entity, World world, float x, float y, float z, MobSpawnerBaseLogic spawner)
public static Result canEntitySpawn(EntityLiving entity, IWorld world, float x, float y, float z, MobSpawnerBaseLogic spawner)
{
if (entity == null)
return Result.DEFAULT;
@@ -426,15 +427,11 @@ public class ForgeEventFactory
return event.getResult() == Result.ALLOW ? 1 : 0;
}
public static void onPlayerDrops(EntityPlayer player, DamageSource cause, List<EntityItem> capturedDrops, boolean recentlyHit)
public static void onPlayerDrops(EntityPlayer player, DamageSource cause, Collection<EntityItem> drops, boolean recentlyHit)
{
PlayerDropsEvent event = new PlayerDropsEvent(player, cause, capturedDrops, recentlyHit);
if (!MinecraftForge.EVENT_BUS.post(event))
{
for (EntityItem item : capturedDrops)
{
player.dropItemAndGetStack(item);
}
PlayerDropsEvent event = new PlayerDropsEvent(player, cause, drops, recentlyHit);
if (!MinecraftForge.EVENT_BUS.post(event)) {
drops.forEach(e -> player.dropItemAndGetStack(e));
}
}
@@ -25,6 +25,7 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.eventbus.api.Event;
import net.minecraft.entity.EntityLiving;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraftforge.eventbus.api.Event.HasResult;
@@ -43,12 +44,12 @@ import net.minecraftforge.eventbus.api.Event.HasResult;
**/
public class LivingSpawnEvent extends LivingEvent
{
private final World world;
private final IWorld world;
private final float x;
private final float y;
private final float z;
public LivingSpawnEvent(EntityLiving entity, World world, float x, float y, float z)
public LivingSpawnEvent(EntityLiving entity, IWorld world, float x, float y, float z)
{
super(entity);
this.world = world;
@@ -57,7 +58,7 @@ public class LivingSpawnEvent extends LivingEvent
this.z = z;
}
public World getWorld() { return world; }
public IWorld getWorld() { return world; }
public float getX() { return x; }
public float getY() { return y; }
public float getZ() { return z; }
@@ -76,7 +77,6 @@ public class LivingSpawnEvent extends LivingEvent
@Nullable
private final MobSpawnerBaseLogic spawner;
/**
* CheckSpawn is fired when an Entity is about to be spawned.
* @param entity the spawning entity
@@ -87,7 +87,7 @@ public class LivingSpawnEvent extends LivingEvent
* @param spawner position of the MobSpawner
* null if it this spawn is coming from a WorldSpawner
*/
public CheckSpawn(EntityLiving entity, World world, float x, float y, float z, @Nullable MobSpawnerBaseLogic spawner)
public CheckSpawn(EntityLiving entity, IWorld world, float x, float y, float z, @Nullable MobSpawnerBaseLogic spawner)
{
super(entity, world, x, y, z);
this.spawner = spawner;
@@ -95,7 +95,7 @@ public class LivingSpawnEvent extends LivingEvent
public boolean isSpawner()
{
return spawner != null; // TODO: replace with spawner null check in 1.13
return spawner != null;
}
@Nullable
@@ -19,7 +19,7 @@
package net.minecraftforge.event.entity.player;
import java.util.List;
import java.util.Collection;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.eventbus.api.Cancelable;
@@ -34,7 +34,7 @@ import net.minecraftforge.event.entity.living.LivingDropsEvent;
* player dies. Canceling the event will prevent ALL drops from entering the
* world.
*/
@net.minecraftforge.eventbus.api.Cancelable
@Cancelable
public class PlayerDropsEvent extends LivingDropsEvent
{
private final EntityPlayer entityPlayer;
@@ -46,7 +46,7 @@ public class PlayerDropsEvent extends LivingDropsEvent
* @param source The source of the damage which is killing the player.
* @param drops List of all drops entering the world.
*/
public PlayerDropsEvent(EntityPlayer entity, DamageSource source, List<EntityItem> drops, boolean recentlyHit)
public PlayerDropsEvent(EntityPlayer entity, DamageSource source, Collection<EntityItem> drops, boolean recentlyHit)
{
super(entity, source, drops, ForgeHooks.getLootingLevel(entity, source.getTrueSource(), source), recentlyHit);