Item and NBT patches, IShearable blocks are responsible for setting themselves to air, to allow for setting other states.

This commit is contained in:
LexManos committed 2018-12-03 18:04:37 -08:00
1 parent bf9158172f
commit a3c8e04ee6
92 files changed
+1008 -2205

No files matched your search

@@ -23,6 +23,7 @@ import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.IWorldReader;
import javax.annotation.Nonnull;
@@ -71,5 +72,5 @@ public interface IShearable
* @return A List containing all items from this shearing. May be empty.
*/
@Nonnull
List<ItemStack> onSheared(@Nonnull ItemStack item, IWorldReader world, BlockPos pos, int fortune);
List<ItemStack> onSheared(@Nonnull ItemStack item, IWorld world, BlockPos pos, int fortune);
}
@@ -26,12 +26,13 @@ import com.google.common.collect.Maps;
public final class ToolType
{
private static final Pattern VALID_NAME = Pattern.compile("[^a-z_]"); //Only a-z and _ are allowed, meaning names must be lower case. And use _ to separate words.
private static final Map<String, ToolType> values = Maps.newHashMap();
public static final ToolType AXE = get("axe");
public static final ToolType PICKAXE = get("pickaxe");
public static final ToolType SHOVEL = get("shovel");
private static final Map<String, ToolType> values = Maps.newHashMap();
private static final Pattern VALID_NAME = Pattern.compile("[^a-z_]"); //Only a-z and _ are allowed, meaning names must be lower case. And use _ to separate words.
public static ToolType get(String name)
{
@@ -160,7 +160,7 @@ public interface IForgeBlock
* @param pos Block position in world
* @return True if the block should deal damage
*/
default boolean isBurning(IWorldReader world, BlockPos pos)
default boolean isBurning(IBlockState state, IBlockReader world, BlockPos pos)
{
return false;
}
@@ -361,7 +361,7 @@ public interface IForgeBlock
* @param pos Block position in world
* @return True if the block considered air
*/
default boolean isAir(IBlockState state, IWorldReader world, BlockPos pos)
default boolean isAir(IBlockState state, IBlockReader world, BlockPos pos)
{
return state.getMaterial() == Material.AIR;
}
@@ -903,9 +903,9 @@ public interface IForgeBlock
* @return the PathNodeType
*/
@Nullable
default PathNodeType getAiPathNodeType(IBlockState state, IWorldReader world, BlockPos pos)
default PathNodeType getAiPathNodeType(IBlockState state, IBlockReader world, BlockPos pos)
{
return isBurning(world, pos) ? PathNodeType.DAMAGE_FIRE : null;
return state.isBurning(world, pos) ? PathNodeType.DAMAGE_FIRE : null;
}
/**
@@ -310,7 +310,7 @@ public interface IForgeBlockState
* @param pos Block position in world
* @return True if the block considered air
*/
default boolean isAir(IWorldReader world, BlockPos pos)
default boolean isAir(IBlockReader world, BlockPos pos)
{
return getBlockState().getBlock().isAir(getBlockState(), world, pos);
}
@@ -898,4 +898,28 @@ public interface IForgeBlockState
{
return getBlockState().getBlock().getValidRotations(getBlockState(), world, pos);
}
/**
* Determines if this block should set fire and deal fire damage
* to entities coming into contact with it.
*
* @param world The current world
* @param pos Block position in world
* @return True if the block should deal damage
*/
default boolean isBurning(IBlockReader world, BlockPos pos)
{
return getBlockState().getBlock().isBurning(getBlockState(), world, pos);
}
/**
* Get the {@code PathNodeType} for this block. Return {@code null} for vanilla behavior.
*
* @return the PathNodeType
*/
@Nullable
default PathNodeType getAiPathNodeType(IBlockReader world, BlockPos pos)
{
return getBlockState().getBlock().getAiPathNodeType(getBlockState(), world, pos);
}
}
@@ -162,7 +162,6 @@ public interface IForgeEntity extends ICapabilitySerializable<NBTTagCompound>
/**
* Checks if this {@link Entity} can trample a {@link Block}.
*
* @param block The block being tested
* @param pos The block pos
* @param fallDistance The fall distance
* @return {@code true} if this entity can trample, {@code false} otherwise
@@ -25,6 +25,7 @@ import javax.annotation.Nullable;
import net.minecraft.block.state.BlockWorldState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -149,4 +150,32 @@ public interface IForgeItemStack extends ICapabilitySerializable<NBTTagCompound>
{
return getStack().getItem().shouldCauseBlockBreakReset(getStack(), newStack);
}
/**
* Checks whether an item can be enchanted with a certain enchantment. This
* applies specifically to enchanting an item in the enchanting table and is
* called when retrieving the list of possible enchantments for an item.
* Enchantments may additionally (or exclusively) be doing their own checks in
* {@link net.minecraft.enchantment.Enchantment#canApplyAtEnchantingTable(ItemStack)};
* check the individual implementation for reference. By default this will check
* if the enchantment type is valid for this item type.
*
* @param stack the item stack to be enchanted
* @param enchantment the enchantment to be applied
* @return true if the enchantment can be applied to this item
*/
default boolean canApplyAtEnchantingTable(Enchantment enchantment)
{
return getStack().getItem().canApplyAtEnchantingTable(getStack(), enchantment);
}
/**
* ItemStack sensitive version of getItemEnchantability
*
* @return the item echantability value
*/
default int getItemEnchantability()
{
return getStack().getItem().getItemEnchantability(getStack());
}
}
@@ -44,6 +44,7 @@ import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.tileentity.MobSpawnerBaseLogic;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
@@ -347,22 +348,22 @@ public class ForgeEventFactory
return MinecraftForge.EVENT_BUS.post(event) ? "" : event.getMessage();
}
public static int onHoeUse(ItemStack stack, EntityPlayer player, World worldIn, BlockPos pos)
public static int onHoeUse(ItemUseContext context)
{
UseHoeEvent event = new UseHoeEvent(player, stack, worldIn, pos);
UseHoeEvent event = new UseHoeEvent(context);
if (MinecraftForge.EVENT_BUS.post(event)) return -1;
if (event.getResult() == Result.ALLOW)
{
stack.damageItem(1, player);
context.getItem().damageItem(1, context.getPlayer());
return 1;
}
return 0;
}
public static int onApplyBonemeal(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull ItemStack stack, @Nullable EnumHand hand)
public static int onApplyBonemeal(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull ItemStack stack)
{
BonemealEvent event = new BonemealEvent(player, world, pos, state, hand, stack);
BonemealEvent event = new BonemealEvent(player, world, pos, state, stack);
if (MinecraftForge.EVENT_BUS.post(event)) return -1;
if (event.getResult() == Result.ALLOW)
{
@@ -20,16 +20,13 @@
package net.minecraftforge.event.entity.player;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* This event is called when a player attempts to use Bonemeal on a block.
@@ -48,17 +45,14 @@ public class BonemealEvent extends PlayerEvent
private final World world;
private final BlockPos pos;
private final IBlockState block;
private final EnumHand hand;
private final ItemStack stack;
public BonemealEvent(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState block, @Nullable EnumHand hand,
@Nonnull ItemStack stack)
public BonemealEvent(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState block, @Nonnull ItemStack stack)
{
super(player);
this.world = world;
this.pos = pos;
this.block = block;
this.hand = hand;
this.stack = stack;
}
@@ -77,12 +71,6 @@ public class BonemealEvent extends PlayerEvent
return block;
}
@Nullable
public EnumHand getHand()
{
return hand;
}
@Nonnull
public ItemStack getStack()
{
@@ -19,10 +19,7 @@
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.item.ItemUseContext;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event.HasResult;
@@ -41,32 +38,17 @@ import javax.annotation.Nonnull;
@HasResult
public class UseHoeEvent extends PlayerEvent
{
private final ItemUseContext context;;
private final ItemStack current;
private final World world;
private final BlockPos pos;
public UseHoeEvent(EntityPlayer player, @Nonnull ItemStack current, World world, BlockPos pos)
public UseHoeEvent(ItemUseContext context)
{
super(player);
this.current = current;
this.world = world;
this.pos = pos;
super(context.getPlayer());
this.context = context;
}
@Nonnull
public ItemStack getCurrent()
public ItemUseContext getContext()
{
return current;
}
public World getWorld()
{
return world;
}
public BlockPos getPos()
{
return pos;
return context;
}
}
@@ -19,13 +19,9 @@
package net.minecraftforge.resource;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
/**
* Represents a generic type of reloadable resource. Used for resource reload filtering.
*/
@OnlyIn(Dist.CLIENT)
public interface IResourceType
{
}