Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.12.2][SOLVED!] Capabilities and networking


MCrafterzz
 Share

Recommended Posts

I do admit the isRemote thing was very dumb. I do return success tho. This is the end of the code (It's not the whole code):

 

if (axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(blockpos))
     && worldIn.setBlockState(blockpos, iblockstate1, 10)) {
    SoundType soundtype = this.block.getSoundType(iblockstate1, worldIn, blockpos, player);
    worldIn.playSound(player, blockpos, soundtype.getPlaceSound(), SoundCategory.BLOCKS,
      (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
    if (player instanceof EntityPlayerMP) {
     CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, blockpos, itemstack);
    }
    itemstack.shrink(amount);
    return EnumActionResult.SUCCESS;
   }
 
EDIT:
printing out "PLACED" with my debugger prints this:
[16:27:31] [main/WARN] [ml]: PLACED
[16:27:31] [Server thread/WARN] [ml]: PLACED
 
Why aren't those two messages the same?
Edited by MCrafterzz
Link to comment
Share on other sites

It works like snow layers so you can build apon the block. Also I added the ability to place a four layers at the same time when clicking + CTRL. It's just so wierd as it is based on ItemBlockSnow but randomly workes differently (triggers two times instead of one). Here's the full code:

https://pastebin.com/fys1Mb4G

Edited by MCrafterzz
Link to comment
Share on other sites

I guess I'll have to look into that. The block setting methoud is the same as the vanilla itemblock tho so what do you mean with only place it on the server? Also I still don't understand the reasoning for it triggering twice as the canplayeredit methoud should prevent it.

 

Is there any easier way to detect the press of CTRL without using packets?

Edited by MCrafterzz
Link to comment
Share on other sites

Seems vanilla's ItemBlock actually does the placement on the client as well, very strange. At this point I suspect it triggering twice is not actually the two hands but server and client. Did you check which thread is calling the method?

 

10 minutes ago, MCrafterzz said:

Is there any easier way to detect the press of CTRL without using packets?

No, the server has no idea about the client's keyboard. The server may be located on the other side of the globe, the only way to communicate with it is packets.

And nothing about packets is hard.

Link to comment
Share on other sites

3 hours ago, MCrafterzz said:

Is there any easier way to detect the press of CTRL without using packets?

Isn't CTRL the key used to sneak?
Check if the player is sneaking.

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

You might be right. I haven't actually played in a while.

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

2 minutes ago, MCrafterzz said:

It still activates twice even tho I use worldIn.isRemote = false

If vanilla does not have the isRemote check, you do not need it either. It will active twice then, that is to be expected.

Please give more information about where these two activations are coming from (use the debugger): What hand? What logical side?

Link to comment
Share on other sites

Changing stuff eventually got it to work so now I just have to get the packages setup. Here is what I have so far:

public class KeybindMessage implements IMessage {

	private boolean keybindDown;

	public KeybindMessage(boolean keybindDown) {
		this.keybindDown = keybindDown;
	}

	@Override
	public void fromBytes(ByteBuf buf) {
		buf.readBoolean();
	}

	@Override
	public void toBytes(ByteBuf buf) {
		buf.writeBoolean(keybindDown);
	}

}
public class KeybindMessageHandler implements IMessageHandler<KeybindMessage, IMessage> {

	@Override
	public IMessage onMessage(KeybindMessage message, MessageContext ctx) {
		return null;
	}

}

What should be in the onMessage methoud?

Main class (some stuff has been removed)

@Mod(modid = "ml", name = "More Layers", version = "1.1.0", acceptedMinecraftVersions = "1.12,1.12.1,1.12.2")
@EventBusSubscriber
public class Main {

	public static final SimpleNetworkWrapper networkInstance = NetworkRegistry.INSTANCE.newSimpleChannel("ml");

	@EventHandler
	public static void preInit(FMLPreInitializationEvent event) {
		networkInstance.registerMessage(KeybindMessageHandler.class, KeybindMessage.class, 0, Side.SERVER);
	}

}

I know that I should call Main.networkInstance.sendToServer but where should I call this and how should I get the result?

 

Link to comment
Share on other sites

2 hours ago, MCrafterzz said:

Bump

No.

 

  • Your IMessage classes must have a public no-parameters constructor.
  • You need to remember on the server for each player whether they are currently pressing the button or not. You can do this using capabilities.
  • When the packet arrives, you store the current state in the player's capability.
  • In your ItemBlock you can then access the capability of the player placing the block.
  • "ml" is a terrible mod ID (and network channel). It should be "morelayers".
  • Thanks 1
Link to comment
Share on other sites

I think I got it working but where should I call the capability to update it? Is there a key press event?:

KeybindInterface keybindInterface = event.getEntityPlayer().getCapability(KeybindProvider.capability, event.getFace());
  keybindInterface.setKeybindDown(Minecraft.getMinecraft().gameSettings.keyBindSprint.isKeyDown());

Edited by MCrafterzz
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
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.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Those three errors are what is making the IRCE return null and kicking them. Not sure what more the debug log will give but at least you know for sure the issue is happening when those three functions try to run. So process of deduction.
    • [Info: 2022-01-23 01:21:36.6133870: Xal.lib(0)] XAL: <<< Xal::Auth::InMemoryXboxTokenCache::GetTokenInternal (000085C2AB6FB370) [Info: 2022-01-23 01:21:36.6159390: Xal.lib(0)] XAL: [op 285139008] Refresh Xtoken running with user: true. [Info: 2022-01-23 01:21:36.6166694: Xal.lib(0)] XAL: [op 285139008] Operation RefreshXtoken is starting [Info: 2022-01-23 01:21:36.6176117: Xal.lib(0)] XAL: [op 285139008]     with CV '9/gCxFwybu+GIYtd.14.95' [Info: 2022-01-23 01:21:36.6179699: Xal.lib(0)] XAL: [op 285139008] RefreshXtoken token fetch started. [Info: 2022-01-23 01:21:36.6560585: NetQueue.cpp(601)] NetQueue: No connection available for https://sentry.io/api/2703928/store/ [Error: 2022-01-23 01:21:36.6562804: SentryAPI.cpp(124)] 0 No network connection available [Info: 2022-01-23 01:21:36.6565318: NetQueue.cpp(601)] NetQueue: No connection available for xsts.auth.xboxlive.com [Error: 2022-01-23 01:21:36.8822268: Xal.lib(0)] XAL: Http request 0C18B300 failed with 0x89235006, system error code 0, message:  [Warning: 2022-01-23 01:21:36.8868846: Xal.lib(0)] XAL: [op 285139008] Operation RefreshXtoken failed with result: 0x89235106 - Network error [Warning: 2022-01-23 01:21:36.8885727: Xal.lib(0)] XAL: [op 295548488] Operation GetXtoken failed with result: 0x89235106 - Network error [Warning: 2022-01-23 01:21:36.8968640: Xal.lib(0)] XAL: [op 258947712] Operation GetTokenAndSignature failed with result: 0x89235106 - Network error [Warning: 2022-01-23 01:21:36.8993100: Xal.lib(0)] XAL: GetTokenAndSignature for presence heartbeat failed with Network error (0x89235106)
    • Did you ever find a resolution?  I know that io.netty.util.IllegalReferenceCountException: refCnt: 0 is used as a way to check/validate functions.  I have yet to understand where there is "0" count. We don't have the issue ever on Val 3 only issue that arrises there is.. lets not go there. Anyway I was curious if you had any info in your research, thanks again!
    • I added it like this main private void doClientStuff(final FMLClientSetupEvent event) { event.enqueueWork(() -> { OverlayRegistry.registerOverlayBelow(ForgeIngameGui.FOOD_LEVEL_ELEMENT , "Mana", new ManaOverlay()); }); } But it's not working.   I feel that you don't understand about main... I'll try to find it.
    • Mc Version: 1.17.1 Forge: 37.1.1 Eclipse: 2021-06 new BlockItem(BlockInit.COMPRESSED_SOULS_BLOCK.get(), new Item(new Item.Properties().tab(CreativeModeTab.TAB_MISC))   When I hover over the line, eclipse says that the constructer BlockItem(Block, Item) is not defined
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.