Implemented capabilities for cable buses in a way that dispatches the capabilities to the parts on the appropriate attachment point. Implemented the capabilities for interface parts and tiles to provide a proof of concept.
This commit is contained in:
parent
8666936646
commit
882f240307
|
@ -37,11 +37,13 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
|
@ -287,4 +289,30 @@ public interface IPart extends IBoxProvider, ICustomCableConnection
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement this method if your part exposes capabilitys. Any requests for capabilities on the cable bus will be forwarded to parts on the appropriate
|
||||
* side.
|
||||
*
|
||||
* @see TileEntity#hasCapability(Capability, EnumFacing)
|
||||
*
|
||||
* @return True if your part has the requested capability.
|
||||
*/
|
||||
default boolean hasCapability( Capability<?> capabilityClass )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement this method if your part exposes capabilitys. Any requests for capabilities on the cable bus will be forwarded to parts on the appropriate
|
||||
* side.
|
||||
*
|
||||
* @see TileEntity#getCapability(Capability, EnumFacing)
|
||||
*
|
||||
* @return The capability or null.
|
||||
*/
|
||||
default <T> T getCapability( Capability<T> capabilityClass )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -43,6 +43,10 @@ import net.minecraft.util.math.BlockPos;
|
|||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
|
@ -129,6 +133,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
|||
private List<ItemStack> waitingToSend = null;
|
||||
private IMEInventory<IAEItemStack> destination;
|
||||
private boolean isWorking = false;
|
||||
private IItemHandler itemHandler = null;
|
||||
|
||||
public DualityInterface( final AENetworkProxy networkProxy, final IInterfaceHost ih )
|
||||
{
|
||||
|
@ -1262,6 +1267,25 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
|||
}
|
||||
}
|
||||
|
||||
public boolean hasCapability( Capability<?> capabilityClass, EnumFacing facing )
|
||||
{
|
||||
return capabilityClass == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;
|
||||
}
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
public <T> T getCapability( Capability<T> capabilityClass, EnumFacing facing )
|
||||
{
|
||||
if( capabilityClass == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY )
|
||||
{
|
||||
if( itemHandler == null )
|
||||
{
|
||||
itemHandler = new InvWrapper( storage );
|
||||
}
|
||||
return (T) itemHandler;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private class InterfaceRequestSource extends MachineSource
|
||||
{
|
||||
|
||||
|
@ -1302,4 +1326,5 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
|||
return super.extractItems( request, type, src );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ import net.minecraft.util.EnumHand;
|
|||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.Upgrades;
|
||||
|
@ -444,4 +446,16 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISto
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability( Capability<?> capabilityClass )
|
||||
{
|
||||
return this.duality.hasCapability( capabilityClass, getSide().getFacing() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getCapability( Capability<T> capabilityClass )
|
||||
{
|
||||
return this.duality.getCapability( capabilityClass, getSide().getFacing() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ package appeng.tile.misc;
|
|||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
@ -34,6 +36,7 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.Upgrades;
|
||||
|
@ -364,4 +367,16 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, IT
|
|||
return this.omniDirectional;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability( Capability<?> capability, @Nullable EnumFacing facing )
|
||||
{
|
||||
return this.duality.hasCapability( capability, facing );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getCapability( Capability<T> capability, @Nullable EnumFacing facing )
|
||||
{
|
||||
return this.duality.getCapability( capability, facing );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package appeng.tile.networking;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
|
@ -35,6 +36,7 @@ import net.minecraft.util.math.AxisAlignedBB;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.parts.IFacadeContainer;
|
||||
|
@ -391,4 +393,24 @@ public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomColl
|
|||
this.cb = cb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability( Capability<?> capabilityClass, @Nullable EnumFacing fromSide )
|
||||
{
|
||||
// Note that null will be translated to INTERNAL here
|
||||
AEPartLocation partLocation = AEPartLocation.fromFacing( fromSide );
|
||||
|
||||
IPart part = getPart( partLocation );
|
||||
return part != null && part.hasCapability( capabilityClass );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getCapability( Capability<T> capabilityClass, @Nullable EnumFacing fromSide )
|
||||
{
|
||||
// Note that null will be translated to INTERNAL here
|
||||
AEPartLocation partLocation = AEPartLocation.fromFacing( fromSide );
|
||||
|
||||
IPart part = getPart( partLocation );
|
||||
return part == null ? null : part.getCapability( capabilityClass );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue