use of net.minecraftforge.common.capabilities.Capability in project MorePlanets by SteveKunG.
the class CapabilityHandlerMP method register.
public static void register() {
CapabilityManager.INSTANCE.register(MorePlanetsCapabilityData.class, new Capability.IStorage<MorePlanetsCapabilityData>() {
@Override
public NBTBase writeNBT(Capability<MorePlanetsCapabilityData> capability, MorePlanetsCapabilityData instance, EnumFacing side) {
NBTTagCompound nbt = new NBTTagCompound();
instance.writeNBT(nbt);
return nbt;
}
@Override
public void readNBT(Capability<MorePlanetsCapabilityData> capability, MorePlanetsCapabilityData instance, EnumFacing side, NBTBase nbt) {
instance.readNBT((NBTTagCompound) nbt);
}
}, MPCapData::new);
CommonRegisterHelper.registerForgeEvent(new CapabilityHandlerMP());
}
use of net.minecraftforge.common.capabilities.Capability in project RFTools by McJty.
the class CommonProxy method preInit.
public void preInit(FMLPreInitializationEvent e) {
MinecraftForge.EVENT_BUS.register(new ForgeEventHandlers());
McJtyLib.preInit(e);
CommandHandler.registerCommands();
reflect();
GeneralConfig.preInit(e);
modConfigDir = e.getModConfigurationDirectory();
mainConfig = new Configuration(new File(modConfigDir.getPath() + File.separator + "rftools", "rftools.cfg"));
CapabilityManager.INSTANCE.register(BuffProperties.class, new Capability.IStorage<BuffProperties>() {
@Override
public NBTBase writeNBT(Capability<BuffProperties> capability, BuffProperties instance, EnumFacing side) {
throw new UnsupportedOperationException();
}
@Override
public void readNBT(Capability<BuffProperties> capability, BuffProperties instance, EnumFacing side, NBTBase nbt) {
throw new UnsupportedOperationException();
}
}, () -> {
throw new UnsupportedOperationException();
});
CapabilityManager.INSTANCE.register(FavoriteDestinationsProperties.class, new Capability.IStorage<FavoriteDestinationsProperties>() {
@Override
public NBTBase writeNBT(Capability<FavoriteDestinationsProperties> capability, FavoriteDestinationsProperties instance, EnumFacing side) {
throw new UnsupportedOperationException();
}
@Override
public void readNBT(Capability<FavoriteDestinationsProperties> capability, FavoriteDestinationsProperties instance, EnumFacing side, NBTBase nbt) {
throw new UnsupportedOperationException();
}
}, () -> {
throw new UnsupportedOperationException();
});
CapabilityManager.INSTANCE.register(IModuleProvider.class, new Capability.IStorage<IModuleProvider>() {
@Override
public NBTBase writeNBT(Capability<IModuleProvider> capability, IModuleProvider instance, EnumFacing side) {
throw new UnsupportedOperationException();
}
@Override
public void readNBT(Capability<IModuleProvider> capability, IModuleProvider instance, EnumFacing side, NBTBase nbt) {
throw new UnsupportedOperationException();
}
}, () -> {
throw new UnsupportedOperationException();
});
readMainConfig();
SimpleNetworkWrapper network = PacketHandler.registerMessages(RFTools.MODID, "rftools");
RFToolsMessages.registerNetworkMessages(network);
ModItems.init();
ModBlocks.init();
ModWorldgen.init();
RFTools.screenModuleRegistry.registerBuiltins();
ForgeChunkManager.setForcedChunkLoadingCallback(RFTools.instance, (tickets, world) -> {
});
}
use of net.minecraftforge.common.capabilities.Capability in project MC-Prefab by Brian-Wuest.
the class ItemBlockCapability method setTileEntityCapabilities.
/**
* Transfers the capability data from this item to the tile entity.
* @param world The world this is affecting.
* @param player The controlling player.
* @param pos The block pos of the placed block.
* @param stack The item stack to set the tile entity capability for.
* @param side The side for which to get the capability for.
*/
protected void setTileEntityCapabilities(World world, EntityPlayer player, BlockPos pos, ItemStack stack, EnumFacing side) {
if (world.isRemote) {
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity != null) {
for (Capability capability : this.allowedCapabilities) {
// Get the interfaces for this capability.
Object stackCapability = stack.getCapability(capability, side);
Object tileEntityCapability = tileEntity.getCapability(capability, side);
if (stackCapability != null && tileEntityCapability != null && stackCapability instanceof ITransferable && tileEntityCapability instanceof ITransferable) {
// transfer the capability data, it's up to the capability to transfer the data.
((ITransferable) tileEntityCapability).Transfer((ITransferable) stackCapability);
}
}
}
}
}
use of net.minecraftforge.common.capabilities.Capability in project Galacticraft by micdoodle8.
the class GCCapabilities method register.
public static void register() {
CapabilityManager.INSTANCE.register(GCPlayerStats.class, new Capability.IStorage<GCPlayerStats>() {
@Override
public NBTBase writeNBT(Capability<GCPlayerStats> capability, GCPlayerStats instance, EnumFacing side) {
NBTTagCompound nbt = new NBTTagCompound();
instance.saveNBTData(nbt);
return nbt;
}
@Override
public void readNBT(Capability<GCPlayerStats> capability, GCPlayerStats instance, EnumFacing side, NBTBase nbt) {
instance.loadNBTData((NBTTagCompound) nbt);
}
}, StatsCapability::new);
CapabilityManager.INSTANCE.register(GCPlayerStatsClient.class, new Capability.IStorage<GCPlayerStatsClient>() {
@Override
public NBTBase writeNBT(Capability<GCPlayerStatsClient> capability, GCPlayerStatsClient instance, EnumFacing side) {
return null;
}
@Override
public void readNBT(Capability<GCPlayerStatsClient> capability, GCPlayerStatsClient instance, EnumFacing side, NBTBase nbt) {
}
}, StatsClientCapability::new);
}
use of net.minecraftforge.common.capabilities.Capability in project ImmersiveEngineering by BluSunrize.
the class CapabilityShader method register.
public static void register() {
CapabilityManager.INSTANCE.register(ShaderWrapper.class, new Capability.IStorage<ShaderWrapper>() {
@Override
public NBTBase writeNBT(Capability<ShaderWrapper> capability, ShaderWrapper instance, EnumFacing side) {
NBTTagCompound nbt = new NBTTagCompound();
ItemStack shader = instance.getShaderItem();
if (!shader.isEmpty())
shader.writeToNBT(nbt);
else
nbt.setString("IE:NoShader", "");
nbt.setString("IE:ShaderType", instance.getShaderType());
return nbt;
}
@Override
public void readNBT(Capability<ShaderWrapper> capability, ShaderWrapper instance, EnumFacing side, NBTBase nbt) {
NBTTagCompound tags = (NBTTagCompound) nbt;
instance.setShaderType(tags.getString("IE:ShaderType"));
if (!tags.hasKey("IE:NoShader"))
instance.setShaderItem(new ItemStack(tags));
}
}, new Callable<ShaderWrapper>() {
@Override
public ShaderWrapper call() {
return new ShaderWrapper_Direct("");
}
});
}
Aggregations