Jump to content

Recommended Posts

Posted

I need to execute some code when the player switches his armor. But the LivingEquipmentChangeEvent is only server side and i need to do my stuff client side. So is there a way to run my stuff client side when the LivingEquipmentChangeEvent is fired?

Posted

I tried sending a packet and it is recieved on the client.

public class MessageHandlerBD implements IMessageHandler<MessageBD, IMessage> {

	@Override
	public IMessage onMessage(MessageBD messageBD, MessageContext ctx) {
		System.out.println("PACKET");
		return null;
	}

}

But instead of just writing PACKET in the client log, I want to do something with my Capability on the client side. But when i try it the game always is crashing

	@Override
	public IMessage onMessage(MessageBD messageBD, MessageContext ctx) {
		ctx.getServerHandler().player.getCapability(DiveSpeedProvider.DIVESPEED, null).updateDiveSpeed(ctx.getServerHandler().player);
		return null;
	}

 

Posted

Ok, I now registered the Packet in my ClientProxy

public class ClientProxy implements CommonProxy {
	
	@Override
	public void init() {
		BetterDiving.INSTANCE.registerMessage(MessageHandlerBD.class, MessageBD.class, 0, Side.CLIENT);
	}
}

But once i switch armor on a server nothing happens and on the server i get this message: Undefined discriminator for message type MessageBD in channel better_diving

Posted

Now I created a MessageHandlerBDDummy class and I'm calling this in my ServerProxy

BetterDiving.INSTANCE.registerMessage(MessageHandlerBDDummy.class, MessageBD.class, 0, Side.SERVER);

The MessageHandlyerBDDummy class isn't doing something when receiving a packet. And everything seems to work know. Thank you for the help. If there is a better way of solving my issue you can say it.

Posted
  On 12/31/2018 at 5:50 PM, Meldexun said:

CommonProxy

Expand  

A common proxy doesn’t make sense, proxies are for separating side specific code i.e. code that will crash when executed on the wrong side. A proxy by definition cannot be common. Common code goes anywhere except for in a proxy

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
  On 1/1/2019 at 1:07 PM, diesieben07 said:

The packet must be registered on both sides, no reason to do that through your proxy.

Only the packet action must be encapsulated.

Expand  

Ok. That makes sense. I will try to do that.

 

  On 1/1/2019 at 1:58 PM, Cadiboo said:

A common proxy doesn’t make sense, proxies are for separating side specific code i.e. code that will crash when executed on the wrong side. A proxy by definition cannot be common. Common code goes anywhere except for in a proxy

Expand  

It's just the name of the interface. I have just followed a tutorial for modding beginning and there it was named common proxy. I'm not doing something in this interface.

Posted
  On 1/1/2019 at 2:13 PM, Meldexun said:

It's just the name of the interface. I have just followed a tutorial for modding beginning and there it was named common proxy. I'm not doing something in this interface.

Expand  

Great! IProxy is the conventional name for it though

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
  On 1/1/2019 at 1:07 PM, diesieben07 said:

The packet must be registered on both sides, no reason to do that through your proxy.

Only the packet action must be encapsulated.

Expand  

I now check in my MessageHandler if the message is recieved client side and it seems to work.

	@Override
	public IMessage onMessage(MessageCapabilitySync messageCapabilitySync, MessageContext ctx) {
		if (ctx.side.isClient()) {
			//do some stuff
		}
		return null;
	}

I tried that before but then it was crashing all the time. Thats why I used the proxy to register my message.

 

  On 1/1/2019 at 2:17 PM, Cadiboo said:

Great! IProxy is the conventional name for it though

Expand  

I also noticed that most people name it IProxy. Maybe I will change it too.

Posted
  On 1/1/2019 at 2:37 PM, diesieben07 said:

The condition is pointless, you know which side you sent the packet do.

The "do some stuff" part must be in your client proxy though, like I initially mentioned.

Expand  

So I just create a method in my Client proxy which is than called by the MessageHandler.

	@Override
	public IMessage onMessage(MessageCapabilitySync messageCapabilitySync, MessageContext ctx) {
		ClientProxy.message1(messageCapabilitySync, ctx);
		return null;
	}

 

Posted

Directly calling something on ClientProxy defeats its purpose IIRC, You need to call the method from your proxy instance

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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

    • You are using Create 6 - some addons are not compatible with it Remove all addons and add these one by one littlecontraptions is mentioned - keep this one removed
    • Different problem now. https://paste.ee/p/iDo8lS35
    • I would like to have a BoP sapling drop from my block if it is also installed. I think I have done everything and I cannot pinpoint the problem, which is the error in the logs that appears when joining a world:   [Worker-Main-11/ERROR] [ne.mi.co.ForgeHooks/]: Couldn't parse element loot_tables:grasses:blocks/leaves_block com.google.gson.JsonSyntaxException: Expected name to be an item, was unknown string 'biomesoplenty:magic_sapling' My code:   LootItemConditions.CONDITIONS.register(modEventBus); public class LootItemConditions { public static final DeferredRegister<LootItemConditionType> CONDITIONS = DeferredRegister.create(Registries.LOOT_CONDITION_TYPE, Grasses.MOD_ID); public static final RegistryObject<LootItemConditionType> IS_MOD_LOADED = CONDITIONS.register("is_mod_loaded", () -> new LootItemConditionType(new IsModLoaded.ConditionSerializer())); } public class IsModLoaded implements LootItemCondition { private final boolean exists; private final String modID; public IsModLoaded(String modID) { this.exists = ModList.get().isLoaded(modID); this.modID = modID; } @Override public LootItemConditionType getType() { return LootItemConditions.IS_MOD_LOADED.get(); } @Override public boolean test(LootContext context) { return this.exists; } public static LootItemCondition.Builder builder(String modid) { return () -> new IsModLoaded(modid); } public static class ConditionSerializer implements Serializer<IsModLoaded> { @Override public void serialize(JsonObject json, IsModLoaded instance, JsonSerializationContext ctx) { json.addProperty("modid", instance.modID); } @Override public IsModLoaded deserialize(JsonObject json, JsonDeserializationContext ctx) { return new IsModLoaded(GsonHelper.getAsString(json, "modid")); } } } protected LootTable.Builder createLeavesDropsWithModIDCheck(Block selfBlock, Item sapling, Property<?>[] properties, String modIDToCheck, float... chances) { CopyBlockState.Builder blockStateCopyBuilder = CopyBlockState.copyState(selfBlock); for(Property<?> property : properties) { blockStateCopyBuilder.copy(property); } return LootTable.lootTable() .withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)) .add(LootItem.lootTableItem(selfBlock) .when(HAS_SHEARS_OR_SILK_TOUCH) .apply(blockStateCopyBuilder))) .withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)) .add(this.applyExplosionCondition(selfBlock, LootItem.lootTableItem(sapling)) .when(IsModLoaded.builder(modIDToCheck))) .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, chances)) .when(HAS_NO_SHEARS_OR_SILK_TOUCH)) .withPool(LootPool.lootPool().name("sticks").setRolls(ConstantValue.exactly(1.0F)) .add(this.applyExplosionDecay(selfBlock, LootItem.lootTableItem(Items.STICK). apply(SetItemCountFunction.setCount(UniformGenerator.between(1.0F, 2.0F)))) .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, NORMAL_LEAVES_STICK_CHANCES)) .when(HAS_NO_SHEARS_OR_SILK_TOUCH))); } I don't know. Am I making a mistake somewhere? Am I forgetting something? Should there be something else?
  • Topics

×
×
  • Create New...

Important Information

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