[英]Minecraft forge mod: Remove a block and place a new block
我目前正在制作《我的世界》锻造模组。 有谁知道如何首先删除特定坐标上的块,然后将新块放置在同一位置? 就像用新块替换旧块一样。
我将在这段代码的中间:
if(player.getCurrentEquippedItem() != null)
{
if(hand.getItem() == Items.dirt)
{
}
}
Item.dirt只是一个测试
因此,如果玩家拿着一个特定的物品(我现在正在用尘土)并右键单击该块,将会发生一些事情。 顺便说一句,我还有更多的代码可以使玩家右键单击该块时发生的代码。
我已经用Google搜索了,没有找到任何东西。
如果特定项目是自定义项目,则它要简单得多。
在您的自定义项目中,设置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函数中,则无需测试以确保该项目已配备,因为必须要调用该函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.