Everything posted by ocome
- 
	
		
		[1.18]How to add PlayerData
		
		My idea is to get the vanilla player, call Capability when the vanilla START is obtained, and then call tick from Interface.... However, from your answer, it seems that it is not. It's hard to .... I want to understand I did not know what parameters were available. I'm sure there is a way to find out from somewhere, but do you know of one? implementation public void tick() { if (!this.level.isClientSide) { this.manaData.tick(player); } } net.minecraftforge.event.ForgeEventFactory.onPlayerPreTick(player); need equivalent of this code? Manadata public void tick(Player p_38711_) { Difficulty difficulty = p_38711_.level.getDifficulty(); this.lastManaLevel = this.manaLevel; if (this.exhaustionLevel > 4.0F) { this.exhaustionLevel -= 4.0F; if (this.saturationLevel > 0.0F) { this.saturationLevel = Math.max(this.saturationLevel - 1.0F, 0.0F); } else if (difficulty != Difficulty.PEACEFUL) { this.manaLevel = Math.max(this.manaLevel - 1, 0); } } boolean flag = p_38711_.level.getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION); if (flag && this.saturationLevel > 0.0F && p_38711_.isHurt() && this.manaLevel >= 20) { ++this.tickTimer; if (this.tickTimer >= 10) { float f = Math.min(this.saturationLevel, 6.0F); p_38711_.heal(f / 6.0F); this.addExhaustion(f); this.tickTimer = 0; } } else if (flag && this.manaLevel >= 18 && p_38711_.isHurt()) { ++this.tickTimer; if (this.tickTimer >= 80) { p_38711_.heal(1.0F); this.addExhaustion(6.0F); this.tickTimer = 0; } } else if (this.manaLevel <= 0) { ++this.tickTimer; if (this.tickTimer >= 80) { if (p_38711_.getHealth() > 10.0F || difficulty == Difficulty.HARD || p_38711_.getHealth() > 1.0F && difficulty == Difficulty.NORMAL) { p_38711_.hurt(DamageSource.STARVE, 1.0F); } this.tickTimer = 0; } } else { this.tickTimer = 0; } }
 - 
	
		
		[1.18]How to add PlayerData
		
		I thought I needed to call capability, so I used getinstance to get it.
 - 
	
		
		[1.18]How to add PlayerData
		
		I thought if I used this it would return true for Player.END Okay, I'll think about it some more.
 - 
	
		
		[1.18]How to add PlayerData
		
		@SubscribeEvent public void onPlayerPreTick(final AttachCapabilitiesEvent<Entity> event){ Player player =Minecraft.getInstance().player; boolean playercheck = MinecraftForge.EVENT_BUS.post(new TickEvent.PlayerTickEvent(TickEvent.Phase.START, player)); if(playercheck ==true) { Minecraft minecraft = Minecraft.getInstance(); LazyOptional<MyCapabilityInterface> stats1 = minecraft.player.getCapability(MyCapability.INSTANCE); MyCapabilityInterface myCapabilityInterface = stats1.orElseThrow(IllegalStateException::new); myCapabilityInterface.tick(); } } Is this wrong? player is being called, but all return false
 - 
	
		
		[1.18]How to add PlayerData
		
		I want to implement something that automatically decreases like the hunger value. (Ideally, something that increases since it is mana)
 - 
	
		
		[1.18]How to add PlayerData
		
		Oh, I left out an explanation. I think I need a method that runs all the time, but in the above location, it is only called at startup. I'd like to get some hints on where to call it.
 - 
	
		
		[1.18]How to add PlayerData
		
		public class MyCapabilityImplementation implements MyCapabilityInterface { protected ManaData manaData = new ManaData(); private static final String NBT_KEY_DAMAGE_DEALT = "damageDealt"; public final Player player ; public final Level level ; private String Value = ""; public MyCapabilityImplementation(Player eventObject) { player=eventObject; level = eventObject.getLevel(); } public MyCapabilityImplementation() { player = null; level = null; } It works and no special errors occur anymore I added it to the previous section thinking it should be executed at Player runtime, but it was only executed at the start.
 - 
	
		
		[1.18]How to add PlayerData
		
		MyCapabilityAttacher Player eventObject = (Player) event.getObject(); final MyCapabilityProviderEntity provider = new MyCapabilityProviderEntity(eventObject); event.addCapability(MyCapabilityProviderEntity.IDENTIFIER, provider); public MyCapabilityProviderEntity(Player eventObject) { new MyCapabilityImplementation(eventObject); } MyCapabilityImplementation public class MyCapabilityImplementation implements MyCapabilityInterface { protected ManaData manaData = new ManaData(); private static final String NBT_KEY_DAMAGE_DEALT = "damageDealt"; public Player player ; public Level level; private String Value = ""; public MyCapabilityImplementation(Player eventObject) { player=eventObject; } Is this correct? I tried to make it as described, but it may not have come across correctly.
 - 
	
		
		[1.18]How to add PlayerData
		
		LazyOptional<MyCapabilityInterface> stats1 = minecraft.player.getCapability(MyCapability.INSTANCE); MyCapabilityInterface myCapabilityInterface=stats1.orElseThrow(IllegalStateException::new); ManaData manaData= myCapabilityInterface.getManaData(); int level =manaData.getManaLevel(); implemented. No errors are seen. public MyCapabilityProviderEntity(Player eventObject) { new MyCapabilityImplementation(eventObject) ; } public void onAttachingCapabilitiesEntity(final AttachCapabilitiesEvent<Entity> event) { boolean iof = event.getObject() instanceof Player; if (iof ==true) { Player eventObject = (Player) event.getObject(); final MyCapabilityProviderEntity provider = new MyCapabilityProviderEntity(eventObject); event.addCapability(MyCapabilityProviderEntity.IDENTIFIER, provider); } } MyCapabilityImplementation public class MyCapabilityImplementation implements MyCapabilityInterface { protected ManaData manaData = new ManaData(); private static final String NBT_KEY_DAMAGE_DEALT = "damageDealt"; public Player player ; public Level level; private String Value = ""; public Minecraft minecraft; public MyCapabilityImplementation() { } public MyCapabilityImplementation(Player object) { player=object; } @Override public ManaData getManaData() { return this.manaData; } Is this what it means to create in the player? Honestly, I'm not sure I'm getting it right due to the way the meaning is conveyed and my lack of knowledge
 - 
	
		
		[1.18]How to add PlayerData
		
		Attach public class MyCapabilityAttacher { public class MyCapabilityProviderEntity implements ICapabilityProvider, INBTSerializable<CompoundTag> { public static final ResourceLocation IDENTIFIER = new ResourceLocation(ExampleMod.MOD_ID, "tutorial"); private final MyCapabilityInterface backend = new MyCapabilityImplementation() ; private final LazyOptional<MyCapabilityInterface> optionalData = LazyOptional.of(() -> backend); @NotNull @Override public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { return MyCapability.INSTANCE.orEmpty(cap, this.optionalData); } void invalidate() { this.optionalData.invalidate(); } @Override public CompoundTag serializeNBT() { return this.backend.serializeNBT(); } @Override public void deserializeNBT(CompoundTag nbt) { this.backend.deserializeNBT(nbt); } } @SubscribeEvent public void onAttachingCapabilitiesEntity(final AttachCapabilitiesEvent<Entity> event) { final MyCapabilityProviderEntity provider = new MyCapabilityProviderEntity(); boolean iof = event.getObject() instanceof Player; if (iof ==true) { Player eventObject = (Player) event.getObject(); event.addCapability(MyCapabilityProviderEntity.IDENTIFIER, provider); new MyCapabilityImplementation().tick(eventObject); } } public MyCapabilityAttacher() { } } Implementation public class MyCapabilityImplementation implements MyCapabilityInterface { protected ManaData manaData = new ManaData(); private static final String NBT_KEY_DAMAGE_DEALT = "damageDealt"; public Level level; private String Value = ""; public ManaData getManaData() { return this.manaData; } @Override public MyCapabilityInterface tick(Player player) { this.manaData.tick(player); return null; } ..... I think it is close to completion. I thought I needed a tick, so I implemented it, but it comes up as an invalid player. Is there a way to fix this?
 - 
	
		
		[1.18]How to add PlayerData
		
		FoodData statsas = minecraft.player.getFoodData(); ManaData statsa1s = MyCapabilityImplementation.getManaData(); int level =statsas.getFoodLevel(); By the way, if this is a java thing, I hope you don't mind, but why do I get a static context error with getManaData while no error occurs with getFoodData? This error requires a lot of time and effort to fix. Or is there no need to write this kind of code in the first place? --> This problem was solved by my mistake.
 - 
	
		
		[1.18]How to add PlayerData
		
		Yes, I understand that. But I don't know how to utilize this. Do I have to get the values related to Manadata from stats?
 - 
	
		
		[1.18]How to add PlayerData
		
		LazyOptional<MyCapabilityInterface> stats = minecraft.player.getCapability(MyCapability.INSTANCE); int level = ManaData.getManaLevel(); Is this what it looks like? To be honest, I don't really understand it. I feel like I don't have enough skills yet. I'm still going to continue creating it, but I'm thinking I should understand it a little better before I start working on it.
 - 
	
		
		[1.18]How to add PlayerData
		
		public class MyCapabilityAttacher { private class MyCapabilityProviderEntity implements ICapabilityProvider, INBTSerializable<CompoundTag> { public static final ResourceLocation IDENTIFIER = new ResourceLocation(ExampleMod.MOD_ID, "tutorial"); private final MyCapabilityInterface backend = new MyCapabilityImplementation(); private final LazyOptional<MyCapabilityInterface> optionalData = LazyOptional.of(() -> backend); public class MyCapabilityImplementation implements MyCapabilityInterface { protected ManaData manaData = new ManaData(); private static final String NBT_KEY_DAMAGE_DEALT = "damageDealt"; public Level level; private String Value = ""; public static ManaData getManaData() { return new ManaData(); } @Override public void tick() { if (!this.level.isClientSide) { this.manaData.tick(this); } } ManaOverlay public static final ManaOverlay INSTANCE = new ManaOverlay(Minecraft.getInstance()); public ManaOverlay(Minecraft p_93005_) { super(p_93005_); this.mc = Minecraft.getInstance(); this.font = mc.font; OverlayRegistry.registerOverlayTop("Mana ", (gui, mStack, partialTicks, screenWidth, screenHeight) -> { boolean isMounted = gui.minecraft.player.getVehicle() instanceof LivingEntity; if (!isMounted && !gui.minecraft.options.hideGui && gui.shouldDrawSurvivalElements()) { setupOverlayRenderState(true, false); renderMana(screenWidth, screenHeight, mStack); } }); } public static void init() { MinecraftForge.EVENT_BUS.register(INSTANCE); } public void renderMana(int width, int height, PoseStack mStack) { minecraft.getProfiler().push("mana"); Player player = (Player)this.minecraft.getCameraEntity(); RenderSystem.enableBlend(); int left = width / 2 + 91; int top = height - right_height ; boolean unused = false; ManaData stats = MyCapabilityImplementation.getManaData(); int level = stats.getManaLevel(); for (int i = 0; i < 10; ++i) { int idx = i * 2 + 1; int x = left - i * 8 - 9; int y = top; int icon = 16; byte background = 0; if (minecraft.player.hasEffect(MobEffects.HUNGER)) { icon += 36; background = 13; } if (unused) background = 1; //Probably should be a += 1 but vanilla never uses this blit(mStack, x, y, 16 + background * 9, 27, 9, 9); if (idx < level) blit(mStack, x, y, icon + 9, 27, 9, 9); else if (idx == level) blit(mStack, x, y, icon + 18, 27, 9, 9); } RenderSystem.disableBlend(); minecraft.getProfiler().pop(); } I created it this way, but there is no change in the overlay. I think the tick is not being called, but before that, I can't seem to fix the static mismatch between Capability and overlay. Is there a way to fix this? No, something wrong with the way I make the overlay side ? I'll look at it some more.
 - 
	
		
		[1.18]How to add PlayerData
		
		Extends to mimic the player's Fooddata, but not necessary? I'll check it out.
 - 
	
		
		[1.18]How to add PlayerData
		
		@SubscribeEvent public static void onAttachingCapabilities(final AttachCapabilitiesEvent<Entity> event) { final MyCapabilityProvider provider = new MyCapabilityProvider(); boolean iof = event.getObject() instanceof Player; if (iof ==true) { event.addCapability(MyCapabilityProvider.IDENTIFIER, provider); } } We have implemented it this way. I think works fine in tests. MyCapabilityProvider private static class MyCapabilityProvider implements ICapabilityProvider, INBTSerializable<CompoundTag> { public static final ResourceLocation IDENTIFIER = new ResourceLocation(ExampleMod.MOD_ID, "tutorial"); public Player player ; public Level level = player.getCommandSenderWorld(); public BlockPos blockPos = player.blockPosition(); public GameProfile gameProfile =player.getGameProfile(); private final MyCapabilityInterface backend = new MyCapabilityImplementation(level,blockPos,0.0F, gameProfile); MyCapabilityImplementation public class MyCapabilityImplementation extends Player implements MyCapabilityInterface { protected ManaData manaData = new ManaData(); private static final String NBT_KEY_DAMAGE_DEALT = "damageDealt"; private String Value = ""; public MyCapabilityImplementation(Level p_36114_, BlockPos p_36115_, float p_36116_, GameProfile p_36117_) { super(p_36114_, p_36115_, p_36116_, p_36117_); } I think I understand what I can get. But I don't know where to get the Player itself.
 - 
	
		
		[1.18]How to add PlayerData
		
		I appreciate again . @SubscribeEvent public static void onAttachingCapabilities(final AttachCapabilitiesEvent<Entity> event) { final MyCapabilityProvider provider = new MyCapabilityProvider(); String string = event.getObject().getType().toShortString(); if (string == "player") { event.addCapability(MyCapabilityProvider.IDENTIFIER, provider); } } I filled it out like this from the answer, but it doesn't seem to work I tried to check it after getting the player element from AttachCapabilitiesEvent<Entity>. Am I wrong? public static void onAttachingCapabilities(final AttachCapabilitiesEvent<Player> event) { final MyCapabilityProvider provider = new MyCapabilityProvider(); Reading the documentation, you can't do this, right? Oh, sure, I checked the Player and it's there. So does that mean I can use AT to get it Thank you very much.
 - 
	
		
		[1.18]How to add PlayerData
		
		I'm trying to add some functionality to the Player. private static class MyCapabilityProvider implements ICapabilityProvider, INBTSerializable<CompoundTag> { public static final ResourceLocation IDENTIFIER = new ResourceLocation(ExampleMod.MOD_ID, "tutorial"); Level level = Minecraft.getInstance().level; private final MyCapabilityInterface backend = new MyCapabilityImplementation(level,BlockPos.ZERO,0,new GameProfile(null,null)); private final LazyOptional<MyCapabilityInterface> optionalData = LazyOptional.of(() -> backend); @NotNull ......... Is this how the call should be made? public class MyCapabilityImplementation extends Player implements MyCapabilityInterface { private static final String NBT_KEY_DAMAGE_DEALT = "damageDealt"; private String Value = ""; public MyCapabilityImplementation(Level p_36114_, BlockPos p_36115_, float p_36116_, GameProfile p_36117_) { super(p_36114_, p_36115_, p_36116_, p_36117_); } @Override public String getValue() { return this.Value; } ....... @Override public void setValue(String Value) { this.Value = Value; } And fill in the code to be added from here? I wonder how to get a gameplofile...
 - 
	
		
		[1.18]How to add PlayerData
		
		Oh, I think my English is wrong again. Mx Luis taught me what I needed to know? I think it is enough. sorry. I'll study English. Back to the topic at hand, after writing the code to implement the mana. If you change it to only call it if the Entity is a player, I think it will work Thank you, all of you. I'll try.
 - 
	
		
		[1.18]How to add PlayerData
		
		uhh... Mycapabilityattacher has MyCapabilityProvider and implements ICapabilityProvide, which I thought was sufficient, but I guess not. I'll check again. public class MyCapabilityAttacher { private static class MyCapabilityProvider implements ICapabilityProvider, INBTSerializable<CompoundTag> { public static final ResourceLocation IDENTIFIER = new ResourceLocation(ExampleMod.MOD_ID, "tutorial"); private final MyCapabilityInterface backend = new MyCapabilityImplementation(); private final LazyOptional<MyCapabilityInterface> optionalData = LazyOptional.of(() -> backend); @NotNull @Override public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { return MyCapability.INSTANCE.orEmpty(cap, this.optionalData); } void invalidate() { this.optionalData.invalidate(); } @Override public CompoundTag serializeNBT() { return this.backend.serializeNBT(); } @Override public void deserializeNBT(CompoundTag nbt) { this.backend.deserializeNBT(nbt); } } ...
 - 
	
		
		[1.18]How to add PlayerData
		
		I have read the documentation and run the example once, but attach is not executed. When the subscribed Entity is called, attach is called, and then MyCapabilityImplementation is called. fill in the code in the place corresponding to MyCapabilityImplementation. This is how I understand it, am I wrong And I'm not sure what the need for the ResourceLocation string is. It says there are no restrictions, so does that mean it is an ID for identification purposes? Main public void registerCapabilities(RegisterCapabilitiesEvent event) { MyCapability.register(event); } The problem with not running has been resolved. I had misinterpreted it. MinecraftForge.EVENT_BUS.register(MyCapabilityAttacher.class); So the only thing I'm concerned about is the correctness of future development procedures.
 - 
	
		
		[1.18]How to add PlayerData
		
		Maybe I'm not communicating correctly because my English is not good enough. https://mcforge.readthedocs.io/en/1.18.x/ I was just looking at this place. But your LINK is more detailed, which means it was helpful. I'm checking the examples now. Thank you.
 - 
	
		
		[1.18]How to add PlayerData
		
		Thank you . I've read the forge documentation. however I couldn't read and understand the documentation, so that helps
 - 
	
		
		[1.18]How to add PlayerData
		
		Oh, I just found a similar question. I'll check it out.
 - 
	
		
		[1.18]How to add PlayerData
		
		I am trying to implement Mana. If I can add it to the Player after creating the Manadata, I think I can create it Is there a way to solve this or a class I can refer to?
 
IPS spam blocked by CleanTalk.