mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-26 06:53:20 +00:00
More compile cleanups. (#5139)
This commit is contained in:
1 parent
dbf649225a
commit
3f743887e7
71 files changed
+901
-411
No files matched your search
@@ -74,10 +74,11 @@ public class ItemHandlerHelper
|
||||
|
||||
// Metadata value only matters when the item has subtypes
|
||||
// Vanilla stacks non-subtype items with different metadata together
|
||||
// e.g. a stick with metadata 0 and a stick with metadata 1 stack
|
||||
// TODO Item subtypes, is this still necessary?
|
||||
/* e.g. a stick with metadata 0 and a stick with metadata 1 stack
|
||||
if (a.getHasSubtypes() && a.getMetadata() != b.getMetadata())
|
||||
return false;
|
||||
|
||||
*/
|
||||
if (a.hasTagCompound() != b.hasTagCompound())
|
||||
return false;
|
||||
|
||||
|
||||
@@ -24,12 +24,13 @@ import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryBasic;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class SlotItemHandler extends Slot
|
||||
{
|
||||
private static IInventory emptyInventory = new InventoryBasic("[Null]", true, 0);
|
||||
private static IInventory emptyInventory = new InventoryBasic(new TextComponentString("[Null]"), 0);
|
||||
private final IItemHandler itemHandler;
|
||||
private final int index;
|
||||
|
||||
@@ -140,10 +141,10 @@ public class SlotItemHandler extends Slot
|
||||
{
|
||||
return itemHandler;
|
||||
}
|
||||
|
||||
/* TODO Slot patches
|
||||
@Override
|
||||
public boolean isSameInventory(Slot other)
|
||||
{
|
||||
return other instanceof SlotItemHandler && ((SlotItemHandler) other).getItemHandler() == this.itemHandler;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@@ -20,6 +20,7 @@
|
||||
package net.minecraftforge.items;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityChest;
|
||||
@@ -58,7 +59,7 @@ public class VanillaDoubleChestItemHandler extends WeakReference<TileEntityChest
|
||||
if (world == null || pos == null || !world.isBlockLoaded(pos))
|
||||
return null; // Still loading
|
||||
|
||||
Block blockType = chest.getBlockType();
|
||||
IBlockState state = chest.func_195044_w();
|
||||
|
||||
EnumFacing[] horizontals = EnumFacing.HORIZONTALS;
|
||||
for (int i = horizontals.length - 1; i >= 0; i--) // Use reverse order so we can return early
|
||||
@@ -67,7 +68,7 @@ public class VanillaDoubleChestItemHandler extends WeakReference<TileEntityChest
|
||||
BlockPos blockpos = pos.offset(enumfacing);
|
||||
Block block = world.getBlockState(blockpos).getBlock();
|
||||
|
||||
if (block == blockType)
|
||||
if (block == state.getBlock())
|
||||
{
|
||||
TileEntity otherTE = world.getTileEntity(blockpos);
|
||||
|
||||
@@ -125,7 +126,7 @@ public class VanillaDoubleChestItemHandler extends WeakReference<TileEntityChest
|
||||
TileEntityChest chest = getChest(accessingUpperChest);
|
||||
if (chest != null)
|
||||
{
|
||||
IItemHandler singleHandler = chest.getSingleChestHandler();
|
||||
IItemHandler singleHandler = null; // TODO TileEntityChest patches chest.getSingleChestHandler();
|
||||
if (singleHandler instanceof IItemHandlerModifiable)
|
||||
{
|
||||
((IItemHandlerModifiable) singleHandler).setStackInSlot(targetSlot, stack);
|
||||
@@ -148,7 +149,7 @@ public class VanillaDoubleChestItemHandler extends WeakReference<TileEntityChest
|
||||
return stack;
|
||||
|
||||
int starting = stack.getCount();
|
||||
ItemStack ret = chest.getSingleChestHandler().insertItem(targetSlot, stack, simulate);
|
||||
ItemStack ret = ItemStack.EMPTY; // TODO TileEntityChest patches chest.getSingleChestHandler().insertItem(targetSlot, stack, simulate);
|
||||
if (ret.getCount() != starting && !simulate)
|
||||
{
|
||||
chest = getChest(!accessingUpperChest);
|
||||
@@ -169,7 +170,7 @@ public class VanillaDoubleChestItemHandler extends WeakReference<TileEntityChest
|
||||
if (chest == null)
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
ItemStack ret = chest.getSingleChestHandler().extractItem(targetSlot, amount, simulate);
|
||||
ItemStack ret = ItemStack.EMPTY; // TODO TileEntityChest patches chest.getSingleChestHandler().extractItem(targetSlot, amount, simulate);
|
||||
if (!ret.isEmpty() && !simulate)
|
||||
{
|
||||
chest = getChest(!accessingUpperChest);
|
||||
@@ -195,7 +196,7 @@ public class VanillaDoubleChestItemHandler extends WeakReference<TileEntityChest
|
||||
TileEntityChest chest = getChest(accessingUpperChest);
|
||||
if (chest != null)
|
||||
{
|
||||
return chest.getSingleChestHandler().isItemValid(targetSlot, stack);
|
||||
return false; // TODO TileEntityChest patches chest.getSingleChestHandler().isItemValid(targetSlot, stack);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.OptionalCapabilityInstance;
|
||||
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
@@ -46,38 +48,38 @@ public class VanillaInventoryCodeHooks
|
||||
@Nullable
|
||||
public static Boolean extractHook(IHopper dest)
|
||||
{
|
||||
Pair<IItemHandler, Object> itemHandlerResult = getItemHandler(dest, EnumFacing.UP);
|
||||
if (itemHandlerResult == null)
|
||||
return null;
|
||||
|
||||
IItemHandler handler = itemHandlerResult.getKey();
|
||||
|
||||
for (int i = 0; i < handler.getSlots(); i++)
|
||||
{
|
||||
ItemStack extractItem = handler.extractItem(i, 1, true);
|
||||
if (!extractItem.isEmpty())
|
||||
{
|
||||
for (int j = 0; j < dest.getSizeInventory(); j++)
|
||||
{
|
||||
ItemStack destStack = dest.getStackInSlot(j);
|
||||
if (dest.isItemValidForSlot(j, extractItem) && (destStack.isEmpty() || destStack.getCount() < destStack.getMaxStackSize() && destStack.getCount() < dest.getInventoryStackLimit() && ItemHandlerHelper.canItemStacksStack(extractItem, destStack)))
|
||||
return getItemHandler(dest, EnumFacing.UP)
|
||||
.map(itemHandlerResult -> {
|
||||
IItemHandler handler = itemHandlerResult.getKey();
|
||||
|
||||
for (int i = 0; i < handler.getSlots(); i++)
|
||||
{
|
||||
extractItem = handler.extractItem(i, 1, false);
|
||||
if (destStack.isEmpty())
|
||||
dest.setInventorySlotContents(j, extractItem);
|
||||
else
|
||||
ItemStack extractItem = handler.extractItem(i, 1, true);
|
||||
if (!extractItem.isEmpty())
|
||||
{
|
||||
destStack.grow(1);
|
||||
dest.setInventorySlotContents(j, destStack);
|
||||
for (int j = 0; j < dest.getSizeInventory(); j++)
|
||||
{
|
||||
ItemStack destStack = dest.getStackInSlot(j);
|
||||
if (dest.isItemValidForSlot(j, extractItem) && (destStack.isEmpty() || destStack.getCount() < destStack.getMaxStackSize() && destStack.getCount() < dest.getInventoryStackLimit() && ItemHandlerHelper.canItemStacksStack(extractItem, destStack)))
|
||||
{
|
||||
extractItem = handler.extractItem(i, 1, false);
|
||||
if (destStack.isEmpty())
|
||||
dest.setInventorySlotContents(j, extractItem);
|
||||
else
|
||||
{
|
||||
destStack.grow(1);
|
||||
dest.setInventorySlotContents(j, destStack);
|
||||
}
|
||||
dest.markDirty();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
dest.markDirty();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
return false;
|
||||
})
|
||||
.orElse(null); // TODO bad null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,31 +89,27 @@ public class VanillaInventoryCodeHooks
|
||||
{
|
||||
EnumFacing enumfacing = world.getBlockState(pos).getValue(BlockDropper.FACING);
|
||||
BlockPos blockpos = pos.offset(enumfacing);
|
||||
Pair<IItemHandler, Object> destinationResult = getItemHandler(world, (double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ(), enumfacing.getOpposite());
|
||||
if (destinationResult == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
IItemHandler itemHandler = destinationResult.getKey();
|
||||
Object destination = destinationResult.getValue();
|
||||
ItemStack dispensedStack = stack.copy().splitStack(1);
|
||||
ItemStack remainder = putStackInInventoryAllSlots(dropper, destination, itemHandler, dispensedStack);
|
||||
|
||||
if (remainder.isEmpty())
|
||||
{
|
||||
remainder = stack.copy();
|
||||
remainder.shrink(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
remainder = stack.copy();
|
||||
}
|
||||
|
||||
dropper.setInventorySlotContents(slot, remainder);
|
||||
return false;
|
||||
}
|
||||
return getItemHandler(world, (double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ(), enumfacing.getOpposite())
|
||||
.map(destinationResult -> {
|
||||
IItemHandler itemHandler = destinationResult.getKey();
|
||||
Object destination = destinationResult.getValue();
|
||||
ItemStack dispensedStack = stack.copy().splitStack(1);
|
||||
ItemStack remainder = putStackInInventoryAllSlots(dropper, destination, itemHandler, dispensedStack);
|
||||
|
||||
if (remainder.isEmpty())
|
||||
{
|
||||
remainder = stack.copy();
|
||||
remainder.shrink(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
remainder = stack.copy();
|
||||
}
|
||||
|
||||
dropper.setInventorySlotContents(slot, remainder);
|
||||
return false;
|
||||
})
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,42 +117,38 @@ public class VanillaInventoryCodeHooks
|
||||
*/
|
||||
public static boolean insertHook(TileEntityHopper hopper)
|
||||
{
|
||||
EnumFacing hopperFacing = BlockHopper.getFacing(hopper.getBlockMetadata());
|
||||
Pair<IItemHandler, Object> destinationResult = getItemHandler(hopper, hopperFacing);
|
||||
if (destinationResult == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
IItemHandler itemHandler = destinationResult.getKey();
|
||||
Object destination = destinationResult.getValue();
|
||||
if (isFull(itemHandler))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < hopper.getSizeInventory(); ++i)
|
||||
{
|
||||
if (!hopper.getStackInSlot(i).isEmpty())
|
||||
EnumFacing hopperFacing = hopper.func_195044_w().getValue(BlockHopper.FACING);
|
||||
return getItemHandler(hopper, hopperFacing)
|
||||
.map(destinationResult -> {
|
||||
IItemHandler itemHandler = destinationResult.getKey();
|
||||
Object destination = destinationResult.getValue();
|
||||
if (isFull(itemHandler))
|
||||
{
|
||||
ItemStack originalSlotContents = hopper.getStackInSlot(i).copy();
|
||||
ItemStack insertStack = hopper.decrStackSize(i, 1);
|
||||
ItemStack remainder = putStackInInventoryAllSlots(hopper, destination, itemHandler, insertStack);
|
||||
|
||||
if (remainder.isEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
hopper.setInventorySlotContents(i, originalSlotContents);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < hopper.getSizeInventory(); ++i)
|
||||
{
|
||||
if (!hopper.getStackInSlot(i).isEmpty())
|
||||
{
|
||||
ItemStack originalSlotContents = hopper.getStackInSlot(i).copy();
|
||||
ItemStack insertStack = hopper.decrStackSize(i, 1);
|
||||
ItemStack remainder = putStackInInventoryAllSlots(hopper, destination, itemHandler, insertStack);
|
||||
|
||||
if (remainder.isEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
hopper.setInventorySlotContents(i, originalSlotContents);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
private static ItemStack putStackInInventoryAllSlots(TileEntity source, Object destination, IItemHandler destInventory, ItemStack stack)
|
||||
@@ -200,7 +194,7 @@ public class VanillaInventoryCodeHooks
|
||||
if (!destinationHopper.mayTransfer())
|
||||
{
|
||||
int k = 0;
|
||||
|
||||
/* TODO TileEntityHopper patches
|
||||
if (source instanceof TileEntityHopper)
|
||||
{
|
||||
if (destinationHopper.getLastUpdateTime() >= ((TileEntityHopper) source).getLastUpdateTime())
|
||||
@@ -208,7 +202,7 @@ public class VanillaInventoryCodeHooks
|
||||
k = 1;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
destinationHopper.setTransferCooldown(8 - k);
|
||||
}
|
||||
}
|
||||
@@ -218,12 +212,11 @@ public class VanillaInventoryCodeHooks
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Pair<IItemHandler, Object> getItemHandler(IHopper hopper, EnumFacing hopperFacing)
|
||||
private static OptionalCapabilityInstance<Pair<IItemHandler, Object>> getItemHandler(IHopper hopper, EnumFacing hopperFacing)
|
||||
{
|
||||
double x = hopper.getXPos() + (double) hopperFacing.getFrontOffsetX();
|
||||
double y = hopper.getYPos() + (double) hopperFacing.getFrontOffsetY();
|
||||
double z = hopper.getZPos() + (double) hopperFacing.getFrontOffsetZ();
|
||||
double x = hopper.getXPos() + (double) hopperFacing.getXOffset();
|
||||
double y = hopper.getYPos() + (double) hopperFacing.getYOffset();
|
||||
double z = hopper.getZPos() + (double) hopperFacing.getZOffset();
|
||||
return getItemHandler(hopper.getWorld(), x, y, z, hopperFacing.getOpposite());
|
||||
}
|
||||
|
||||
@@ -253,10 +246,8 @@ public class VanillaInventoryCodeHooks
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Pair<IItemHandler, Object> getItemHandler(World worldIn, double x, double y, double z, final EnumFacing side)
|
||||
public static OptionalCapabilityInstance<Pair<IItemHandler, Object>> getItemHandler(World worldIn, double x, double y, double z, final EnumFacing side)
|
||||
{
|
||||
Pair<IItemHandler, Object> destination = null;
|
||||
int i = MathHelper.floor(x);
|
||||
int j = MathHelper.floor(y);
|
||||
int k = MathHelper.floor(z);
|
||||
@@ -264,19 +255,16 @@ public class VanillaInventoryCodeHooks
|
||||
net.minecraft.block.state.IBlockState state = worldIn.getBlockState(blockpos);
|
||||
Block block = state.getBlock();
|
||||
|
||||
if (block.hasTileEntity(state))
|
||||
if (block.hasTileEntity(/* TODO Block patches // state */))
|
||||
{
|
||||
TileEntity tileentity = worldIn.getTileEntity(blockpos);
|
||||
if (tileentity != null)
|
||||
{
|
||||
if (tileentity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side))
|
||||
{
|
||||
IItemHandler capability = tileentity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
|
||||
destination = ImmutablePair.<IItemHandler, Object>of(capability, tileentity);
|
||||
}
|
||||
return tileentity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)
|
||||
.map(capability -> ImmutablePair.<IItemHandler, Object>of(capability, tileentity));
|
||||
}
|
||||
}
|
||||
|
||||
return destination;
|
||||
return OptionalCapabilityInstance.empty();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user