Jump to content

saving multiple values in 1 Capablity


Oscarita25

Recommended Posts

Basicly just as the title describes i want to save multiple values in 1 Capability.

i know i can do this with something like this in the Storage class:
 

	@Override
	public NBTBase writeNBT(Capability<IQuirk> capability, IQuirk instance, EnumFacing side) {
		NBTTagCompound tag = new NBTTagCompound();
		
		tag.setString("name", instance.getName());
		
		tag.setBoolean("activated", instance.getActivated());
		tag.setBoolean("available",instance.getAvailable());
		//Cooldown
		tag.setInteger("maxCooldown", instance.getMaxCooldown());
		tag.setInteger("cooldown", instance.getCooldown());
		
		//Activation Time
		tag.setInteger("maxAct", instance.getMaxActivatedTime());
		tag.setInteger("act", instance.getAct());
		
		//Quirk ID
		tag.setInteger("quirkid", instance.getQuirkID());
		
		return tag;
	}

	 
	@Override
	public void readNBT(Capability<IQuirk> capability, IQuirk instance, EnumFacing side, NBTBase nbt) {
		NBTTagCompound tag = (NBTTagCompound) nbt;
		
		tag.getBoolean("activated");
		tag.getBoolean("aviable");
		//Cooldown
		tag.getInteger("maxCooldown");
		tag.getInteger("cooldown");

		//Activation Time
		tag.getInteger("maxAct");
		tag.getInteger("act");
			
		//Quirk ID
		tag.getInteger("quirkid");
		}


But i ran into the problem with this that it saves to the Player... not on the world.
(as Example: i join world A with "xp" capablity set to 12 and log out join world B and still have the same amount!)
i AM using packets... so i dont know what i am doing wrong here..

thanks in advance

Link to comment
Share on other sites

Of course you "join world A" and then "join world B" won't carry a value with the player. They aren't the same player. It's the same player account, but World A and World B are two completely unrelated save files. Data does not carry over between them.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

okay sorry for the late reply, (had some school stuff to do)

basicly i only want to save those values on the player but they save on the account and i dont know why
till now my code is a BIG mess so its also very difficult to find the problem

i set it up like this:
in my OnPlayerJoin event

(0 is the default value)
a random "qurik" should be choosen (an ID between 1 and 2 till now) when it is 0...  but the ID is NOT 0 when i joined a world before i join another

 if i restart the game the value is 0 again...

If a Github Repository is prefered i would provide one (it will take some time because i am installing now a second OS on my pc)

Edited by Oscarita25
Link to comment
Share on other sites

3 hours ago, Oscarita25 said:

but they save on the account 

Capabilities are not set up to work this way. 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

@diesieben07 here is the full code: https://github.com/Oscarita25/QuickRepo

this is in my eventhandler:
 

	@SubscribeEvent
	public void onPlayerLoggedIn(PlayerLoggedInEvent event) {
		EntityPlayer player = event.player;
		//Sycronizing Capabilities
		ILevel level = player.getCapability(LevelProvider.LEVEL_CAP, null);
		IExp exp = player.getCapability(ExpProvider.EXP_CAP, null);
		INExp nexp = player.getCapability(NExpProvider.NEXP_CAP, null);
		IQuirk iquirk = player.getCapability(QuirkProvider.QUIRK_CAP, null);
		
		BNHA.NETWORK.sendTo(new MessageRequestLEVEL(), (EntityPlayerMP) player);
		BNHA.NETWORK.sendTo(new MessageRequestEXP(), (EntityPlayerMP) player);
		BNHA.NETWORK.sendTo(new MessageRequestNEXP(), (EntityPlayerMP) player);
		BNHA.NETWORK.sendTo(new MessageRequestQuirk(),(EntityPlayerMP) player);
		BNHA.NETWORK.sendToServer(new MessageLEVEL());
		BNHA.NETWORK.sendToServer(new MessageEXP());
		BNHA.NETWORK.sendToServer(new MessageNEXP());
		BNHA.NETWORK.sendToServer(new MessageQuirk());
		
		player.sendMessage(new TextComponentString("Your level is: " + level.getlvl()));
		player.sendMessage(new TextComponentString("Your exp is: " + exp.getexp()));
		player.sendMessage(new TextComponentString("Exp needed for the next level: " + (nexp.getnexp() - exp.getexp())));

		

		}

	
	
	@SubscribeEvent
	public void onPlayerClone(PlayerEvent.Clone event) {
		//copy's capabilities
		EntityPlayer player = event.getEntityPlayer();
		ILevel level = player.getCapability(LevelProvider.LEVEL_CAP, null);
		ILevel oldLevel = event.getOriginal().getCapability(LevelProvider.LEVEL_CAP, null);
		
		IExp exp = player.getCapability(ExpProvider.EXP_CAP, null);
		IExp oldExp = event.getOriginal().getCapability(ExpProvider.EXP_CAP, null);
		
		INExp nexp = player.getCapability(NExpProvider.NEXP_CAP, null);
		INExp oldNExp = event.getOriginal().getCapability(NExpProvider.NEXP_CAP, null);
		
		IQuirk cap = player.getCapability(QuirkProvider.QUIRK_CAP, null);
		IQuirk capold = event.getOriginal().getCapability(QuirkProvider.QUIRK_CAP, null);
		
		if(event.isWasDeath()) {
		cap.setMaxCooldown(capold.getMaxCooldown());
		cap.setMaxActivatedTime(capold.getMaxActivatedTime());
		cap.setCooldown(capold.getCooldown());
		cap.setAct(capold.getAct());
		cap.setActivated(capold.getActivated());
		cap.setAvailable(capold.getAvailable());
		cap.setQuirkID(capold.getQuirkID());
		level.setlvl(oldLevel.getlvl());
		exp.setexp(oldExp.getexp());
		nexp.setnexp(oldNExp.getnexp());
		
		BNHA.NETWORK.sendToServer(new MessageLEVEL());
		BNHA.NETWORK.sendToServer(new MessageEXP());
		BNHA.NETWORK.sendToServer(new MessageNEXP());
		BNHA.NETWORK.sendToServer(new MessageQuirk());
		BNHA.NETWORK.sendTo(new MessageRequestLEVEL(), (EntityPlayerMP) player);
		BNHA.NETWORK.sendTo(new MessageRequestEXP(), (EntityPlayerMP) player);
		BNHA.NETWORK.sendTo(new MessageRequestNEXP(), (EntityPlayerMP) player);
		BNHA.NETWORK.sendTo(new MessageRequestQuirk(),(EntityPlayerMP) player);
		}
	}
	
	
	@SubscribeEvent
	public void onPlayerTick(LivingUpdateEvent event) {
		//checking for level ups
		if (event.getEntity() instanceof EntityPlayer) {
		EntityPlayer player = (EntityPlayer) event.getEntity();
		IExp exp = player.getCapability(ExpProvider.EXP_CAP, null);
		INExp nexp = player.getCapability(NExpProvider.NEXP_CAP, null);
		ILevel level = player.getCapability(LevelProvider.LEVEL_CAP, null);
		IQuirk iquirk = player.getCapability(QuirkProvider.QUIRK_CAP, null);

		if (!player.world.isRemote) {
			//Random quirk choose
			Reference.RandomQuirkChoose(iquirk, player);
			
			if(exp.getexp() >= nexp.getnexp()) {
				level.setlvl(level.getlvl() + 1);
				BNHA.NETWORK.sendToServer(new MessageLEVEL());
				nexp.setnexp(nexp.getnexp()*(level.getlvl() ^ 1));
				BNHA.NETWORK.sendToServer(new MessageNEXP());
		        exp.setexp(0);
				BNHA.NETWORK.sendToServer(new MessageEXP());
				player.sendMessage(new TextComponentString("You reached Level " + level.getlvl()));
				}
			}else return;
		}
	}


in the on LivingUpdateEvent i put "Reference.RandomQuirkChoose(iquirk, player);"
in my Reference class it looks like this (dont know if its relevant)
 

	public static void RandomQuirkChoose(IQuirk iquirk,EntityPlayer player) {
		if(iquirk.getQuirkID() == Reference.none) {
			int random = Reference.RandomIntChoose();
			System.out.println(random + "Quirk NONE");
			iquirk.setQuirkID(random);
			BNHA.NETWORK.sendToServer(new MessageQuirk());
			
			if(iquirk.getQuirkID() == Reference.quirkless) {
				System.out.println(random + "Quirk QUIRKLESS");
				iquirk.setName("Quirkless");
				BNHA.NETWORK.sendToServer(new MessageQuirk());
				
			}else if(iquirk.getQuirkID() == Reference.explosionquirk) {
				System.out.println(random + "Quirk EXPLOSION");
				iquirk.setName("Explosion Quirk");
				BNHA.NETWORK.sendToServer(new MessageQuirk());
		}
			
			if(iquirk.getQuirkID() == Reference.quirkless) {
				player.sendMessage(new TextComponentString("You are " + iquirk.getName()));
			}else {
				player.sendMessage(new TextComponentString("Your Quirk is: " + iquirk.getName()));
				}
			}
	}

 

Link to comment
Share on other sites

On 1/23/2019 at 4:29 AM, Daeruin said:

You need to explain what you are trying to achieve. Do you want the value to follow the player from world to world? When do you want the value go up and down? Is this a characteristic of the player, or the world?

also i did overlook this one ... i am only trying that it doesn't follow the player from world to world,   I want to change the value when he has the default value, it is a capablitly attached to the player.

Link to comment
Share on other sites

2 hours ago, Oscarita25 said:

also i did overlook this one ... i am only trying that it doesn't follow the player from world to world,   I want to change the value when he has the default value, it is a capablitly attached to the player.

The game does not do this. You need to save your data somewhere else, manually.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

3 hours ago, diesieben07 said:

As for what Draco said: The behavior you described does not just appear. It has to be caused by something in your code. It's not that you have to do something for it to stop, you have to stop doing something for it to stop.

I think its behavior he doesn't have and wants. Not behavior that he has and doesn't want.

 

But either way, in order to change it, it has to be custom code.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

1 hour ago, Draco18s said:

I think its behavior he doesn't have and wants. Not behavior that he has and doesn't want.

 

But either way, in order to change it, it has to be custom code.

nope its just exactly as the @diesieben07 said. for the unecissary package "overload" its just trying around ... if you read my previous posts you will propably notice that i had absolutly no clue how packages work ... so i am gotta fix that now. also thanks for all the pointers of what is complete nonsense of what i wrote there.

Link to comment
Share on other sites

  • 2 weeks later...

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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