【问题标题】:Minecraft forge mod: Remove a block and place a new blockMinecraft forge mod:移除一个方块并放置一个新方块
【发布时间】:2015-01-03 08:15:22
【问题描述】:

我目前正在制作我的世界锻造模组。 有谁知道如何首先删除特定坐标上的块,然后 在同一个地方放置一个新块?就像用新块替换旧块一样。

我将它放在这段代码的中间:

if(player.getCurrentEquippedItem() != null)
  {

     if(hand.getItem() == Items.dirt)
     {

     }

  }

Item.dirt 只是一个测试

所以如果玩家拿着一个特定的物品(我现在使用泥土)并右键单击该块,就会发生一些事情。顺便说一句,当玩家右键单击该块时,我有更多的代码来实现这一点。

我用谷歌搜索了它,但没有找到任何东西。

【问题讨论】:

    标签: java minecraft minecraft-forge


    【解决方案1】:

    如果特定项目是自定义项目,则要简单得多。

    在您的自定义项目中,设置onItemUse(用于右键单击)或onItemClick(用于左键单击)函数:

    public boolean onItemUse(ItemStack item, EntityPlayer player, World world,
        // which block was in the target when clicked
        int posx, int posy, int posz, 
        // where on the target block was clicked (0.0-1.0)
        int side, float blockx, float blocky, float blockz)
    {
        if(world.isRemote) {
            // can't do anything here as we don't own the world (client side)
            return false;
        }
        // server side - here we can change the block
    

    这个函数被传递给被点击的方块的坐标,以及世界对象。然后,您可以测试被点击的方块,并对其进行任何操作(本示例将其设置为泥土):

    rv = world.setBlock(posx,posy,posz,Blocks.dirt);
    

    当然,如果你把它放在自定义物品自己的onItemUse函数中,那么你就不需要测试来确定物品是否配备了,因为它必须是为了调用该函数。

    【讨论】:

    • 谢谢你,m8。我需要这个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多