use of net.minecraftforge.common.capabilities.Capability in project MorePlanets by SteveKunG.
the class CapabilityHandlerMP method register.
public static void register() {
CapabilityManager.INSTANCE.register(AbstractCapabilityDataMP.class, new Capability.IStorage<AbstractCapabilityDataMP>() {
@Override
public NBTBase writeNBT(Capability<AbstractCapabilityDataMP> capability, AbstractCapabilityDataMP instance, EnumFacing side) {
NBTTagCompound nbt = new NBTTagCompound();
instance.writeNBT(nbt);
return nbt;
}
@Override
public void readNBT(Capability<AbstractCapabilityDataMP> capability, AbstractCapabilityDataMP instance, EnumFacing side, NBTBase nbt) {
instance.readNBT((NBTTagCompound) nbt);
}
}, CapabilityDataMP::new);
CommonUtils.registerEventHandler(new CapabilityHandlerMP());
}
use of net.minecraftforge.common.capabilities.Capability in project Tropicraft by Tropicraft.
the class ScubaData method onPlayerTick.
@SubscribeEvent
public static void onPlayerTick(PlayerTickEvent event) {
Level world = event.player.level;
if (event.phase == Phase.END) {
// TODO support more than chest slot?
ItemStack chestStack = event.player.getItemBySlot(EquipmentSlot.CHEST);
Item chestItem = chestStack.getItem();
if (chestItem instanceof ScubaArmorItem) {
LazyOptional<ScubaData> data = event.player.getCapability(CAPABILITY);
if (!world.isClientSide) {
underwaterPlayers.add((ServerPlayer) event.player);
}
if (isUnderWater(event.player)) {
data.ifPresent(d -> {
d.tick(event.player);
if (!world.isClientSide) {
d.updateClient((ServerPlayer) event.player, false);
}
});
((ScubaArmorItem) chestItem).tickAir(event.player, EquipmentSlot.CHEST, chestStack);
if (!world.isClientSide && world.getGameTime() % 60 == 0) {
// TODO this effect could be better, custom packet?
Vec3 eyePos = event.player.getEyePosition(0);
Vec3 motion = event.player.getDeltaMovement();
Vec3 particlePos = eyePos.add(motion.reverse());
((ServerLevel) world).sendParticles(ParticleTypes.BUBBLE, particlePos.x(), particlePos.y(), particlePos.z(), 4 + world.random.nextInt(3), 0.25, 0.25, 0.25, motion.length());
}
} else if (!world.isClientSide && underwaterPlayers.remove(event.player)) {
// Update client state as they leave the water
data.ifPresent(d -> d.updateClient((ServerPlayer) event.player, false));
}
}
}
}
use of net.minecraftforge.common.capabilities.Capability in project Charset by CharsetMC.
the class Capabilities method init.
public static void init() {
CapabilityManager.INSTANCE.register(IBundledEmitter.class, new DefaultBundledEmitterStorage(), DefaultBundledEmitter.class);
CapabilityManager.INSTANCE.register(IRedstoneEmitter.class, new DefaultRedstoneEmitterStorage(), DefaultRedstoneEmitter.class);
CapabilityManager.INSTANCE.register(IBundledReceiver.class, new Capability.IStorage<IBundledReceiver>() {
@Override
public NBTBase writeNBT(Capability<IBundledReceiver> capability, IBundledReceiver instance, EnumFacing side) {
return null;
}
@Override
public void readNBT(Capability<IBundledReceiver> capability, IBundledReceiver instance, EnumFacing side, NBTBase nbt) {
}
}, DummyRedstoneReceiver.class);
CapabilityManager.INSTANCE.register(IRedstoneReceiver.class, new Capability.IStorage<IRedstoneReceiver>() {
@Override
public NBTBase writeNBT(Capability<IRedstoneReceiver> capability, IRedstoneReceiver instance, EnumFacing side) {
return null;
}
@Override
public void readNBT(Capability<IRedstoneReceiver> capability, IRedstoneReceiver instance, EnumFacing side, NBTBase nbt) {
}
}, DummyRedstoneReceiver.class);
if (Loader.isModLoaded("mcmultipart")) {
initMultiplePants();
}
}
use of net.minecraftforge.common.capabilities.Capability in project MC-Prefab by Brian-Wuest.
the class TileEntityBase method transferCapabilities.
/**
* Transfers capabilities available for transferring to the supplied itemstack.
* @param stack The item stack to copy capabilities for.
* @return The updated item stack with the original ItemStack's capabilities.
*/
public ItemStack transferCapabilities(ItemStack stack) {
// Transfer each transferable capability to the itemstack.
for (Capability allowedCapability : this.getAllowedCapabilities()) {
// Get the interfaces for this capability.
Object stackCapability = stack.getCapability(allowedCapability, EnumFacing.NORTH);
Object tileEntityCapability = this.getCapability(allowedCapability, EnumFacing.NORTH);
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) stackCapability).Transfer((ITransferable) tileEntityCapability);
}
}
return stack;
}
use of net.minecraftforge.common.capabilities.Capability in project BuildCraft by BuildCraft.
the class CapabilityHelper method getCapability.
@SuppressWarnings("unchecked")
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, EnumFacing facing) {
Map<Capability<?>, Supplier<?>> capMap = getCapMap(facing);
Supplier<?> supplier = capMap.get(capability);
if (supplier != null) {
return (T) supplier.get();
}
for (ICapabilityProvider provider : additional) {
if (provider.hasCapability(capability, facing)) {
return provider.getCapability(capability, facing);
}
}
return null;
}
Aggregations