mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-22 19:58:35 +01:00
added compatibility for vanilla's weird composter special case
Closes #47
This commit is contained in:
parent
abc5a96b96
commit
072fc3b924
3 changed files with 28 additions and 3 deletions
|
@ -2,10 +2,14 @@ package de.ellpeck.prettypipes;
|
|||
|
||||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import de.ellpeck.prettypipes.network.PipeItem;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.inventory.ISidedInventoryProvider;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
|
@ -23,6 +27,7 @@ import net.minecraft.world.World;
|
|||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.SidedInvWrapper;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -130,6 +135,17 @@ public final class Utility {
|
|||
return items;
|
||||
}
|
||||
|
||||
public static IItemHandler getBlockItemHandler(World world, BlockPos pos, Direction direction) {
|
||||
BlockState state = world.getBlockState(pos);
|
||||
Block block = state.getBlock();
|
||||
if (!(block instanceof ISidedInventoryProvider))
|
||||
return null;
|
||||
ISidedInventory inventory = ((ISidedInventoryProvider) block).createInventory(state, world, pos);
|
||||
if (inventory == null)
|
||||
return null;
|
||||
return new SidedInvWrapper(inventory, direction);
|
||||
}
|
||||
|
||||
public interface IMergeItemStack {
|
||||
boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection);
|
||||
}
|
||||
|
|
|
@ -201,15 +201,19 @@ public class PipeBlock extends ContainerBlock {
|
|||
BlockPos offset = pos.offset(direction);
|
||||
if (!world.isBlockLoaded(offset))
|
||||
return ConnectionType.DISCONNECTED;
|
||||
Direction opposite = direction.getOpposite();
|
||||
TileEntity tile = world.getTileEntity(offset);
|
||||
if (tile != null) {
|
||||
IPipeConnectable connectable = tile.getCapability(Registry.pipeConnectableCapability, direction.getOpposite()).orElse(null);
|
||||
IPipeConnectable connectable = tile.getCapability(Registry.pipeConnectableCapability, opposite).orElse(null);
|
||||
if (connectable != null)
|
||||
return connectable.getConnectionType(pos, direction);
|
||||
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, direction.getOpposite()).orElse(null);
|
||||
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, opposite).orElse(null);
|
||||
if (handler != null)
|
||||
return ConnectionType.CONNECTED;
|
||||
}
|
||||
IItemHandler blockHandler = Utility.getBlockItemHandler(world, offset, opposite);
|
||||
if (blockHandler != null)
|
||||
return ConnectionType.CONNECTED;
|
||||
BlockState offState = world.getBlockState(offset);
|
||||
if (hasLegsTo(world, offState, offset, direction)) {
|
||||
if (DIRECTIONS.values().stream().noneMatch(d -> state.get(d) == ConnectionType.LEGS))
|
||||
|
|
|
@ -13,6 +13,8 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.inventory.ISidedInventoryProvider;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.item.Item;
|
||||
|
@ -304,7 +306,10 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide
|
|||
}
|
||||
|
||||
public IItemHandler getItemHandler(Direction dir) {
|
||||
return this.getNeighborCap(dir, CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
|
||||
IItemHandler handler = this.getNeighborCap(dir, CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
|
||||
if (handler != null)
|
||||
return handler;
|
||||
return Utility.getBlockItemHandler(this.world, this.pos.offset(dir), dir.getOpposite());
|
||||
}
|
||||
|
||||
public <T> T getNeighborCap(Direction dir, Capability<T> cap) {
|
||||
|
|
Loading…
Reference in a new issue