Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.14.4] SimpleChannel.registerMessage not working
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
EnderUnknown

[1.14.4] SimpleChannel.registerMessage not working

By EnderUnknown, August 9 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

EnderUnknown    0

EnderUnknown

EnderUnknown    0

  • Tree Puncher
  • EnderUnknown
  • Members
  • 0
  • 17 posts
Posted August 9

I am trying to register a packet to send block contents data from the server to the client. The SimpleChannel isn't letting me register my packet.

PacketHandler class

package com.corruption.network;

import com.corruption.network.packets.PacketPedestal;

import net.minecraft.client.Minecraft;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.network.NetworkRegistry;
import net.minecraftforge.fml.network.PacketDistributor;
import net.minecraftforge.fml.network.simple.SimpleChannel;

public final class PacketHandler {

	private static final String PROTICOL_VERSION = "1";
    public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel(
    		new ResourceLocation("corruption","main")
    		,() -> PROTICOL_VERSION
    		, PROTICOL_VERSION::equals
    		, PROTICOL_VERSION::equals);
    
    public static void register() {
    	int id = 0;
    	
    	CHANNEL.registerMessage(id++, PacketPedestal.class, PacketPedestal::encode, PacketPedestal::new, PacketPedestal::handle);
    }
}

Packet class

package com.corruption.network.packets;

import com.google.common.base.Supplier;

import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkEvent;

public class PacketPedestal {
	private final ItemStack item;
	
	public PacketPedestal(ItemStack stack) {
		this.item = stack;
	}
	public static void encode(PacketPedestal msg, PacketBuffer buf) {
		buf.writeItemStack(msg.item);
	}
	public static PacketPedestal decode(PacketBuffer buf) {
		return new PacketPedestal(buf.readItemStack());
	}
	public static void handle(PacketPedestal msg, Supplier<NetworkEvent.Context> context) {
		
	}
}

Thanks! 

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6692

diesieben07

diesieben07    6692

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6692
  • 45730 posts
Posted August 9
  • Do not create your channel in a static initializer.
  • Please clarify on "isn't letting me".
  • Quote

Share this post


Link to post
Share on other sites

loordgek    163

loordgek

loordgek    163

  • World Shaper
  • loordgek
  • Members
  • 163
  • 1606 posts
Posted August 9

the 4 parameter is wrong change it to  PacketPedestal::decode

  • Quote

Share this post


Link to post
Share on other sites

EnderUnknown    0

EnderUnknown

EnderUnknown    0

  • Tree Puncher
  • EnderUnknown
  • Members
  • 0
  • 17 posts
Posted August 9 (edited)
Quote
  •  Please clarify on "isn't letting me".

I get an error message on PacketPedestal::encode that says:

The type PacketPedestal does not define encode(MSG, PacketBuffer) that is applicable here

and the same for PacketPedestal::handle. The PacketPedestal::decode (previously PacketPedestal::new)  has a different error:

The type of decode(PacketBuffer) from the type PacketPedestal is PacketPedestal, this is incompatible with the descriptor's return type: MSG

I have been following the latest Forge Documentation for Packets which I know is for 1.13 but it is the closest that I could find.

Edited August 9 by EnderUnknown
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6692

diesieben07

diesieben07    6692

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6692
  • 45730 posts
Posted August 9

You are trying to pass PacketPedastal::new for decoder, but the signature does not match up with the required functional interface.

  • Quote

Share this post


Link to post
Share on other sites

EnderUnknown    0

EnderUnknown

EnderUnknown    0

  • Tree Puncher
  • EnderUnknown
  • Members
  • 0
  • 17 posts
Posted August 9

Okay. I changed the PacketPedastal::new to PacketPedastal::decode but it still won't regard that as a MSG. MSG doesn't appear to be a class/interface. How would I go about making the signatures match up or am I missing something big here? Should I use the actual methods instead of just references? 

  • Quote

Share this post


Link to post
Share on other sites

EnderUnknown    0

EnderUnknown

EnderUnknown    0

  • Tree Puncher
  • EnderUnknown
  • Members
  • 0
  • 17 posts
Posted August 9
class MyPacket {
    private final int data;
    MyPacket(PacketBuffer buf) {
        this.data = buf.readInt();
    }

    MyPacket(int data) {
        this.data = data;
    }

    void encode(PacketBuffer buf) {
        buf.writeInt(data);
    }

    void handle(Supplier<NetworkEvent.Context> context) {
    }
}

channel.registerMessage(0, MyPacket.class, MyPacket::encode, MyPacket::new, MyPacket::handle);

I found this on a 1.14.2 post for a similar issue. I tried inserting the code and I received different errors. All three of the method references gave the same error with a different method that isn't being defined:

The type PacketPedestal does not define encode(MSG, PacketBuffer) that is applicable here

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6692

diesieben07

diesieben07    6692

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6692
  • 45730 posts
Posted August 9

Make sure your IDE is configured correctly... this sounds like an IDE issue.

  • Quote

Share this post


Link to post
Share on other sites

EnderUnknown    0

EnderUnknown

EnderUnknown    0

  • Tree Puncher
  • EnderUnknown
  • Members
  • 0
  • 17 posts
Posted August 9

Okay, I will look into that. Thanks!

  • Quote

Share this post


Link to post
Share on other sites

EnderUnknown    0

EnderUnknown

EnderUnknown    0

  • Tree Puncher
  • EnderUnknown
  • Members
  • 0
  • 17 posts
Posted August 10 (edited)

I reloaded and refreshed all of the gradlew stuff and updated forge and I still received the same errors. Would there be an alternative to using a packet? All I need to do is let my TileEntityRenderer know what item is in the PedestalTileEntity, but since renders are handled on the Client side and the client thinks the block is empty nothing happens. I will link my TileEntity and Render classes below. The block calls the method addItemToInventory when activated.

package com.corruption.tileentity;

import com.corruption.Corruption;

import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.item.ItemFrameEntity;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.NonNullList;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

public class PedestalTileEntity extends TileEntity implements ITickableTileEntity{

	protected NonNullList<ItemStack> inv = NonNullList.withSize(1, ItemStack.EMPTY);
	private static final DataParameter<ItemStack> ITEM = EntityDataManager.createKey(ItemFrameEntity.class, DataSerializers.ITEMSTACK);
	protected double currentRotation = 0;
	protected double prevRotation = 0;
	
	public PedestalTileEntity() {
		super(TileEntityRegistry.PEDESTAL);
	}

	
	@Override
	public void tick() {
		this.prevRotation = this.currentRotation;
        this.currentRotation = (this.currentRotation + (double)(50.0F / ((float)20 + 200.0F))) % 360.0D;
        Corruption.LOGGER.info(inv.get(0));
	}
	
	
	public CompoundNBT write(CompoundNBT compound) {	
		super.write(compound);
		ItemStackHelper.saveAllItems(compound, inv);
		return compound;
	}
	public void read(CompoundNBT compound) {
		super.read(compound);
		this.inv = NonNullList.withSize(1, ItemStack.EMPTY);
		ItemStackHelper.loadAllItems(compound, inv);
	}
	
	
	public boolean addItemToInventory(Item item, CompoundNBT itemNbt) {
		if(inv.get(0).isEmpty() && item!=null) {
			inv.clear();
			ItemStack i = new ItemStack(item,1,itemNbt);
			i.setTag(itemNbt);
			inv = NonNullList.withSize(1,i);
			return true;
		}
		else {
			dropItems();
			return false;
		}
	}
	
	
	
	public void dropItems() {
		if(!inv.get(0).isEmpty()) {
			ItemEntity i = new ItemEntity(this.world,(double)this.pos.getX()+0.5D,(double)this.pos.getY()+1.0D, (double)this.pos.getZ()+0.5D,inv.get(0));
			this.world.addEntity(i);
			this.inv.clear();
			this.inv = NonNullList.withSize(1, ItemStack.EMPTY);
		}
	}
	
	public ItemStack getContainedItem() {
		return inv.get(0);
		
	}
	
	@OnlyIn(Dist.CLIENT)
	public double getCurrentRotation() {
		return this.currentRotation;
	}
	@OnlyIn(Dist.CLIENT)
	public double getPrevRotation() {
		return this.prevRotation;
	}

}
package com.corruption.client.render;

import com.corruption.tileentity.PedestalTileEntity;
import com.mojang.blaze3d.platform.GlStateManager;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class PedestalRender extends TileEntityRenderer<PedestalTileEntity>{
	
	private  ItemRenderer itemRenderer;
	
	
	@Override
	public void render(PedestalTileEntity tileEntityIn, double x, double y, double z, float partialTicks,
			int destroyStage) {
		if(itemRenderer == null)
			itemRenderer = Minecraft.getInstance().getItemRenderer();
		ItemStack stack = tileEntityIn.GetContainedItem();
		if(!stack.isEmpty()) {
			RenderHelper.enableStandardItemLighting();
			GlStateManager.pushMatrix();
			
			GlStateManager.translated(x + 0.5, y + 1.5, z + 0.5);
			GlStateManager.scalef(0.5f, 0.5f, 0.5f);
			GlStateManager.rotatef((float)MathHelper.lerp((double)partialTicks, tileEntityIn.GetPrevRotation(), tileEntityIn.GetCurrentRotation()) * 10.0F, 0.0F, 1.0F, 0.0F);
			
			GlStateManager.enableLighting();
			this.itemRenderer.renderItem(stack, ItemCameraTransforms.TransformType.FIXED);
			
			GlStateManager.popMatrix();

		}
		super.render(tileEntityIn, x, y, z, partialTicks, destroyStage);
	}
}

Any help would be appreciated. Thanks! 

Edited August 10 by EnderUnknown
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6692

diesieben07

diesieben07    6692

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6692
  • 45730 posts
Posted August 10

Please post your code as a working Git repository.

  • Quote

Share this post


Link to post
Share on other sites

EnderUnknown    0

EnderUnknown

EnderUnknown    0

  • Tree Puncher
  • EnderUnknown
  • Members
  • 0
  • 17 posts
Posted August 10

I added the code to GitHub:

https://github.com/EnderUnknown/Corruption

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6692

diesieben07

diesieben07    6692

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6692
  • 45730 posts
Posted August 10

Your git repository is unusable. The repository root should be in your project root, where your build.gradle is. The MDK comes with a .gitignore for a reason.

  • Quote

Share this post


Link to post
Share on other sites

EnderUnknown    0

EnderUnknown

EnderUnknown    0

  • Tree Puncher
  • EnderUnknown
  • Members
  • 0
  • 17 posts
Posted August 10

Okay. Sorry for the inconvenience: It should be all sorted out here:

https://github.com/EnderUnknown/Corruption1.14.4

 

 

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6692

diesieben07

diesieben07    6692

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6692
  • 45730 posts
Posted August 10

com.google.common.base.Supplier is not java.util.function.Supplier.

  • Thanks 2
  • Quote

Share this post


Link to post
Share on other sites

EnderUnknown    0

EnderUnknown

EnderUnknown    0

  • Tree Puncher
  • EnderUnknown
  • Members
  • 0
  • 17 posts
Posted August 10

Thank you! That fixed it!

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Oliviafrostpaw
      [1.14.4] Injecting into Existing Loot Tables, Blocks

      By Oliviafrostpaw · Posted 18 minutes ago

      After some poking, the function is not firing whatsoever
    • RaphGamingz
      [1.14.4] Dimensions

      By RaphGamingz · Posted 1 hour ago

      Anyone?
    • RaphGamingz
      [1.14.4] Injecting into Existing Loot Tables, Blocks

      By RaphGamingz · Posted 1 hour ago

      Are you sure this is correct, shouldn’t it be  new ResourceLocation(“minecraft”,”grass”) And is the function firing?
    • mervinrasquinha
      Introducing Stonecage

      By mervinrasquinha · Posted 3 hours ago

      If you’re interested in a modpack with a little bit of tech, a little bit of magic, and a lot of adventure, I would love for you to try out my modpack Stonecage. Stonecage takes mods you might have seen before (and many you might not have), and adds a twist to them to make them fresh again. The main gimmick of the pack is that it makes stone unmineable, meaning you’ll have to explore caves and dungeons the way they were intended, and find solutions to problems you never knew existed. It aims to be a hardcore pack that’s more fair than most, and leaves you to seek combat and adventure on your own terms. While you may start out weak, you’ll find magical artifacts known as curios in your adventures that can be crafted into powerful baubles that will help you in combat and elsewhere. You’ll also find pieces of ancient machines that with research can be deciphered and put back together, bringing industry back to a world that has long been without it. The pack is heavily centered around researching these lost machines, and the research table will guide you through the modpack while giving you more freedom than a quest book would. With a small, curated list of mods, most computers will likely be able to run it, and the many, many lines of scripting keep these mods integrated into what feels like a cohesive whole. If this sounds like fun to you, I encourage you to check it out. If you do, I hope you have as much fun playing it as I did creating it.
    • Darth_Cobalt
      Forge 1.14.4 crashes.

      By Darth_Cobalt · Posted 4 hours ago

      Hi I just downloaded forge and every time i try to load it, it crashes. I have tried 1.14.4 - 28.1.0 and 1.14.4 - 28.1.106. It crashes with both versions. I couldn't figure out how to upload the crash files, could somebody explain how I can do that?
  • Topics

    • Oliviafrostpaw
      7
      [1.14.4] Injecting into Existing Loot Tables, Blocks

      By Oliviafrostpaw
      Started December 8

    • RaphGamingz
      1
      [1.14.4] Dimensions

      By RaphGamingz
      Started Yesterday at 07:45 AM

    • mervinrasquinha
      0
      Introducing Stonecage

      By mervinrasquinha
      Started 3 hours ago

    • Darth_Cobalt
      0
      Forge 1.14.4 crashes.

      By Darth_Cobalt
      Started 4 hours ago

    • leonardsores
      0
      Fun mod interactions

      By leonardsores
      Started 4 hours ago

  • Who's Online (See full list)

    • Redstoneguy129
    • Oliviafrostpaw
    • ricoc90
    • xerca
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.14.4] SimpleChannel.registerMessage not working
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community