
link182
Members-
Posts
21 -
Joined
-
Last visited
Everything posted by link182
-
Ah I never thought about that, great idea. Thanks for the suggestion dude.
-
@SubscribeEvent public void onAttachCapabilities(AttachCapabilitiesEvent<Entity> event) { if (event.getObject() instanceof PlayerEntity) { PlayerEntity playerEntity = (PlayerEntity) event.getObject(); playerEntityPortalManagerMap.put(playerEntity, new PortalManager(playerEntity.getEntityWorld(), playerEntity)); } } public PortalManager(World worldIn, Entity playerIn) { this.portalCommands = new PortalCommands( worldIn.getServer().getCommandSource() .withPermissionLevel(2) .withEntity(playerIn) .withFeedbackDisabled(), worldIn.getServer().getCommandManager()); PORTAL_1_ID = "portal_1_" + playerIn.getUniqueID(); PORTAL_2_ID = "portal_2_" + playerIn.getUniqueID(); } Here's the exception: net.minecraft.crash.ReportedException: Ticking memory connection at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:154) ~[?:?] {re:classloading} at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:899) ~[?:?] {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:84) ~[?:?] {re:classloading,pl:runtimedistcleaner:A} at net.minecraft.server.MinecraftServer.func_240802_v_(MinecraftServer.java:664) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.lambda$func_240784_a_$0(MinecraftServer.java:233) ~[?:?] {re:classloading,pl:accesstransformer:B} at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181] {} Caused by: java.lang.NullPointerException at net.minecraft.entity.player.PlayerEntity.getName(PlayerEntity.java:1793) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.command.CommandSource.withEntity(CommandSource.java:75) ~[forge-1.16.5-36.1.0_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading} at com.namarino41.portalgunforge.util.PortalManager.<init>(PortalManager.java:39) ~[main/:?] {re:classloading} at com.namarino41.portalgunforge.items.PortalGunItem.onAttachCapabilities(PortalGunItem.java:108) ~[main/:?] {re:classloading} at net.minecraftforge.eventbus.ASMEventHandler_3_PortalGunItem_onAttachCapabilities_AttachCapabilitiesEvent.invoke(.dynamic) ~[?:?] {} at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-4.0.0.jar:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-4.0.0.jar:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-4.0.0.jar:?] {} at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:579) ~[?:?] {re:classloading} at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:573) ~[?:?] {re:classloading} at net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:48) ~[?:?] {re:classloading} at net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:44) ~[?:?] {re:classloading} at net.minecraft.entity.Entity.<init>(Entity.java:221) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.entity.LivingEntity.<init>(LivingEntity.java:207) ~[?:?] {re:classloading} at net.minecraft.entity.player.PlayerEntity.<init>(PlayerEntity.java:160) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.entity.player.ServerPlayerEntity.<init>(ServerPlayerEntity.java:182) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.management.PlayerList.createPlayerForUser(PlayerList.java:419) ~[?:?] {re:classloading} at net.minecraft.network.login.ServerLoginNetHandler.tryAcceptPlayer(ServerLoginNetHandler.java:122) ~[?:?] {re:classloading} at net.minecraft.network.login.ServerLoginNetHandler.tick(ServerLoginNetHandler.java:66) ~[?:?] {re:classloading} at net.minecraft.network.NetworkManager.tick(NetworkManager.java:244) ~[?:?] {re:classloading} at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:151) ~[?:?] {re:classloading} ... 6 more withEntity calls toString which is causing the error. Again, is there a way I can get the fully initialized player?
-
Clearly...how can I do it then?
-
I was trying to initialize another object using the player. https://github.com/namarino41/portalgun_forge/blob/ef13a032415f9a0a484005c847eae5b8ae5a7782/src/main/java/com/namarino41/portalgunforge/util/PortalManager.java#L35
-
Interesting, I wasn't trying to print out the player. So is there another way to get the fully initialized player?
-
Yeah but doing that results in that exception I noted above.
-
Well basically I need to create an object using the player and the world.
-
Hmm, I'm trying to get the player though. Anyway I can do that?
-
Hello. I'm playing around with the AttachCapabilitiesEvent<Entity>. I'm trying to attach something to the player, but right now I'm just seeing if I can get the player object. I'm getting a NullPointerException though when I try to do this. Here is the relevant code: public class PortalGun extends Item{ public PortalGun() { super(new Item.Properties().group(ItemGroup.TOOLS)); MinecraftForge.EVENT_BUS.register(this); } @SubscribeEvent public void onAttachCapabilities(AttachCapabilitiesEvent<Entity> event) { if (event.getObject() instanceof PlayerEntity) { // do something with Player } } } When the player loads into the game, I get the following error: [02:05:50] [Server thread/ERROR] [minecraft/MinecraftServer]: Encountered an unexpected exception net.minecraft.crash.ReportedException: Ticking memory connection at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:154) ~[?:?] {re:classloading} at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:899) ~[?:?] {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:84) ~[?:?] {re:classloading,pl:runtimedistcleaner:A} at net.minecraft.server.MinecraftServer.func_240802_v_(MinecraftServer.java:664) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.lambda$func_240784_a_$0(MinecraftServer.java:233) ~[?:?] {re:classloading,pl:accesstransformer:B} at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181] {} Caused by: java.lang.NullPointerException at net.minecraft.entity.player.PlayerEntity.getName(PlayerEntity.java:1793) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.entity.Entity.toString(Entity.java:2362) ~[?:?] {re:classloading,pl:accesstransformer:B} at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_181] {} at net.minecraftforge.fml.loading.TracingPrintStream.println(TracingPrintStream.java:65) ~[forge-1.16.5-36.1.0_mapped_snapshot_20200514-1.16-launcher.jar:36.1] {} at com.namarino41.portalgunforge.items.PortalGunItem.onAttachCapabilities(PortalGunItem.java:106) ~[main/:?] {re:classloading} at net.minecraftforge.eventbus.ASMEventHandler_2_PortalGunItem_onAttachCapabilities_AttachCapabilitiesEvent.invoke(.dynamic) ~[?:?] {} at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-4.0.0.jar:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-4.0.0.jar:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-4.0.0.jar:?] {} at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:579) ~[?:?] {re:classloading} at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:573) ~[?:?] {re:classloading} at net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:48) ~[?:?] {re:classloading} at net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:44) ~[?:?] {re:classloading} at net.minecraft.entity.Entity.<init>(Entity.java:221) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.entity.LivingEntity.<init>(LivingEntity.java:207) ~[?:?] {re:classloading} at net.minecraft.entity.player.PlayerEntity.<init>(PlayerEntity.java:160) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.entity.player.ServerPlayerEntity.<init>(ServerPlayerEntity.java:182) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.management.PlayerList.createPlayerForUser(PlayerList.java:419) ~[?:?] {re:classloading} at net.minecraft.network.login.ServerLoginNetHandler.tryAcceptPlayer(ServerLoginNetHandler.java:122) ~[?:?] {re:classloading} at net.minecraft.network.login.ServerLoginNetHandler.tick(ServerLoginNetHandler.java:66) ~[?:?] {re:classloading} at net.minecraft.network.NetworkManager.tick(NetworkManager.java:244) ~[?:?] {re:classloading} at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:151) ~[?:?] {re:classloading} ... 6 more How can I work around this and get the player? Thanks.
-
How do I get the player though? Can you please give me an example of how to do this?
-
I'll ask the question again. Differently this time. I would like to initialize the PM outside of the item method. It requires a CommandSource, a Commands object, and the player. Right now, these are gotten from the player in the item method. How can I accomplish this without using the item method?
-
That was before you said you had no idea what I was talking about...so clearly you still didn't understand and yet you didn't ask for more clarification so you could actually help.
-
Then I told you and you said you have no idea what my issue was
-
If you don't know what the issue is, why not ask for clarification?
-
The Portal Manager takes in a CommandSource and a Commands object. How do I get these without the Item method? I can't use world and player from the item method because then the player would first have to use the item before the portal manager knows anything about the world. I think it's made pretty clear in my question.
-
The player using the item and the world he's playing in. No offense and I'm really not trying to be rude here, but I feel like this a pretty good question that deserves some better answers and engagement than what it's been given. I think you can intuit which world and which player I'm talking about. You don't need to try to hit me with a gotcha question. I would really appreciate some help on this with some actual examples that I can use. Considering there is almost no documentation on this stuff, I don't think that's too much to ask.
-
Still not sure I understand. How can I get the world and player without it coming through itemRightClicked? Again, I would appreciate an actual example of this stuff working.
-
I know how to google. I was hoping someone could explain to me how this relates to commands and how to get a command manager using this.
-
Can I get some slightly more detailed help please? @diesieben07's answer was not exactly what I was looking for.
-
How do I use World capability? Could you give me a short example?
-
Hello, I am making a mod that uses the commands from another mod to create portals. That mod is in a state of disrepair environment wise, so I'm not able to use its code, that's why I have to use commands. So essentially what I'm trying to make is a glorified command stick. I have a few question regarding the design. The relevant code snippets can be find below. This code works in a single player world, but, while I haven't tested it there yet, I don't think it would work in a multiplayer one, even if I tweak the whole "!worldIn.isRemote" part. 1. You can see I create a PortalManager when the item is used. Obviously this is not ideal. For example, if I reload a world where I've created portals, I am creating a new PM that doesn't know about them. The problem is I need the "playerIn" object provided by "onItemRightClick" to create the CommandSource and Commands objects. I've tried using "Minecract.getInstance().getServer()", but that returns "null". Ideally, I would want to make PM outside of all this so I can initialize it with stuff from an existing world with portals in it. So basically, how can I get a CommandSource and a Commands object without the "playerIn" from "onItemRightClick"? 2. Sort of related to 1. What tweaks would I have to make in order for this to work on a dedicated server as well as single player world? I don't think I have to worry about packets as the commands from the mod I'm using already take care of spawning entities and what not. Should the commands be executed on the server instead of the client? I don't have a good understanding of which side should execute what. PortalGunItem PortalManager Thank you very much for the help, it is greatly appreciated. Please let me know if you need to see more code in order to help me. I have a pretty functional od already, but didn't want to flood this post with all the code obviously.