Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

KitoWasHere

Members
  • Joined

  • Last visited

  1. I'm trying to attach a capability to a chunk, but I can't do it, I did it the following way and it doesn't work, what's wrong? How do I solve it? public class BloodDensityProvider implements ICapabilityProvider, INBTSerializable<CompoundTag> { public static Capability<TitanBloodDensity> TITAN_BLOOD_HANDLER = CapabilityManager.get(new CapabilityToken<>() {}); private TitanBloodDensity density; private final LazyOptional<TitanBloodDensity> optional = LazyOptional.of(this::getDensity); public TitanBloodDensity getDensity() { if (density == null) density = new TitanBloodDensity(); return density; } @Override public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { if (cap == TITAN_BLOOD_HANDLER) return optional.cast(); else return LazyOptional.empty(); } @Override public CompoundTag serializeNBT() { CompoundTag nbt = new CompoundTag(); nbt.putInt("density", getDensity().getAmount()); return nbt; } @Override public void deserializeNBT(CompoundTag nbt) { getDensity().set(nbt.getInt("density")); } } public class TitanBloodDensity implements ITitanBloodHandler { private int bloodAmount = 0; @Override public int getAmount() { return bloodAmount; } @Override public void sub(int amount) { bloodAmount -= amount; } @Override public void add(int amount) { bloodAmount += amount; } @Override public void set(int value) { bloodAmount = value; } } @Mod.EventBusSubscriber(modid = MODID) public class ModEvent { [...] @SubscribeEvent public void onAttachChunkCapabilitiesChunk(AttachCapabilitiesEvent<LevelChunk> event) { if (!event.getObject().getCapability(TITAN_BLOOD_HANDLER).isPresent()) { event.addCapability(new ResourceLocation(MODID, "proprieties/blood_density"), new BloodDensityProvider()); } } [...] @SubscribeEvent public static void onRegisterCapabilities(RegisterCapabilitiesEvent event) { event.register(PlayerGCTXProvider.class); event.register(BloodDensityProvider.class); } [...] } public class SprayerBlockEntity extends FluidHandlerBlockEntity implements MenuProvider { [...] public boolean trySpray() { if (tank.getFluidAmount() >= BUCKET_VOLUME) { assert level != null; LazyOptional<TitanBloodDensity> capability = level.getChunkAt(getBlockPos()) .getCapability(TITAN_BLOOD_HANDLER); capability.ifPresent(handler -> { handler.add(100); tank.drain(BUCKET_VOLUME, IFluidHandler.FluidAction.EXECUTE); }); System.out.println(capability.isPresent()); // false return capability.isPresent(); } return false; } } I did the same method for the player and it worked, why doesn't it work with chunk?

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.