роблема этого кода в том, что если я кину яблоко жмакну на блок, а после кину алмаз и жмакну на блок, то условие выполнится, и в итоге потратится только алмазfor (EntityItem i : worldIn.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(pos).expand(2.5D, 2.6D, 2.5D))) { if (apple == null && i.getEntityItem().getItem() == Items.APPLE) apple = i; else if (diamond == null && i.getEntityItem().getItem() == Items.DIAMOND) diamond = i; if (apple != null && diamond != null) break; }
то есть ты тоже не понимаешь почему именно на 4 парах предметов работает, а на 1 паре нет?Хм... Тогда не знаю чем тебе ещё помочь (на новой версии Minecraft).
У тебя на 1.11+, а у меня 1.12+.могу полностью регистрацию кинуть, то есть весь свой код
Примерно так-же:а можешь кинуть как ты сделал на 1.7.10?
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
if (world.isRemote) return true;
EntityItem
apple = null,
diamond = null;
for (int xp =-2; xp <= 2; xp++) {
if (xp == 0) {
for (int zp =-2; zp <= 2; zp++) {
if (zp == 0) continue;
if (world.getBlock(x, y, z + zp) != net.minecraft.init.Blocks.diamond_block) return true;
}
} else {
if (world.getBlock(x + xp, y, z) != net.minecraft.init.Blocks.diamond_block) return true;
}
}
for (Object o : world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(x, y, z, x + 1D, y + 1D, z + 1D).expand(2D, 2D, 2D))) {
EntityItem i = (EntityItem)o;
if (apple == null && i.getEntityItem().getItem() == Items.apple) apple = i;
else if (diamond == null && i.getEntityItem().getItem() == Items.diamond) diamond = i;
if (apple != null && diamond != null) break;
}
if (apple != null && diamond != null) {
ItemStack is = apple.getEntityItem();
--is.stackSize;
if (is.stackSize <= 0) apple.setDead(); else apple.setEntityItemStack(is);
is = diamond.getEntityItem();
--is.stackSize;
if (is.stackSize <= 0) diamond.setDead(); else diamond.setEntityItemStack(is);
world.setWorldTime(0L);
}
return true;
}
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
EntityItem apple = null,
diamond = null;
for (EntityItem i : worldIn.getEntitiesWithinAABB(EntityItem.class, getEntityBoundingBox().expand(2.5D, 2.6D, 2.5D).offset(new BlockPos(pos.getX(), pos.getY(), pos.getZ())))) {
if (apple == null && i.getEntityItem().getItem() == Items.APPLE) apple = i;
else if (diamond == null && i.getEntityItem().getItem() == Items.DIAMOND) diamond = i;
if (apple != null && diamond != null) break;
}
if (apple != null && diamond != null) {
ItemStack is = apple.getEntityItem();
is.shrink(1);
if (is.getCount() <= 0) apple.setDead(); else apple.setEntityItemStack(is);
is = diamond.getEntityItem();
is.shrink(1);
if (is.getCount() <= 0) diamond.setDead(); else diamond.setEntityItemStack(is);
worldIn.setWorldTime(0);
}
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
Ну как самому это нужно сделать этот Delay / CoolDown. Ну как-бы предположение, как сделать, есть.делай
Немного не понялНу как самому это нужно сделать этот Delay / CoolDown. Ну как-бы предположение, как сделать, есть.
А тут не чего понимать. Моё предположение, типа есть несколько видов. Ну, типа одно из них:Немного не понял
Просто наверное есть какой нибудь метод, который по тикам отсчитывает время и на это опиратьсятипа есть несколько видов
EntityItem
apple = null,
diamond = null;
for (EntityItem i :worldIn.getEntitiesWithinAABB(EntityItem.class, getEntityBoundingBox().expand(2.5D, 2.6D, 2.5D).offset(new BlockPos(pos.getX(), pos.getY(), pos.getZ())))) {
if (apple == null && i.getEntityItem().getItem() == Items.APPLE) apple = i;
else if (diamond == null && i.getEntityItem().getItem() == Items.DIAMOND) diamond = i;
if (apple != null && diamond != null) break;
}
if (apple != null && diamond != null) {
apple.getEntityItem().stackSize -= 1;
if (apple.getEntityItem().stackSize <= 0) {
apple.setDead();
}else {
apple.setEntityItemStack(apple.getEntityItem());
}
diamond.getEntityItem().stackSize -= 1;
if (diamond.getEntityItem().stackSize <= 0) {
diamond.setDead();
}else {
diamond.setEntityItemStack(diamond.getEntityItem());
}
worldIn.setWorldTime(0);
}
Я без понятия, что ты собираешься с этим делать.вот вопрос что с этим делать та