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.

Featured Replies

Posted

Hi, I'm trying to save some additional data to chunks, and have figured out that Capabilities are probably the way to go. After looking around the internet for a bit I think I got the gist and I set to coding. However, the AttachCapabilitiesEvent#addCapability() method seems to require an ICapabilityProvider, which I don't remember seeing anything on. Here's what I've got so far:

 

IRift class:

public interface IRift {
	boolean isRift();
	float getRiftActivityPercent();
	void setRiftActivityPercent(float riftActivityPercent);
	void makeRift();
	void closeRift();
	void riftEvent();
}

 

RiftStorage class:

public class RiftStorage implements Capability.IStorage<IRift> {

	@Override
	public INBT writeNBT(Capability<IRift> capability, IRift instance, Direction side) {
		CompoundNBT nbt = new CompoundNBT();
		
		if(instance.isRift()) {
			nbt.putBoolean("isRift", instance.isRift());
			nbt.putFloat("riftActivityPercent", instance.getRiftActivityPercent());
		}
		
		return nbt;
	}

	@Override
	public void readNBT(Capability<IRift> capability, IRift instance, Direction side, INBT nbt) {
		CompoundNBT cnbt = ((CompoundNBT)nbt);
		
		if(cnbt.getBoolean("isRift")) {
			instance.makeRift();
			instance.setRiftActivityPercent(cnbt.getFloat("riftActivityPercent"));
		}
	}
}

 

RiftCapability class:

public class RiftCapability implements IRift {
	
	private boolean isRift = false;
	private float riftActivityPercent = 0.0f;

	@Override
	public boolean isRift() {
		return isRift;
	}

	@Override
	public float getRiftActivityPercent() {
		return riftActivityPercent;
	}

	@Override
	public void setRiftActivityPercent(float riftActivityPercent) {
		if(riftActivityPercent < 0 || riftActivityPercent > 1) throw new IndexOutOfBoundsException("Rift Activity Percent cannot be less than 0 or greater than 1!");
		else this.riftActivityPercent = riftActivityPercent;
	}

	@Override
	public void makeRift() {
		this.isRift = true;
	}

	@Override
	public void closeRift() {
		this.isRift = false;
	}

	@Override
	public void riftEvent() {
		//TODO: Fire a rift event.
	}
}

 

Advice much appreciated. Thanks :)

Edited by BlockyPenguin

Today (22/10/20) I reached 100 posts!

I'm probably more excited than I should be for something so realistically minor...

  • Author

I got it working! Thank you :)

 

Today (22/10/20) I reached 100 posts!

I'm probably more excited than I should be for something so realistically minor...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

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.