Search in sources :

Example 1 with IMultipartTile

use of mcmultipart.api.multipart.IMultipartTile in project Charset by CharsetMC.

the class MCMPAddonBase method onAttachTile.

@SubscribeEvent
public final void onAttachTile(AttachCapabilitiesEvent<TileEntity> event) {
    if (tileEntityPredicate.test(event.getObject())) {
        final IMultipartTile multipartTile = multipartTileSupplier.apply(event.getObject());
        event.addCapability(KEY, factory.create(multipartTile));
    }
}
Also used : IMultipartTile(mcmultipart.api.multipart.IMultipartTile) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IMultipartTile

use of mcmultipart.api.multipart.IMultipartTile in project Charset by CharsetMC.

the class WireUtils method getWire.

@Nullable
public static Wire getWire(IBlockAccess access, BlockPos pos, WireFace face) {
    IMultipartContainer container = null;
    if (access instanceof IMultipartBlockAccess) {
        access = ((IMultipartBlockAccess) access).getActualWorld();
    }
    Optional<IMultipartContainer> containerOpt = MultipartHelper.getContainer(access, pos);
    if (containerOpt.isPresent()) {
        container = containerOpt.get();
    }
    if (container != null) {
        Optional<IMultipartTile> tile = container.getPartTile(toPartSlot(face));
        if (tile.isPresent() && tile.get().getTileEntity() instanceof TileWire) {
            Wire wire = ((TileWire) tile.get().getTileEntity()).wire;
            if (wire != null && wire.getLocation() == face) {
                return ((TileWire) tile.get().getTileEntity()).wire;
            }
        }
        return null;
    }
    TileEntity tile = access.getTileEntity(pos);
    if (tile != null && tile instanceof TileWire && ((TileWire) tile).wire != null && ((TileWire) tile).wire.getLocation() == face) {
        return ((TileWire) tile).wire;
    } else {
        return null;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMultipartContainer(mcmultipart.api.container.IMultipartContainer) IMultipartBlockAccess(mcmultipart.api.world.IMultipartBlockAccess) IMultipartTile(mcmultipart.api.multipart.IMultipartTile) Nullable(javax.annotation.Nullable)

Example 3 with IMultipartTile

use of mcmultipart.api.multipart.IMultipartTile in project Charset by CharsetMC.

the class MCMPAddonGates method onAttachCaps.

@SubscribeEvent
public void onAttachCaps(AttachCapabilitiesEvent<TileEntity> event) {
    if (event.getObject() instanceof PartGate) {
        final PartGate gate = (PartGate) event.getObject();
        final IMultipartTile mpartTile = new MultipartTile<>(gate);
        event.addCapability(LOC, new ICapabilityProvider() {

            @Override
            public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
                return capability == MCMPCapabilities.MULTIPART_TILE;
            }

            @Nullable
            @Override
            public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
                return capability == MCMPCapabilities.MULTIPART_TILE ? MCMPCapabilities.MULTIPART_TILE.cast(mpartTile) : null;
            }
        });
    }
}
Also used : ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) EnumFacing(net.minecraft.util.EnumFacing) PartGate(pl.asie.simplelogic.gates.PartGate) MultipartTile(pl.asie.charset.lib.modcompat.mcmultipart.MultipartTile) IMultipartTile(mcmultipart.api.multipart.IMultipartTile) IMultipartTile(mcmultipart.api.multipart.IMultipartTile) Nullable(javax.annotation.Nullable) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IMultipartTile (mcmultipart.api.multipart.IMultipartTile)3 Nullable (javax.annotation.Nullable)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 IMultipartContainer (mcmultipart.api.container.IMultipartContainer)1 IMultipartBlockAccess (mcmultipart.api.world.IMultipartBlockAccess)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 ICapabilityProvider (net.minecraftforge.common.capabilities.ICapabilityProvider)1 MultipartTile (pl.asie.charset.lib.modcompat.mcmultipart.MultipartTile)1 PartGate (pl.asie.simplelogic.gates.PartGate)1