mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-22 05:02:18 +00:00
Update to 1.17
Update to Official classnames Patchwork Make the game compile and run Merge in the new HUD overlay API Merge in the new render properties API PEEL Use Gradle 7.2 snapshot to fix eclipse integration bug in 7.1, Would use 7.0 but FG needs 7.1 for some reason. New FML installer Update to 1.17.1 Co-authored-by: LexManos <[email protected]> Co-authored-by: SizableShrimp <[email protected]> Co-authored-by: cpw <[email protected]> Co-authored-by: Curle <[email protected]> Co-authored-by: Unnoen <[email protected]> Co-authored-by: covers1624 <[email protected]> Co-authored-by: DaemonUmbra <[email protected]> Co-authored-by: gigaherz <[email protected]> Signed-off-by: SizableShrimp <[email protected]>
This commit is contained in:
1 parent
064ae6961b
commit
be5446b91c
1990 files changed
+35661
-37544
No files matched your search
@@ -19,17 +19,10 @@
|
||||
|
||||
package net.minecraftforge.items;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class CapabilityItemHandler
|
||||
{
|
||||
@CapabilityInject(IItemHandler.class)
|
||||
@@ -37,46 +30,7 @@ public class CapabilityItemHandler
|
||||
|
||||
public static void register()
|
||||
{
|
||||
CapabilityManager.INSTANCE.register(IItemHandler.class, new Capability.IStorage<IItemHandler>()
|
||||
{
|
||||
@Override
|
||||
public INBT writeNBT(Capability<IItemHandler> capability, IItemHandler instance, Direction side)
|
||||
{
|
||||
ListNBT nbtTagList = new ListNBT();
|
||||
int size = instance.getSlots();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
ItemStack stack = instance.getStackInSlot(i);
|
||||
if (!stack.isEmpty())
|
||||
{
|
||||
CompoundNBT itemTag = new CompoundNBT();
|
||||
itemTag.putInt("Slot", i);
|
||||
stack.save(itemTag);
|
||||
nbtTagList.add(itemTag);
|
||||
}
|
||||
}
|
||||
return nbtTagList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNBT(Capability<IItemHandler> capability, IItemHandler instance, Direction side, INBT base)
|
||||
{
|
||||
if (!(instance instanceof IItemHandlerModifiable))
|
||||
throw new RuntimeException("IItemHandler instance does not implement IItemHandlerModifiable");
|
||||
IItemHandlerModifiable itemHandlerModifiable = (IItemHandlerModifiable) instance;
|
||||
ListNBT tagList = (ListNBT) base;
|
||||
for (int i = 0; i < tagList.size(); i++)
|
||||
{
|
||||
CompoundNBT itemTags = tagList.getCompound(i);
|
||||
int j = itemTags.getInt("Slot");
|
||||
|
||||
if (j >= 0 && j < instance.getSlots())
|
||||
{
|
||||
itemHandlerModifiable.setStackInSlot(j, ItemStack.of(itemTags));
|
||||
}
|
||||
}
|
||||
}
|
||||
}, ItemStackHandler::new);
|
||||
CapabilityManager.INSTANCE.register(IItemHandler.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,15 +19,10 @@
|
||||
|
||||
package net.minecraftforge.items;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public interface IItemHandler
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
package net.minecraftforge.items;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
||||
@@ -19,13 +19,13 @@
|
||||
|
||||
package net.minecraftforge.items;
|
||||
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -149,7 +149,7 @@ public class ItemHandlerHelper
|
||||
}
|
||||
|
||||
/** giveItemToPlayer without preferred slot */
|
||||
public static void giveItemToPlayer(PlayerEntity player, @Nonnull ItemStack stack) {
|
||||
public static void giveItemToPlayer(Player player, @Nonnull ItemStack stack) {
|
||||
giveItemToPlayer(player, stack, -1);
|
||||
}
|
||||
|
||||
@@ -160,12 +160,12 @@ public class ItemHandlerHelper
|
||||
* @param player The player to give the item to
|
||||
* @param stack The itemstack to insert
|
||||
*/
|
||||
public static void giveItemToPlayer(PlayerEntity player, @Nonnull ItemStack stack, int preferredSlot)
|
||||
public static void giveItemToPlayer(Player player, @Nonnull ItemStack stack, int preferredSlot)
|
||||
{
|
||||
if (stack.isEmpty()) return;
|
||||
|
||||
IItemHandler inventory = new PlayerMainInvWrapper(player.inventory);
|
||||
World world = player.level;
|
||||
IItemHandler inventory = new PlayerMainInvWrapper(player.getInventory());
|
||||
Level world = player.level;
|
||||
|
||||
// try adding it into the inventory
|
||||
ItemStack remainder = stack;
|
||||
@@ -184,7 +184,7 @@ public class ItemHandlerHelper
|
||||
if (remainder.isEmpty() || remainder.getCount() != stack.getCount())
|
||||
{
|
||||
world.playSound(null, player.getX(), player.getY() + 0.5, player.getZ(),
|
||||
SoundEvents.ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((world.random.nextFloat() - world.random.nextFloat()) * 0.7F + 1.0F) * 2.0F);
|
||||
SoundEvents.ITEM_PICKUP, SoundSource.PLAYERS, 0.2F, ((world.random.nextFloat() - world.random.nextFloat()) * 0.7F + 1.0F) * 2.0F);
|
||||
}
|
||||
|
||||
// drop remaining itemstack into the world
|
||||
@@ -227,7 +227,7 @@ public class ItemHandlerHelper
|
||||
}
|
||||
|
||||
proportion = proportion / (float)inv.getSlots();
|
||||
return MathHelper.floor(proportion * 14.0F) + (itemsFound > 0 ? 1 : 0);
|
||||
return Mth.floor(proportion * 14.0F) + (itemsFound > 0 ? 1 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,16 +19,16 @@
|
||||
|
||||
package net.minecraftforge.items;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ItemStackHandler implements IItemHandler, IItemHandlerModifiable, INBTSerializable<CompoundNBT>
|
||||
public class ItemStackHandler implements IItemHandler, IItemHandlerModifiable, INBTSerializable<CompoundTag>
|
||||
{
|
||||
protected NonNullList<ItemStack> stacks;
|
||||
|
||||
@@ -178,33 +178,33 @@ public class ItemStackHandler implements IItemHandler, IItemHandlerModifiable, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT serializeNBT()
|
||||
public CompoundTag serializeNBT()
|
||||
{
|
||||
ListNBT nbtTagList = new ListNBT();
|
||||
ListTag nbtTagList = new ListTag();
|
||||
for (int i = 0; i < stacks.size(); i++)
|
||||
{
|
||||
if (!stacks.get(i).isEmpty())
|
||||
{
|
||||
CompoundNBT itemTag = new CompoundNBT();
|
||||
CompoundTag itemTag = new CompoundTag();
|
||||
itemTag.putInt("Slot", i);
|
||||
stacks.get(i).save(itemTag);
|
||||
nbtTagList.add(itemTag);
|
||||
}
|
||||
}
|
||||
CompoundNBT nbt = new CompoundNBT();
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
nbt.put("Items", nbtTagList);
|
||||
nbt.putInt("Size", stacks.size());
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundNBT nbt)
|
||||
public void deserializeNBT(CompoundTag nbt)
|
||||
{
|
||||
setSize(nbt.contains("Size", Constants.NBT.TAG_INT) ? nbt.getInt("Size") : stacks.size());
|
||||
ListNBT tagList = nbt.getList("Items", Constants.NBT.TAG_COMPOUND);
|
||||
ListTag tagList = nbt.getList("Items", Constants.NBT.TAG_COMPOUND);
|
||||
for (int i = 0; i < tagList.size(); i++)
|
||||
{
|
||||
CompoundNBT itemTags = tagList.getCompound(i);
|
||||
CompoundTag itemTags = tagList.getCompound(i);
|
||||
int slot = itemTags.getInt("Slot");
|
||||
|
||||
if (slot >= 0 && slot < stacks.size())
|
||||
|
||||
@@ -19,16 +19,16 @@
|
||||
|
||||
package net.minecraftforge.items;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.SimpleContainer;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class SlotItemHandler extends Slot
|
||||
{
|
||||
private static IInventory emptyInventory = new Inventory(0);
|
||||
private static Container emptyInventory = new SimpleContainer(0);
|
||||
private final IItemHandler itemHandler;
|
||||
private final int index;
|
||||
|
||||
@@ -105,7 +105,7 @@ public class SlotItemHandler extends Slot
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayPickup(PlayerEntity playerIn)
|
||||
public boolean mayPickup(Player playerIn)
|
||||
{
|
||||
return !this.getItemHandler().extractItem(index, 1, true).isEmpty();
|
||||
}
|
||||
|
||||
@@ -19,17 +19,17 @@
|
||||
|
||||
package net.minecraftforge.items;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.HopperTileEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.entity.HopperBlockEntity;
|
||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class VanillaHopperItemHandler extends InvWrapper
|
||||
{
|
||||
private final HopperTileEntity hopper;
|
||||
private final HopperBlockEntity hopper;
|
||||
|
||||
public VanillaHopperItemHandler(HopperTileEntity hopper)
|
||||
public VanillaHopperItemHandler(HopperBlockEntity hopper)
|
||||
{
|
||||
super(hopper);
|
||||
this.hopper = hopper;
|
||||
|
||||
@@ -19,19 +19,17 @@
|
||||
|
||||
package net.minecraftforge.items;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.DropperBlock;
|
||||
import net.minecraft.block.HopperBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.IHopper;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.DispenserTileEntity;
|
||||
import net.minecraft.tileentity.HopperTileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraft.world.level.block.DropperBlock;
|
||||
import net.minecraft.world.level.block.HopperBlock;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.entity.Hopper;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.DispenserBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.HopperBlockEntity;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
@@ -47,9 +45,9 @@ public class VanillaInventoryCodeHooks
|
||||
* @return Null if we did nothing {no IItemHandler}, True if we moved an item, False if we moved no items
|
||||
*/
|
||||
@Nullable
|
||||
public static Boolean extractHook(IHopper dest)
|
||||
public static Boolean extractHook(Level level, Hopper dest)
|
||||
{
|
||||
return getItemHandler(dest, Direction.UP)
|
||||
return getItemHandler(level, dest, Direction.UP)
|
||||
.map(itemHandlerResult -> {
|
||||
IItemHandler handler = itemHandlerResult.getKey();
|
||||
|
||||
@@ -86,7 +84,7 @@ public class VanillaInventoryCodeHooks
|
||||
/**
|
||||
* Copied from BlockDropper#dispense and added capability support
|
||||
*/
|
||||
public static boolean dropperInsertHook(World world, BlockPos pos, DispenserTileEntity dropper, int slot, @Nonnull ItemStack stack)
|
||||
public static boolean dropperInsertHook(Level world, BlockPos pos, DispenserBlockEntity dropper, int slot, @Nonnull ItemStack stack)
|
||||
{
|
||||
Direction enumfacing = world.getBlockState(pos).getValue(DropperBlock.FACING);
|
||||
BlockPos blockpos = pos.relative(enumfacing);
|
||||
@@ -116,10 +114,10 @@ public class VanillaInventoryCodeHooks
|
||||
/**
|
||||
* Copied from TileEntityHopper#transferItemsOut and added capability support
|
||||
*/
|
||||
public static boolean insertHook(HopperTileEntity hopper)
|
||||
public static boolean insertHook(HopperBlockEntity hopper)
|
||||
{
|
||||
Direction hopperFacing = hopper.getBlockState().getValue(HopperBlock.FACING);
|
||||
return getItemHandler(hopper, hopperFacing)
|
||||
return getItemHandler(hopper.getLevel(), hopper, hopperFacing)
|
||||
.map(destinationResult -> {
|
||||
IItemHandler itemHandler = destinationResult.getKey();
|
||||
Object destination = destinationResult.getValue();
|
||||
@@ -152,7 +150,7 @@ public class VanillaInventoryCodeHooks
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
private static ItemStack putStackInInventoryAllSlots(TileEntity source, Object destination, IItemHandler destInventory, ItemStack stack)
|
||||
private static ItemStack putStackInInventoryAllSlots(BlockEntity source, Object destination, IItemHandler destInventory, ItemStack stack)
|
||||
{
|
||||
for (int slot = 0; slot < destInventory.getSlots() && !stack.isEmpty(); slot++)
|
||||
{
|
||||
@@ -164,7 +162,7 @@ public class VanillaInventoryCodeHooks
|
||||
/**
|
||||
* Copied from TileEntityHopper#insertStack and added capability support
|
||||
*/
|
||||
private static ItemStack insertStack(TileEntity source, Object destination, IItemHandler destInventory, ItemStack stack, int slot)
|
||||
private static ItemStack insertStack(BlockEntity source, Object destination, IItemHandler destInventory, ItemStack stack, int slot)
|
||||
{
|
||||
ItemStack itemstack = destInventory.getStackInSlot(slot);
|
||||
|
||||
@@ -188,16 +186,16 @@ public class VanillaInventoryCodeHooks
|
||||
|
||||
if (insertedItem)
|
||||
{
|
||||
if (inventoryWasEmpty && destination instanceof HopperTileEntity)
|
||||
if (inventoryWasEmpty && destination instanceof HopperBlockEntity)
|
||||
{
|
||||
HopperTileEntity destinationHopper = (HopperTileEntity)destination;
|
||||
HopperBlockEntity destinationHopper = (HopperBlockEntity)destination;
|
||||
|
||||
if (!destinationHopper.isOnCustomCooldown())
|
||||
{
|
||||
int k = 0;
|
||||
if (source instanceof HopperTileEntity)
|
||||
if (source instanceof HopperBlockEntity)
|
||||
{
|
||||
if (destinationHopper.getLastUpdateTime() >= ((HopperTileEntity) source).getLastUpdateTime())
|
||||
if (destinationHopper.getLastUpdateTime() >= ((HopperBlockEntity) source).getLastUpdateTime())
|
||||
{
|
||||
k = 1;
|
||||
}
|
||||
@@ -211,12 +209,12 @@ public class VanillaInventoryCodeHooks
|
||||
return stack;
|
||||
}
|
||||
|
||||
private static Optional<Pair<IItemHandler, Object>> getItemHandler(IHopper hopper, Direction hopperFacing)
|
||||
private static Optional<Pair<IItemHandler, Object>> getItemHandler(Level level, Hopper hopper, Direction hopperFacing)
|
||||
{
|
||||
double x = hopper.getLevelX() + (double) hopperFacing.getStepX();
|
||||
double y = hopper.getLevelY() + (double) hopperFacing.getStepY();
|
||||
double z = hopper.getLevelZ() + (double) hopperFacing.getStepZ();
|
||||
return getItemHandler(hopper.getLevel(), x, y, z, hopperFacing.getOpposite());
|
||||
return getItemHandler(level, x, y, z, hopperFacing.getOpposite());
|
||||
}
|
||||
|
||||
private static boolean isFull(IItemHandler itemHandler)
|
||||
@@ -245,21 +243,21 @@ public class VanillaInventoryCodeHooks
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Optional<Pair<IItemHandler, Object>> getItemHandler(World worldIn, double x, double y, double z, final Direction side)
|
||||
public static Optional<Pair<IItemHandler, Object>> getItemHandler(Level worldIn, double x, double y, double z, final Direction side)
|
||||
{
|
||||
int i = MathHelper.floor(x);
|
||||
int j = MathHelper.floor(y);
|
||||
int k = MathHelper.floor(z);
|
||||
int i = Mth.floor(x);
|
||||
int j = Mth.floor(y);
|
||||
int k = Mth.floor(z);
|
||||
BlockPos blockpos = new BlockPos(i, j, k);
|
||||
net.minecraft.block.BlockState state = worldIn.getBlockState(blockpos);
|
||||
net.minecraft.world.level.block.state.BlockState state = worldIn.getBlockState(blockpos);
|
||||
|
||||
if (state.hasTileEntity())
|
||||
if (state.hasBlockEntity())
|
||||
{
|
||||
TileEntity tileentity = worldIn.getBlockEntity(blockpos);
|
||||
if (tileentity != null)
|
||||
BlockEntity blockEntity = worldIn.getBlockEntity(blockpos);
|
||||
if (blockEntity != null)
|
||||
{
|
||||
return tileentity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)
|
||||
.map(capability -> ImmutablePair.<IItemHandler, Object>of(capability, tileentity));
|
||||
return blockEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)
|
||||
.map(capability -> ImmutablePair.<IItemHandler, Object>of(capability, blockEntity));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
package net.minecraftforge.items.wrapper;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
package net.minecraftforge.items.wrapper;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
|
||||
@@ -19,9 +19,8 @@
|
||||
|
||||
package net.minecraftforge.items.wrapper;
|
||||
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.inventory.EquipmentSlotType;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
|
||||
/**
|
||||
* Exposes the armor inventory of an {@link EntityLivingBase} as an {@link IItemHandler} using {@link EntityLivingBase#getItemStackFromSlot} and
|
||||
@@ -31,6 +30,6 @@ public class EntityArmorInvWrapper extends EntityEquipmentInvWrapper
|
||||
{
|
||||
public EntityArmorInvWrapper(final LivingEntity entity)
|
||||
{
|
||||
super(entity, EquipmentSlotType.Group.ARMOR);
|
||||
super(entity, EquipmentSlot.Type.ARMOR);
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,10 @@
|
||||
package net.minecraftforge.items.wrapper;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.inventory.EquipmentSlotType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import java.util.ArrayList;
|
||||
@@ -32,10 +31,6 @@ import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Exposes the armor or hands inventory of an {@link EntityLivingBase} as an {@link IItemHandler} using {@link EntityLivingBase#getItemStackFromSlot} and
|
||||
* {@link EntityLivingBase#setItemStackToSlot}.
|
||||
@@ -50,19 +45,19 @@ public abstract class EntityEquipmentInvWrapper implements IItemHandlerModifiabl
|
||||
/**
|
||||
* The slots exposed by this wrapper, with {@link EntityEquipmentSlot#index} as the index.
|
||||
*/
|
||||
protected final List<EquipmentSlotType> slots;
|
||||
protected final List<EquipmentSlot> slots;
|
||||
|
||||
/**
|
||||
* @param entity The entity.
|
||||
* @param slotType The slot type to expose.
|
||||
*/
|
||||
public EntityEquipmentInvWrapper(final LivingEntity entity, final EquipmentSlotType.Group slotType)
|
||||
public EntityEquipmentInvWrapper(final LivingEntity entity, final EquipmentSlot.Type slotType)
|
||||
{
|
||||
this.entity = entity;
|
||||
|
||||
final List<EquipmentSlotType> slots = new ArrayList<EquipmentSlotType>();
|
||||
final List<EquipmentSlot> slots = new ArrayList<EquipmentSlot>();
|
||||
|
||||
for (final EquipmentSlotType slot : EquipmentSlotType.values())
|
||||
for (final EquipmentSlot slot : EquipmentSlot.values())
|
||||
{
|
||||
if (slot.getType() == slotType)
|
||||
{
|
||||
@@ -93,7 +88,7 @@ public abstract class EntityEquipmentInvWrapper implements IItemHandlerModifiabl
|
||||
if (stack.isEmpty())
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
final EquipmentSlotType equipmentSlot = validateSlotIndex(slot);
|
||||
final EquipmentSlot equipmentSlot = validateSlotIndex(slot);
|
||||
|
||||
final ItemStack existing = entity.getItemBySlot(equipmentSlot);
|
||||
|
||||
@@ -134,7 +129,7 @@ public abstract class EntityEquipmentInvWrapper implements IItemHandlerModifiabl
|
||||
if (amount == 0)
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
final EquipmentSlotType equipmentSlot = validateSlotIndex(slot);
|
||||
final EquipmentSlot equipmentSlot = validateSlotIndex(slot);
|
||||
|
||||
final ItemStack existing = entity.getItemBySlot(equipmentSlot);
|
||||
|
||||
@@ -166,8 +161,8 @@ public abstract class EntityEquipmentInvWrapper implements IItemHandlerModifiabl
|
||||
@Override
|
||||
public int getSlotLimit(final int slot)
|
||||
{
|
||||
final EquipmentSlotType equipmentSlot = validateSlotIndex(slot);
|
||||
return equipmentSlot.getType() == EquipmentSlotType.Group.ARMOR ? 1 : 64;
|
||||
final EquipmentSlot equipmentSlot = validateSlotIndex(slot);
|
||||
return equipmentSlot.getType() == EquipmentSlot.Type.ARMOR ? 1 : 64;
|
||||
}
|
||||
|
||||
protected int getStackLimit(final int slot, @Nonnull final ItemStack stack)
|
||||
@@ -178,7 +173,7 @@ public abstract class EntityEquipmentInvWrapper implements IItemHandlerModifiabl
|
||||
@Override
|
||||
public void setStackInSlot(final int slot, @Nonnull final ItemStack stack)
|
||||
{
|
||||
final EquipmentSlotType equipmentSlot = validateSlotIndex(slot);
|
||||
final EquipmentSlot equipmentSlot = validateSlotIndex(slot);
|
||||
if (ItemStack.matches(entity.getItemBySlot(equipmentSlot), stack))
|
||||
return;
|
||||
entity.setItemSlot(equipmentSlot, stack);
|
||||
@@ -190,7 +185,7 @@ public abstract class EntityEquipmentInvWrapper implements IItemHandlerModifiabl
|
||||
return true;
|
||||
}
|
||||
|
||||
protected EquipmentSlotType validateSlotIndex(final int slot)
|
||||
protected EquipmentSlot validateSlotIndex(final int slot)
|
||||
{
|
||||
if (slot < 0 || slot >= slots.size())
|
||||
throw new IllegalArgumentException("Slot " + slot + " not in valid range - [0," + slots.size() + ")");
|
||||
|
||||
@@ -19,9 +19,8 @@
|
||||
|
||||
package net.minecraftforge.items.wrapper;
|
||||
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.inventory.EquipmentSlotType;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
|
||||
/**
|
||||
* Exposes the hands inventory of an {@link EntityLivingBase} as an {@link IItemHandler} using {@link EntityLivingBase#getItemStackFromSlot} and
|
||||
@@ -31,6 +30,6 @@ public class EntityHandsInvWrapper extends EntityEquipmentInvWrapper
|
||||
{
|
||||
public EntityHandsInvWrapper(LivingEntity entity)
|
||||
{
|
||||
super(entity, EquipmentSlotType.Group.HAND);
|
||||
super(entity, EquipmentSlot.Type.HAND);
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
package net.minecraftforge.items.wrapper;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
@@ -28,9 +28,9 @@ import javax.annotation.Nonnull;
|
||||
|
||||
public class InvWrapper implements IItemHandlerModifiable
|
||||
{
|
||||
private final IInventory inv;
|
||||
private final Container inv;
|
||||
|
||||
public InvWrapper(IInventory inv)
|
||||
public InvWrapper(Container inv)
|
||||
{
|
||||
this.inv = inv;
|
||||
}
|
||||
@@ -210,7 +210,7 @@ public class InvWrapper implements IItemHandlerModifiable
|
||||
return getInv().canPlaceItem(slot, stack);
|
||||
}
|
||||
|
||||
public IInventory getInv()
|
||||
public Container getInv()
|
||||
{
|
||||
return inv;
|
||||
}
|
||||
|
||||
@@ -19,17 +19,17 @@
|
||||
|
||||
package net.minecraftforge.items.wrapper;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.EquipmentSlotType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class PlayerArmorInvWrapper extends RangedWrapper
|
||||
{
|
||||
private final PlayerInventory inventoryPlayer;
|
||||
private final Inventory inventoryPlayer;
|
||||
|
||||
public PlayerArmorInvWrapper(PlayerInventory inv)
|
||||
public PlayerArmorInvWrapper(Inventory inv)
|
||||
{
|
||||
super(new InvWrapper(inv), inv.items.size(), inv.items.size() + inv.armor.size());
|
||||
inventoryPlayer = inv;
|
||||
@@ -39,10 +39,10 @@ public class PlayerArmorInvWrapper extends RangedWrapper
|
||||
@Nonnull
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
|
||||
{
|
||||
EquipmentSlotType equ = null;
|
||||
for (EquipmentSlotType s : EquipmentSlotType.values())
|
||||
EquipmentSlot equ = null;
|
||||
for (EquipmentSlot s : EquipmentSlot.values())
|
||||
{
|
||||
if (s.getType() == EquipmentSlotType.Group.ARMOR && s.getIndex() == slot)
|
||||
if (s.getType() == EquipmentSlot.Type.ARMOR && s.getIndex() == slot)
|
||||
{
|
||||
equ = s;
|
||||
break;
|
||||
@@ -56,7 +56,7 @@ public class PlayerArmorInvWrapper extends RangedWrapper
|
||||
return stack;
|
||||
}
|
||||
|
||||
public PlayerInventory getInventoryPlayer()
|
||||
public Inventory getInventoryPlayer()
|
||||
{
|
||||
return inventoryPlayer;
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
|
||||
package net.minecraftforge.items.wrapper;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class PlayerInvWrapper extends CombinedInvWrapper
|
||||
{
|
||||
public PlayerInvWrapper(PlayerInventory inv)
|
||||
public PlayerInvWrapper(Inventory inv)
|
||||
{
|
||||
super(new PlayerMainInvWrapper(inv), new PlayerArmorInvWrapper(inv), new PlayerOffhandInvWrapper(inv));
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
|
||||
package net.minecraftforge.items.wrapper;
|
||||
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -31,9 +31,9 @@ import javax.annotation.Nonnull;
|
||||
*/
|
||||
public class PlayerMainInvWrapper extends RangedWrapper
|
||||
{
|
||||
private final PlayerInventory inventoryPlayer;
|
||||
private final Inventory inventoryPlayer;
|
||||
|
||||
public PlayerMainInvWrapper(PlayerInventory inv)
|
||||
public PlayerMainInvWrapper(Inventory inv)
|
||||
{
|
||||
super(new InvWrapper(inv), 0, inv.items.size());
|
||||
inventoryPlayer = inv;
|
||||
@@ -54,7 +54,7 @@ public class PlayerMainInvWrapper extends RangedWrapper
|
||||
{
|
||||
inSlot.setPopTime(5);
|
||||
}
|
||||
else if(getInventoryPlayer().player instanceof ServerPlayerEntity) {
|
||||
else if(getInventoryPlayer().player instanceof ServerPlayer) {
|
||||
getInventoryPlayer().player.containerMenu.broadcastChanges();
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class PlayerMainInvWrapper extends RangedWrapper
|
||||
return rest;
|
||||
}
|
||||
|
||||
public PlayerInventory getInventoryPlayer()
|
||||
public Inventory getInventoryPlayer()
|
||||
{
|
||||
return inventoryPlayer;
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
|
||||
package net.minecraftforge.items.wrapper;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class PlayerOffhandInvWrapper extends RangedWrapper
|
||||
{
|
||||
public PlayerOffhandInvWrapper(PlayerInventory inv)
|
||||
public PlayerOffhandInvWrapper(Inventory inv)
|
||||
{
|
||||
super(new InvWrapper(inv), inv.items.size() + inv.armor.size(),
|
||||
inv.items.size() + inv.armor.size() + inv.offhand.size());
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
package net.minecraftforge.items.wrapper;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
|
||||
package net.minecraftforge.items.wrapper;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
public class RecipeWrapper implements IInventory {
|
||||
public class RecipeWrapper implements Container {
|
||||
|
||||
protected final IItemHandlerModifiable inv;
|
||||
|
||||
@@ -113,10 +113,10 @@ public class RecipeWrapper implements IInventory {
|
||||
@Override
|
||||
public void setChanged() {}
|
||||
@Override
|
||||
public boolean stillValid(PlayerEntity player) { return false; }
|
||||
public boolean stillValid(Player player) { return false; }
|
||||
@Override
|
||||
public void startOpen(PlayerEntity player) {}
|
||||
public void startOpen(Player player) {}
|
||||
@Override
|
||||
public void stopOpen(PlayerEntity player) {}
|
||||
public void stopOpen(Player player) {}
|
||||
|
||||
}
|
||||
@@ -19,9 +19,9 @@
|
||||
|
||||
package net.minecraftforge.items.wrapper;
|
||||
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.world.WorldlyContainer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
@@ -31,12 +31,12 @@ import javax.annotation.Nullable;
|
||||
|
||||
public class SidedInvWrapper implements IItemHandlerModifiable
|
||||
{
|
||||
protected final ISidedInventory inv;
|
||||
protected final WorldlyContainer inv;
|
||||
@Nullable
|
||||
protected final Direction side;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static LazyOptional<IItemHandlerModifiable>[] create(ISidedInventory inv, Direction... sides) {
|
||||
public static LazyOptional<IItemHandlerModifiable>[] create(WorldlyContainer inv, Direction... sides) {
|
||||
LazyOptional<IItemHandlerModifiable>[] ret = new LazyOptional[sides.length];
|
||||
for (int x = 0; x < sides.length; x++) {
|
||||
final Direction side = sides[x];
|
||||
@@ -45,13 +45,13 @@ public class SidedInvWrapper implements IItemHandlerModifiable
|
||||
return ret;
|
||||
}
|
||||
|
||||
public SidedInvWrapper(ISidedInventory inv, @Nullable Direction side)
|
||||
public SidedInvWrapper(WorldlyContainer inv, @Nullable Direction side)
|
||||
{
|
||||
this.inv = inv;
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
public static int getSlot(ISidedInventory inv, int slot, @Nullable Direction side)
|
||||
public static int getSlot(WorldlyContainer inv, int slot, @Nullable Direction side)
|
||||
{
|
||||
int[] slots = inv.getSlotsForFace(side);
|
||||
if (slot < slots.length)
|
||||
|
||||
Reference in new issue
Block a user