Jump to content

[1.15] performEffect does not work


Zemelua

Recommended Posts

public class ModEffect extends Effect {

	protected ModEffect(EffectType typeIn, int liquidColorIn) {
		super(typeIn, liquidColorIn);
	}

	@Override
	public void performEffect(LivingEntity entityLivingBaseIn, int amplifier) {
		if (this == DepressionModRegistry.INSTANT_ANTIDEPRESSANT.get()) {
			LazyOptional<PlayerMentalInterface> cap = ((PlayerEntity)entityLivingBaseIn).getCapability(PlayerMentalCapabilityRegistry.PLAYER_MENTAL_CAPABILITY);
			int currentMental = 0;
			try {
				currentMental = cap.orElseThrow(IllegalAccessException::new).getMental();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
			int _currentMental = currentMental + 3;
			if (_currentMental > 20) {
				_currentMental = 20;
			}
			try {
				cap.orElseThrow(IllegalAccessException::new).setMental(_currentMental);
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
	}
}
public class DepressionModRegistry {

		//EffectRegistry
		public static final DeferredRegister<Effect> EFFECTS = DeferredRegister.create(ForgeRegistries.POTIONS, DepressionMod.MOD_ID);

		public static final RegistryObject<Effect> INSTANT_ANTIDEPRESSANT = EFFECTS.register("instant_antidepressant", () -> new InstantEffect(EffectType.BENEFICIAL, 123456));

		//PotionRegistry
		public static final DeferredRegister<Potion> POTIONS = DeferredRegister.create(ForgeRegistries.POTION_TYPES, DepressionMod.MOD_ID);

		public static final RegistryObject<Potion> BRON = POTIONS.register("bron", () -> new Potion(new EffectInstance(Effects.LEVITATION, 120), new EffectInstance(Effects.JUMP_BOOST, 3600, 2), new EffectInstance(Effects.SLOW_FALLING, 3600), new EffectInstance(INSTANT_ANTIDEPRESSANT.get(), 1)));

		//RecipeRegistry
		public static void addRecipes() {
			BrewingRecipeRegistry.addRecipe(new PotionRecipe(Lazy.concurrentOf(() -> Potions.AWKWARD), Ingredient.fromItems(Items.SUNFLOWER), Lazy.concurrentOf(() -> BRON.get())));
		}
	}

In the code above, I've succeeded in implementing potions and effects, but I can't get the effect's effect to work. Specifically, it increases the capacity value by a certain amount, similar to instant health. It has also been confirmed that the capabilities are properly implemented. It just seems to me that performEffect isn't working.

Link to comment
Share on other sites

public class ModEffect extends InstantEffect {

	protected ModEffect(EffectType typeIn, int liquidColorIn) {
		super(typeIn, liquidColorIn);
	}

	@Override
	public void affectEntity(@Nullable Entity source, @Nullable Entity indirectSource, LivingEntity entityLivingBaseIn, int amplifier, double health) {
		if (this == DepressionModRegistry.INSTANT_ANTIDEPRESSANT.get()) {
			this.performEffect(entityLivingBaseIn, amplifier);
		}
	}
	
	@Override
	public void performEffect(LivingEntity entityLivingBaseIn, int amplifier) {
		if (this == DepressionModRegistry.INSTANT_ANTIDEPRESSANT.get()) {
			LazyOptional<PlayerMentalInterface> cap = ((PlayerEntity)entityLivingBaseIn).getCapability(PlayerMentalCapabilityRegistry.PLAYER_MENTAL_CAPABILITY);
			int currentMental = 0;
			try {
				currentMental = cap.orElseThrow(IllegalAccessException::new).getMental();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
			int _currentMental = currentMental + 3;
			if (_currentMental > 20) {
				_currentMental = 20;
			}
			try {
				cap.orElseThrow(IllegalAccessException::new).setMental(_currentMental);
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
	}
}

I extended InstantEffect and override affectEntity, but it's still not working.

Link to comment
Share on other sites

public class ModEffect extends InstantEffect {

	public ModEffect(EffectType typeIn, int liquidColorIn) {
		super(typeIn, liquidColorIn);
	}

	@Override
	public void performEffect(LivingEntity entityLivingBaseIn, int amplifier) {
		if (entityLivingBaseIn instanceof PlayerEntity) {
			LazyOptional<PlayerMentalInterface> cap = ((PlayerEntity)entityLivingBaseIn).getCapability(PlayerMentalCapabilityRegistry.PLAYER_MENTAL_CAPABILITY);
			int currentMental = cap.ifPresent(f -> f.getMental());  //<-here
			int _currentMental = currentMental + 3;
		//if (_currentMental > 20) {
		//	_currentMental = 20;
		//}
			cap.ifPresent(f -> f.setMental(_currentMental));
		}
	}

	@Override
	public void affectEntity(@Nullable Entity source, @Nullable Entity indirectSource, LivingEntity entityLivingBaseIn, int amplifier, double health) {
		this.performEffect(entityLivingBaseIn, amplifier);
	}
}

I've improved the code, but I don't know how to use ifPresent with getMental ().

The code can be found at https://github.com/Zemelua/Depression-Mod . I haven't updated it yet, but I have a complete implementation of capability.

Edited by Zemelua
Link to comment
Share on other sites

1 hour ago, Zemelua said:

I've improved the code, but I don't know how to use ifPresent with getMental ().

Of course that won't work, since ifPresent() returns void. Why not put all code that needs access to your capability in the consumer in ifPresent()?

 

Basic Java stuff like this is best to know before going into modding, which is why I would strongly encourage you to take a few weeks off modding and take that time to learn the basics of Java. 

Link to comment
Share on other sites

I'm sorry. Since I am learning java in parallel with modding (such as learning java code that got stuck in modding at that time), I am aware that there is a part that is not learned enough. This time, I asked a question because I misunderstood that the cause was not in java. I'm sorry.

	@Override
	public void performEffect(LivingEntity entityLivingBaseIn, int amplifier) {
		if (entityLivingBaseIn instanceof PlayerEntity) {
			System.out.print("test");
			LazyOptional<PlayerMentalInterface> cap = ((PlayerEntity)entityLivingBaseIn).getCapability(PlayerMentalCapabilityRegistry.PLAYER_MENTAL_CAPABILITY);
			cap.ifPresent(f ->
				f.setMental(f.getMental() + 3)
			);

Well, I've fixed the code and I think this is the correct java code, but it doesn't work. Is this also a java issue?

Edited by Zemelua
Link to comment
Share on other sites

You haven't answered either of my two questions. How are you viewing the data? If you're grabbing it from the logical server, it will be present. However, the logical client would need to have the information synced across the two threads.

 

You also only attach the capability on the client player meaning that it will never be stored or found on the server. This means that nothing in your above code will work.

Link to comment
Share on other sites

I'm sorry. I forgot to answer. The data is displayed as a HUD in the client / gui / MentalOverlayHandler. (This has already been successful.) The current ultimate goal is to increase the value of capacity by drinking potions, and reflect that in the HUD. The code doesn't reflect the potion and effect code yet, but it's here. https://github.com/Zemelua/Depression-Mod

Link to comment
Share on other sites

1 hour ago, ChampionAsh5357 said:

You also only attach the capability on the client player meaning that it will never be stored or found on the server. This means that nothing in your above code will work.

Along with what I already mentioned, you need to sync the data to the logical client with a packet whenever the value changes.

Link to comment
Share on other sites

	@Override
	public void performEffect(LivingEntity entityLivingBaseIn, int amplifier) {
		if (entityLivingBaseIn instanceof PlayerEntity) {
			System.out.print("test");
			LazyOptional<PlayerMentalInterface> cap = ((PlayerEntity)entityLivingBaseIn).getCapability(PlayerMentalCapabilityRegistry.PLAYER_MENTAL_CAPABILITY);
			cap.ifPresent(f -> {
				int _currentMental = f.getMental() + 3;
				f.setMental(_currentMental);
				DepressionModPacketHandler.sendToClient(new PlayerMentalCapabilityMessage(_currentMental), (PlayerEntity) entityLivingBaseIn);
			});
		}
	}

I've improved the code, but it crashed when I drank a potion. I don't know the cause, so can you tell me? The crash report is below.

 

 

---- Minecraft Crash Report ----
// Shall we play a game?

Time: 20/10/26 3:40
Description: Ticking player

java.lang.ClassCastException: net.minecraftforge.common.util.LazyOptional cannot be cast to depression_mod.capability.mentalpoint.PlayerMentalInterface
    at depression_mod.network.PlayerMentalCapabilityMessage.<init>(PlayerMentalCapabilityMessage.java:19) ~[?:?] {re:classloading}
    at depression_mod.potion.ModEffect.lambda$0(ModEffect.java:30) ~[?:?] {re:classloading}
    at net.minecraftforge.common.util.LazyOptional.ifPresent(LazyOptional.java:161) ~[?:?] {re:classloading}
    at depression_mod.potion.ModEffect.performEffect(ModEffect.java:27) ~[?:?] {re:classloading}
    at depression_mod.potion.ModEffect.affectEntity(ModEffect.java:37) ~[?:?] {re:classloading}
    at net.minecraft.item.PotionItem.onItemUseFinish(PotionItem.java:47) ~[?:?] {re:classloading}
    at net.minecraft.item.ItemStack.onItemUseFinish(ItemStack.java:213) ~[?:?] {re:classloading}
    at net.minecraft.entity.LivingEntity.onItemUseFinish(LivingEntity.java:2876) ~[?:?] {re:classloading}
    at net.minecraft.entity.player.ServerPlayerEntity.onItemUseFinish(ServerPlayerEntity.java:1027) ~[?:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.entity.LivingEntity.updateActiveHand(LivingEntity.java:2754) ~[?:?] {re:classloading}
    at net.minecraft.entity.LivingEntity.tick(LivingEntity.java:2185) ~[?:?] {re:classloading}
    at net.minecraft.entity.player.PlayerEntity.tick(PlayerEntity.java:237) ~[?:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.entity.player.ServerPlayerEntity.playerTick(ServerPlayerEntity.java:379) ~[?:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.network.play.ServerPlayNetHandler.tick(ServerPlayNetHandler.java:188) ~[?:?] {re:classloading}
    at net.minecraft.network.NetworkManager.tick(NetworkManager.java:250) ~[?:?] {re:classloading}
    at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:152) ~[?:?] {re:classloading}
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:903) ~[?:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:821) ~[?:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120) ~[?:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:662) [?:?] {re:classloading,pl:accesstransformer:B}
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_261] {}


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Server thread
Stacktrace:
    at depression_mod.network.PlayerMentalCapabilityMessage.<init>(PlayerMentalCapabilityMessage.java:19)
    at depression_mod.potion.ModEffect.lambda$0(ModEffect.java:30)
    at net.minecraftforge.common.util.LazyOptional.ifPresent(LazyOptional.java:161)
    at depression_mod.potion.ModEffect.performEffect(ModEffect.java:27)
    at depression_mod.potion.ModEffect.affectEntity(ModEffect.java:37)
    at net.minecraft.item.PotionItem.onItemUseFinish(PotionItem.java:47)
    at net.minecraft.item.ItemStack.onItemUseFinish(ItemStack.java:213)
    at net.minecraft.entity.LivingEntity.onItemUseFinish(LivingEntity.java:2876)
    at net.minecraft.entity.player.ServerPlayerEntity.onItemUseFinish(ServerPlayerEntity.java:1027)
    at net.minecraft.entity.LivingEntity.updateActiveHand(LivingEntity.java:2754)
    at net.minecraft.entity.LivingEntity.tick(LivingEntity.java:2185)
    at net.minecraft.entity.player.PlayerEntity.tick(PlayerEntity.java:237)

-- Player being ticked --
Details:
    Entity Type: minecraft:player (net.minecraft.entity.player.ServerPlayerEntity)
    Entity ID: 135
    Entity Name: Dev
    Entity's Exact location: -140.31, 70.20, -6.46
    Entity's Block location: World: (-141,70,-7), Chunk: (at 3,4,9 in -9,-1; contains blocks -144,0,-16 to -129,255,-1), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1)
    Entity's Momentum: 0.00, 0.01, 0.00
    Entity's Passengers: []
    Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
    at net.minecraft.entity.player.ServerPlayerEntity.playerTick(ServerPlayerEntity.java:379)
    at net.minecraft.network.play.ServerPlayNetHandler.tick(ServerPlayNetHandler.java:188)
    at net.minecraft.network.NetworkManager.tick(NetworkManager.java:250)

-- Ticking connection --
Details:
    Connection: net.minecraft.network.NetworkManager@3bcb3751
Stacktrace:
    at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:152)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:903)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:821)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:662)
    at java.lang.Thread.run(Thread.java:748)

-- System Details --
Details:
    Minecraft Version: 1.15.2
    Minecraft Version ID: 1.15.2
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_261, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 532880904 bytes (508 MB) / 1263534080 bytes (1205 MB) up to 1873805312 bytes (1787 MB)
    CPUs: 12
    JVM Flags: 1 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump
    ModLauncher: 5.1.2+70+master.2845bb9
    ModLauncher launch target: fmluserdevclient
    ModLauncher naming: mcp
    ModLauncher services: 
        /eventbus-2.2.0-service.jar eventbus PLUGINSERVICE 
        /forge-1.15.2-31.2.41_mapped_snapshot_20200514-1.15.1-launcher.jar object_holder_definalize PLUGINSERVICE 
        /forge-1.15.2-31.2.41_mapped_snapshot_20200514-1.15.1-launcher.jar runtime_enum_extender PLUGINSERVICE 
        /accesstransformers-2.1.3-shadowed.jar accesstransformer PLUGINSERVICE 
        /forge-1.15.2-31.2.41_mapped_snapshot_20200514-1.15.1-launcher.jar capability_inject_definalize PLUGINSERVICE 
        /forge-1.15.2-31.2.41_mapped_snapshot_20200514-1.15.1-launcher.jar runtimedistcleaner PLUGINSERVICE 
        /forge-1.15.2-31.2.41_mapped_snapshot_20200514-1.15.1-launcher.jar fml TRANSFORMATIONSERVICE 
    FML: 31.2
    Forge: net.minecraftforge:31.2.41
    FML Language Providers: 
        javafml@31.2
        minecraft@1
    Mod List: 
        client-extra.jar Minecraft {minecraft@1.15.2 DONE}
        forge-1.15.2-31.2.41_mapped_snapshot_20200514-1.15.1-recomp.jar Forge {forge@31.2.41 DONE}
        main Depression Mod {depression_mod@NONE DONE}
    Player Count: 1 / 8; [ServerPlayerEntity['Dev'/135, l='New World', x=-140.31, y=70.20, z=-6.46]]
    Data Packs: vanilla, mod:forge (incompatible), mod:depression_mod
    Type: Integrated Server (map_client.txt)
    Is Modded: Definitely; Client brand changed to 'forge'

Link to comment
Share on other sites

public class PlayerMentalCapabilityMessage {
	ClientPlayerEntity player = Minecraft.getInstance().player;  //getInstance().playerをplayerにぶち込む
	LazyOptional<PlayerMentalInterface> cap = player.getCapability(PlayerMentalCapabilityRegistry.PLAYER_MENTAL_CAPABILITY);
		//playerからキャパビリティを取得してplayerMentalInterfaceにぶち込む
	int currentMental = cap.orElseThrow(IllegalArgumentException::new).getMental();
	//int currentMental = ((PlayerMentalInterface) playerMentalInterface).getMental();  //playerMentalInterfaceからmentalの値を取得してcurrentMentalにぶち込む

	public PlayerMentalCapabilityMessage(int currentMental) {
		this.currentMental = currentMental;
	}

	public static void encode(PlayerMentalCapabilityMessage message, PacketBuffer buf) {
		buf.writeInt(message.currentMental);
	}

	public static PlayerMentalCapabilityMessage decode(PacketBuffer buf) {
		int currentMental = buf.readInt();
		return new PlayerMentalCapabilityMessage(currentMental);

	}

	public static void handle(PlayerMentalCapabilityMessage message, Supplier<NetworkEvent.Context> ctx) {
		ctx.get().enqueueWork(() -> {
			DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> Handle.handleClient(message.currentMental));
		});
		ctx.get().setPacketHandled(true);
	}

	//@SuppressWarnings("resource")
	public static class Handle {
		public static DistExecutor.SafeRunnable handleClient(int currentMental) {
			return new DistExecutor.SafeRunnable() {
				@Override
				public void run() {
					LazyOptional<PlayerMentalInterface> cap = Minecraft.getInstance().player.getCapability(PlayerMentalCapabilityRegistry.PLAYER_MENTAL_CAPABILITY);
					cap.orElseThrow(IllegalArgumentException::new).setMental(currentMental);
				}
			};
		}
	}

I fixed the code in the network message and it seems that it crashed for another reason, but I don't know ...

 

---- Minecraft Crash Report ----
// Don't do that.

Time: 20/10/26 13:32
Description: Ticking player

java.lang.ExceptionInInitializerError: null
    at depression_mod.potion.ModEffect.lambda$0(ModEffect.java:30) ~[?:?] {re:classloading}
    at net.minecraftforge.common.util.LazyOptional.ifPresent(LazyOptional.java:161) ~[?:?] {re:classloading}
    at depression_mod.potion.ModEffect.performEffect(ModEffect.java:27) ~[?:?] {re:classloading}
    at depression_mod.potion.ModEffect.affectEntity(ModEffect.java:37) ~[?:?] {re:classloading}
    at net.minecraft.item.PotionItem.onItemUseFinish(PotionItem.java:47) ~[?:?] {re:classloading}
    at net.minecraft.item.ItemStack.onItemUseFinish(ItemStack.java:213) ~[?:?] {re:classloading}
    at net.minecraft.entity.LivingEntity.onItemUseFinish(LivingEntity.java:2876) ~[?:?] {re:classloading}
    at net.minecraft.entity.player.ServerPlayerEntity.onItemUseFinish(ServerPlayerEntity.java:1027) ~[?:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.entity.LivingEntity.updateActiveHand(LivingEntity.java:2754) ~[?:?] {re:classloading}
    at net.minecraft.entity.LivingEntity.tick(LivingEntity.java:2185) ~[?:?] {re:classloading}
    at net.minecraft.entity.player.PlayerEntity.tick(PlayerEntity.java:237) ~[?:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.entity.player.ServerPlayerEntity.playerTick(ServerPlayerEntity.java:379) ~[?:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.network.play.ServerPlayNetHandler.tick(ServerPlayNetHandler.java:188) ~[?:?] {re:classloading}
    at net.minecraft.network.NetworkManager.tick(NetworkManager.java:250) ~[?:?] {re:classloading}
    at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:152) ~[?:?] {re:classloading}
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:903) ~[?:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:821) ~[?:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120) ~[?:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:662) [?:?] {re:classloading,pl:accesstransformer:B}
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_261] {}
Caused by: java.lang.IllegalArgumentException: Registration of network channels is locked
    at net.minecraftforge.fml.network.NetworkRegistry.createInstance(NetworkRegistry.java:130) ~[?:?] {re:classloading}
    at net.minecraftforge.fml.network.NetworkRegistry.newSimpleChannel(NetworkRegistry.java:97) ~[?:?] {re:classloading}
    at depression_mod.network.DepressionModPacketHandler.<clinit>(DepressionModPacketHandler.java:13) ~[?:?] {re:classloading}
    ... 20 more


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Server thread
Stacktrace:
    at depression_mod.potion.ModEffect.lambda$0(ModEffect.java:30)
    at net.minecraftforge.common.util.LazyOptional.ifPresent(LazyOptional.java:161)
    at depression_mod.potion.ModEffect.performEffect(ModEffect.java:27)
    at depression_mod.potion.ModEffect.affectEntity(ModEffect.java:37)
    at net.minecraft.item.PotionItem.onItemUseFinish(PotionItem.java:47)
    at net.minecraft.item.ItemStack.onItemUseFinish(ItemStack.java:213)
    at net.minecraft.entity.LivingEntity.onItemUseFinish(LivingEntity.java:2876)
    at net.minecraft.entity.player.ServerPlayerEntity.onItemUseFinish(ServerPlayerEntity.java:1027)
    at net.minecraft.entity.LivingEntity.updateActiveHand(LivingEntity.java:2754)
    at net.minecraft.entity.LivingEntity.tick(LivingEntity.java:2185)
    at net.minecraft.entity.player.PlayerEntity.tick(PlayerEntity.java:237)

-- Player being ticked --
Details:
    Entity Type: minecraft:player (net.minecraft.entity.player.ServerPlayerEntity)
    Entity ID: 134
    Entity Name: Dev
    Entity's Exact location: -140.36, 70.20, -5.77
    Entity's Block location: World: (-141,70,-6), Chunk: (at 3,4,10 in -9,-1; contains blocks -144,0,-16 to -129,255,-1), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1)
    Entity's Momentum: 0.00, 0.01, 0.00
    Entity's Passengers: []
    Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
    at net.minecraft.entity.player.ServerPlayerEntity.playerTick(ServerPlayerEntity.java:379)
    at net.minecraft.network.play.ServerPlayNetHandler.tick(ServerPlayNetHandler.java:188)
    at net.minecraft.network.NetworkManager.tick(NetworkManager.java:250)

-- Ticking connection --
Details:
    Connection: net.minecraft.network.NetworkManager@20737ec4
Stacktrace:
    at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:152)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:903)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:821)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:662)
    at java.lang.Thread.run(Thread.java:748)

-- System Details --
Details:
    Minecraft Version: 1.15.2
    Minecraft Version ID: 1.15.2
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_261, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 435238600 bytes (415 MB) / 1243086848 bytes (1185 MB) up to 1873805312 bytes (1787 MB)
    CPUs: 12
    JVM Flags: 1 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump
    ModLauncher: 5.1.2+70+master.2845bb9
    ModLauncher launch target: fmluserdevclient
    ModLauncher naming: mcp
    ModLauncher services: 
        /eventbus-2.2.0-service.jar eventbus PLUGINSERVICE 
        /forge-1.15.2-31.2.41_mapped_snapshot_20200514-1.15.1-launcher.jar object_holder_definalize PLUGINSERVICE 
        /forge-1.15.2-31.2.41_mapped_snapshot_20200514-1.15.1-launcher.jar runtime_enum_extender PLUGINSERVICE 
        /accesstransformers-2.1.3-shadowed.jar accesstransformer PLUGINSERVICE 
        /forge-1.15.2-31.2.41_mapped_snapshot_20200514-1.15.1-launcher.jar capability_inject_definalize PLUGINSERVICE 
        /forge-1.15.2-31.2.41_mapped_snapshot_20200514-1.15.1-launcher.jar runtimedistcleaner PLUGINSERVICE 
        /forge-1.15.2-31.2.41_mapped_snapshot_20200514-1.15.1-launcher.jar fml TRANSFORMATIONSERVICE 
    FML: 31.2
    Forge: net.minecraftforge:31.2.41
    FML Language Providers: 
        javafml@31.2
        minecraft@1
    Mod List: 
        client-extra.jar Minecraft {minecraft@1.15.2 DONE}
        forge-1.15.2-31.2.41_mapped_snapshot_20200514-1.15.1-recomp.jar Forge {forge@31.2.41 DONE}
        main Depression Mod {depression_mod@NONE DONE}
    Player Count: 1 / 8; [ServerPlayerEntity['Dev'/134, l='New World', x=-140.36, y=70.20, z=-5.77]]
    Data Packs: vanilla, mod:forge (incompatible), mod:depression_mod
    Type: Integrated Server (map_client.txt)
    Is Modded: Definitely; Client brand changed to 'forge'

Link to comment
Share on other sites

12 hours ago, Zemelua said:

ClientPlayerEntity player = Minecraft.getInstance().player; //getInstance().playerをplayerにぶち込む LazyOptional<PlayerMentalInterface> cap = player.getCapability(PlayerMentalCapabilityRegistry.PLAYER_MENTAL_CAPABILITY); //playerからキャパビリティを取得してplayerMentalInterfaceにぶち込む int currentMental = cap.orElseThrow(IllegalArgumentException::new).getMental();

Reaching across logical sides. Don't ever do this.

13 hours ago, Zemelua said:

LazyOptional<PlayerMentalInterface> cap = Minecraft.getInstance().player.getCapability(PlayerMentalCapabilityRegistry.PLAYER_MENTAL_CAPABILITY); cap.orElseThrow(IllegalArgumentException::new).setMental(currentMental);

We've already went over not to use this.

13 hours ago, Zemelua said:

Registration of network channels is locked

This is the actual error. You're trying to register your network too late. You probably also haven't registered the message either.

13 hours ago, Zemelua said:

public static class Handle { public static DistExecutor.SafeRunnable handleClient(int currentMental) { return new DistExecutor.SafeRunnable() { @Override public void run() { LazyOptional<PlayerMentalInterface> cap = Minecraft.getInstance().player.getCapability(PlayerMentalCapabilityRegistry.PLAYER_MENTAL_CAPABILITY); cap.orElseThrow(IllegalArgumentException::new).setMental(currentMental); } }; } }

This entire thing is a hack. Isolate the code in a different class an use the unsafe version of DistExecutor.

Link to comment
Share on other sites

I'm sorry. I'm still not familiar with network systems. I've read the documentation and some commentary over and over again to understand the rough mechanics (which allows the server / client to exchange data with each other via packets), but specifically which method does what. I'm not sure what it is (what the encode and decode are doing, which method is actually passing the data, etc.) ... if you like, I'll explain it in detail. Could you please?

Link to comment
Share on other sites

In you encode you are writing data from the instance of the packet class to the buffer that is going to be send to the client/server. In decode you are reading the data of the buffer, and pass it into the instance of the packet class which is what handle() will receive and proceed with it.

Edited by poopoodice
Link to comment
Share on other sites

public class PlayerMentalCapabilityMessage {
	ClientPlayerEntity player = Minecraft.getInstance().player;  //getInstance().playerをplayerにぶち込む
	LazyOptional<PlayerMentalInterface> cap = player.getCapability(PlayerMentalCapabilityRegistry.PLAYER_MENTAL_CAPABILITY);
		//playerからキャパビリティを取得してplayerMentalInterfaceにぶち込む
	int currentMental = cap.orElseThrow(IllegalArgumentException::new).getMental();
	//int currentMental = ((PlayerMentalInterface) playerMentalInterface).getMental();  //playerMentalInterfaceからmentalの値を取得してcurrentMentalにぶち込む

	public PlayerMentalCapabilityMessage(int currentMental) {
		this.currentMental = currentMental;
	}

	public static void encode(PlayerMentalCapabilityMessage message, PacketBuffer buf) {
		buf.writeInt(message.currentMental);  //currentMentalの値をバッファーにぶち込む
	}

	public static PlayerMentalCapabilityMessage decode(PacketBuffer buf) {
		int currentMental = buf.readInt();  //バッファーから値を取得する
		return new PlayerMentalCapabilityMessage(currentMental);  //バッファーから取得した値でPlayerMentalCapabilityMessage(int)をインスタンス化

	}

	public static void handle(PlayerMentalCapabilityMessage message, Supplier<NetworkEvent.Context> ctx) {
		ctx.get().enqueueWork(() -> {
			DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> Handle.handleClient(message.currentMental));
		});
		ctx.get().setPacketHandled(true);
	}

	//@SuppressWarnings("resource")
	public static class Handle {
		public static DistExecutor.SafeRunnable handleClient(int currentMental) {
			return new DistExecutor.SafeRunnable() {
				@Override
				public void run() {
					LazyOptional<PlayerMentalInterface> cap = Minecraft.getInstance().player.getCapability(PlayerMentalCapabilityRegistry.PLAYER_MENTAL_CAPABILITY);
					cap.orElseThrow(IllegalArgumentException::new).setMental(currentMental);
				}
			};
		}
	}
}

Sorry. this is.

Link to comment
Share on other sites

I'm not sure why you still have this

	ClientPlayerEntity player = Minecraft.getInstance().player;  //getInstance().playerをplayerにぶち込む
	LazyOptional<PlayerMentalInterface> cap = player.getCapability(PlayerMentalCapabilityRegistry.PLAYER_MENTAL_CAPABILITY);
		//playerからキャパビリティを取得してplayerMentalInterfaceにぶち込む
	int currentMental = cap.orElseThrow(IllegalArgumentException::new).getMental();

You have the value that has passed in to the contructor, just store it there, and use it when needed.

Link to comment
Share on other sites

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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • 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;     }  
  • Topics

×
×
  • Create New...

Important Information

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