Jump to content

Recommended Posts

  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

Posted
  On 8/31/2016 at 3:04 PM, lukas2005 said:

is there a way to use NBTTag?

 

NBT should only be used to save data, it shouldn't be used to store it at runtime.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I believe you don't fully understand how data should be stored on players. Well - I might be wrong, but worth asking :)

 

Saving data to player data files is different from assigning data to player when he is online.

 

It would help us help you if you would describe your end goal and what you want to store.

  Quote

1.7.10 is no longer supported by forge, you are on your own.

Posted
  On 8/31/2016 at 4:28 PM, lukas2005 said:

i have a variable and i need to save it and i have no idea how to use capabilities

Read the docs

http://mcforge.readthedocs.io/en/latest/datastorage/capabilities/

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Do any of the existing capabilities (

IItemHandler

,

IFluidHandler

,

IAnimationStateMachine

) match the data you want to store?

 

If they do, use them. If they don't, create your own.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

few questions:

 

1.Where i shloud register my capabliity

2.i have an error when i am trying to register a capability

eclipse marks this with red line:

CapabilityManager.INSTANCE.register(PlayerDataCapabilityClass.PlayerDataCapability.class, PlayerDataCapabilityClass.PlayerDataCapabilityStorage.class, PlayerDataCapabilityClass.PlayerDataCapabilityFactory.class);

PlayerDataCapabilityClass.java:

public class PlayerDataCapabilityClass {

public interface PlayerDataCapability {



}

public static class PlayerDataCapabilityStorage implements Capability.IStorage<PlayerDataCapability> {

	  @Override
	  public NBTBase writeNBT(Capability<PlayerDataCapability> capability, PlayerDataCapability instance, EnumFacing side) {
		return null;
	    // return an NBT tag
	  }

		@Override
		public void readNBT(Capability<PlayerDataCapability> capability, PlayerDataCapability instance, EnumFacing side,
				NBTBase nbt) {
			// TODO Auto-generated method stub

		}

}

public static class PlayerDataCapabilityFactory implements Callable<PlayerDataCapability> {

	  @Override
	  public PlayerDataCapability call() throws Exception {
		  
	    return null;
	    
	  }
	  
}


}

 

Posted
  On 9/16/2016 at 1:22 PM, lukas2005 said:

few questions:

 

1.Where i shloud register my capabliity

2.i have an error when i am trying to register a capability

eclipse marks this with red line:

CapabilityManager.INSTANCE.register(PlayerDataCapabilityClass.PlayerDataCapability.class, PlayerDataCapabilityClass.PlayerDataCapabilityStorage.class, PlayerDataCapabilityClass.PlayerDataCapabilityFactory.class);

PlayerDataCapabilityClass.java:

public class PlayerDataCapabilityClass {

public interface PlayerDataCapability {



}

public static class PlayerDataCapabilityStorage implements Capability.IStorage<PlayerDataCapability> {

	  @Override
	  public NBTBase writeNBT(Capability<PlayerDataCapability> capability, PlayerDataCapability instance, EnumFacing side) {
		return null;
	    // return an NBT tag
	  }

		@Override
		public void readNBT(Capability<PlayerDataCapability> capability, PlayerDataCapability instance, EnumFacing side,
				NBTBase nbt) {
			// TODO Auto-generated method stub

		}

}

public static class PlayerDataCapabilityFactory implements Callable<PlayerDataCapability> {

	  @Override
	  public PlayerDataCapability call() throws Exception {
		  
	    return null;
	    
	  }
	  
}


}

Listen to eclipse it is probably an invalid arguement.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

It says

"The method register(Class<T>, Capability.IStorage<T>,Class<? extends T>) is not applicable for arguments(Class<PlayerDataCapabilityClass.PlayerDataCapability>,Class<PlayerDataCapabilityClass.PlayerDataCapabilityStorage>,Class<PlayerDataCapabilityClass.PlayerDataCapabilityFactory>)"

 

Posted
  On 9/16/2016 at 1:22 PM, lukas2005 said:

1.Where i shloud register my capabliity

Register it in preInit from your

@Mod

class or a class called from it.

 

 

  Quote

2.i have an error when i am trying to register a capability

There are two overloads of

CapabilityManager#registerCapability

that take a different third argument:

  • One takes the
    Class

    of the capability interface's default implementation

  • One takes an instance of
    Callable

    that returns an instance of the default implementation

 

You're trying to pass the

Class

of the

Callable

implementation, which is incorrect.

 

You haven't actually added any methods to your capability interface or implemented any of the methods in your

IStorage

and

Callable

implementations.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
  On 9/16/2016 at 10:22 PM, lukas2005 said:

So i need to pass a PlayerDataCapabilityClass.PlayerDataCapabilityFactory.this as a third argument?

 

No, you need to create an instance of

PlayerDataCapabilityClass.PlayerDataCapabilityFactory

and pass that as the third argument.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
  On 9/18/2016 at 10:37 AM, lukas2005 said:

ok i have created and registered capability but how do i use it?

 

Call

ICapabilityProvider#getCapability

to get the instance of your handler attached to the provider.

 

Every

Entity

(including

EntityPlayer

) is an

ICapabilityProvider

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
  On 9/18/2016 at 10:44 AM, Choonster said:

  Quote

ok i have created and registered capability but how do i use it?

 

Call

ICapabilityProvider#getCapability

to get the instance of your handler attached to the provider.

 

Every

Entity

(including

EntityPlayer

) is an

ICapabilityProvider

.

where i need to call this and how do i read/write the data?

Posted
  On 9/18/2016 at 10:54 AM, lukas2005 said:

where i need to call this and how do i read/write the data?

 

Call it whenever you want to access your handler instance (i.e. the instance of

PlayerDataCapability

). This handler instance stores the data, you need to create methods in your interface to interact with the data (read/write it).

 

The

ICapabilitySerializable

is responsible for reading the handler from and writing the handler to NBT.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
  On 9/18/2016 at 12:30 PM, lukas2005 said:

can you show me an example?

 

I linked several examples here.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

i have this code:

package pl.minepack.gym.capabilities;

import java.util.concurrent.Callable;

import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;

public class PlayerDataCapabilityClass {

public interface PlayerDataCapability {

	int Strength = 0;

	public int addStrength(int count);
	public int subStrength(int count);

	public void setStrength(int count);
	public int getStrength();

}

public static class PlayerDataCapabilityStorage implements Capability.IStorage<PlayerDataCapability> {

	  @Override
	  public NBTBase writeNBT(Capability<PlayerDataCapability> capability, PlayerDataCapability instance, EnumFacing side) {
		  NBTTagCompound nbt = new NBTTagCompound();
		  
		  nbt.setInteger("Strength", instance.getStrength());
		  
		  return nbt;
	  }

		@Override
		public void readNBT(Capability<PlayerDataCapability> capability, PlayerDataCapability instance, EnumFacing side,
				NBTBase nbt) {

			instance.setStrength(((NBTTagCompound)nbt).getInteger("Strength"));

		}

}

public static class PlayerDataCapabilityFactory implements PlayerDataCapability {

	private int Strength = 0;

	@Override
	public int addStrength(int count) {

		return this.Strength += count;
	}

	@Override
	public int subStrength(int count) {

		return this.Strength -= count;
	}

	@Override
	public void setStrength(int count) {

		this.Strength = count;

	}

	@Override
	public int getStrength() {
		// TODO Auto-generated method stub
		return this.Strength;
	}  
}


}

and what now?

Guest
This topic is now closed to further replies.

Announcements




  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello , when I try to launch the forge installer it just crash with a message for 0,5 secondes. I'm using java 17 to launch it. Here's the link of the error :https://cdn.corenexis.com/view/?img=d/ma24/qs7u4U.jpg  
    • You will find the crash-report or log in your minecraft directory (crash-report or logs folder)
    • Use a modpack which is using these 2 mods as working base:   https://www.curseforge.com/minecraft/modpacks/life-in-the-village-3
    • inicie un mundo donde instale Croptopia y Farmer's Delight, entonces instale el addon Croptopia Delight pero no funciona. es la version 1.18.2
    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
  • Topics

×
×
  • Create New...

Important Information

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