Jump to content

Recommended Posts

Posted

Hello everyone,

 

I'm currently making a mod for a server where I need to add 3 custom signs. The problem is that the method

EntityPlayerSP.openEditSign

uses the vanilla class

GuiEditSign

so the render is completely broken for both the model and the GUI. I made my own

GuiScreen

but I don't know where to use it. I tried to use a

GuiHandler

but I don't know what to return in the method

getServerGuiElement()

.

 

Thanks in advance.

Posted

Hello everyone,

 

I'm currently making a mod for a server where I need to add 3 custom signs. The problem is that the method

EntityPlayerSP.openEditSign

uses the vanilla class

GuiEditSign

so the render is completely broken for both the model and the GUI. I made my own

GuiScreen

but I don't know where to use it. I tried to use a

GuiHandler

but I don't know what to return in the method

getServerGuiElement()

.

 

Thanks in advance.

Cant you extend GuiEditSign? If not you will need to recreate it in your own class.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Well, the thing is that it is hard-coded into the method, so it can't be replaced.

Extracted from EntityPlayerSP:

public void openEditSign(TileEntitySign signTile) {
  this.mc.displayGuiScreen(new GuiEditSign(signTile));
}

My problem is that I don't know how to go around this...

Posted

Well, the thing is that it is hard-coded into the method, so it can't be replaced.

Extracted from EntityPlayerSP:

public void openEditSign(TileEntitySign signTile) {
  this.mc.displayGuiScreen(new GuiEditSign(signTile));
}

My problem is that I don't know how to go around this...

Then try returning null, and if that doesnt work return a new Container or if you have one a new CustomContainer.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

I tried that, but the server never sends the packet to the client to open the gui. I looked up the code inside the openEditSign method in EntityPlayerMP, a specific packet (SPacketSignEditorOpen) is sent to the client when it is called. It's that packet, when processed, that opens the gui clientside. I tried sending it myself but still no luck, the clientside method is still hardcoded.

Posted

Because the method handleSignEditorOpen calls the openEditSign method from the player which opens the default gui. We're coming back to the initial concern.

Posted

McfrNetworkWrapper is the custom network wrapper; OpenEditMcfrSignMessage is the custom packet to notify the client to open the sign edition gui; TileEntityMcfrSign is a custom tile entity extending TileEntitySign; CustomGuiScreen is an enum declaring all guis from the mod.

 

Custom Item Sign:

public class McfrItemSign extends McfrItem {
  private McfrBlockStandingSign standingSign;
  private McfrBlockWallSign wallSign;
  private McfrBlockSuspendedSign suspendedSign;
  private Class<? extends TileEntityMcfrSign> teClass;

  public McfrItemSign(String name, McfrBlockStandingSign standingSign, McfrBlockWallSign wallSign, McfrBlockSuspendedSign suspendedSign, Class<? extends TileEntityMcfrSign> teClass) {
    super(name, 64, CreativeTabs.DECORATIONS);
    this.standingSign = standingSign;
    this.wallSign = wallSign;
    this.suspendedSign = suspendedSign;
    this.teClass = teClass;
  }

  @Override
  public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    IBlockState state = worldIn.getBlockState(pos);
    boolean flag = state.getBlock().isReplaceable(worldIn, pos);

    if (facing != EnumFacing.DOWN && (state.getMaterial().isSolid() || flag) && (!flag || facing == EnumFacing.UP)) {
      pos = pos.offset(facing);

      if (playerIn.canPlayerEdit(pos, facing, stack) && this.standingSign.canPlaceBlockAt(worldIn, pos)) {
        if (!worldIn.isRemote) {
          pos = flag ? pos.down() : pos;

          if (facing == EnumFacing.UP) {
            int i = getRotation(playerIn);
            worldIn.setBlockState(pos, this.standingSign.getDefaultState().withProperty(McfrBlockStandingSign.ROTATION, Integer.valueOf(i)), 11);
          }
          else if (facing == EnumFacing.DOWN) {
            int i = getRotation(playerIn);
            worldIn.setBlockState(pos, this.suspendedSign.getDefaultState().withProperty(McfrBlockSuspendedSign.ROTATION, Integer.valueOf(i)), 11);
          }
          else {
            worldIn.setBlockState(pos, this.wallSign.getDefaultState().withProperty(McfrBlockWallSign.FACING, facing), 11);
          }

          stack.stackSize--;
          TileEntity te = worldIn.getTileEntity(pos);

          if (te != null && te.getClass() == this.teClass && !ItemBlock.setTileEntityNBT(worldIn, playerIn, pos, stack)) {
            ((TileEntityMcfrSign) te).setPlayer(playerIn);
            // We send the packet to the client.
            McfrNetworkWrapper.getInstance().sendTo(new OpenEditMcfrSignMessage(pos), (EntityPlayerMP) playerIn);
          }
        }

        return EnumActionResult.SUCCESS;
      }
    }

    return EnumActionResult.FAIL;
  }

  private int getRotation(EntityPlayer playerIn) {
    return MathHelper.floor_double((playerIn.rotationYaw + 180) * 16 / 360 + 0.5) & 15;
  }
}

 

Message Handler:

public class OpenEditMcfrSignMessageHandler implements IMessageHandler<OpenEditMcfrSignMessage, IMessage> {
  @Override
  @SideOnly(Side.CLIENT)
  public IMessage onMessage(final OpenEditMcfrSignMessage message, MessageContext ctx) {
    Minecraft.getMinecraft().addScheduledTask(new Runnable() {
      @Override
      public void run() {
        BlockPos pos = message.getSignPos();
        EntityPlayer player = Minecraft.getMinecraft().thePlayer;
        World world = Minecraft.getMinecraft().theWorld;

        // Opens the sign edition gui (calls the Gui Handler below).
        player.openGui(McfrMain.instance, CustomGuiScreens.SIGN.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
      }
    });

    return null;
  }
}

 

Gui Handler:

  @Override
  public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
    BlockPos pos = new BlockPos(x, y, z);
    // Here I get null instead of the sign's tile entity.
    TileEntity tileEntity = world.getTileEntity(pos);
    // If the ID is SIGN, open the custom edition gui.
    if (id == CustomGuiScreen.SIGN.ordinal() && tileEntity instanceof TileEntityMcfrSign)
      return new GuiEditSign((TileEntityMcfrSign) tileEntity);
    return null;
  }

 

What is happening here is that when the player right-clicks, the server sends a packet (call to sendTo in onItemUse) to the player to make him open the edition gui. When the Gui Handler is called, I get null where there should be the newly placed tile entity.

Posted

I use a gui handler because I have many custom containers that need that system. I used it to handle the signs gui as well as it was already made (and I don't know how to do otherwise). The code I posted is just the part relevant to the current question.

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



×
×
  • Create New...

Important Information

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