EntityItem ei = ...
ItemStack is = ei.getEntityItem();
--is.stackSize;
if (is.stackSize <= 0)
ei.setDead();
else
ei.setEntityItemStack(is);
А мона код пояснить?Типа как-то так:
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 (i.getEntityItem().getItem() == Items.APPLE) {
for (EntityItem j :worldIn.getEntitiesWithinAABB(EntityItem.class, getEntityBoundingBox().expand(2.5D, 2.6D, 2.5D).offset(new BlockPos(pos.getX(), pos.getY(), pos.getZ())))){
if (j.getEntityItem().getItem() == Items.DIAMOND) {
Diamond1 =true;
j.setDead();
i.setDead();
}
}
}
}
А мона код пояснить?
EntityItem ei = ...//Твой предмет виде Entity в мире, т.е. EntityItem.
ItemStack is = ei.getEntityItem();//Берём из EntityItem объект ItemStack'а.
--is.stackSize;//Уменьшаем размер стака на одну единицу.
if (is.stackSize <= 0)//Если размер стака меньше или равно нулю, то...
ei.setDead();//EntityItem умрёт (ну типа из мира исчезнет).
else//Если больше нуля, то...
ei.setEntityItemStack(is);//То даём изменённый ItemStack для EntityItem.
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.getItem().getItem() == Items.APPLE) apple = i;
else if (diamond == null && i.getItem().getItem() == Items.DIAMOND) diamond = i;
if (apple != null && diamond != null) break;
}
if (apple != null && diamond != null) {
ItemStack is = apple.getItem();
is.shrink(1);
if (is.getCount() <= 0) apple.setDead(); else apple.setItem(is);
is = diamond.getItem();
is.shrink(1);
if (is.getCount() <= 0) diamond.setDead(); else diamond.setItem(is);
}
Ну прям слишком подробно) я имел ввиду stackSize это откуда брать? Свою переменную пилить? Или как то принимать ее из ItemStack?EntityItem ei = ...//Твой предмет виде Entity в мире, т.е. EntityItem. ItemStack is = ei.getEntityItem();//Берём из EntityItem объект ItemStack'а. --is.stackSize;//Уменьшаем размер стака на одну единицу. if (is.stackSize <= 0)//Если размер стака меньше или равно нулю, то... ei.setDead();//EntityItem умрёт (ну типа из мира исчезнет). else//Если больше нуля, то... ei.setEntityItemStack(is);//То даём изменённый ItemStack для EntityItem.
Это в старой версии в новой брать из метода getCount(), давать setCount(int).stackSize это откуда брать?
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
world = worldIn;
for(int k =-1; k<=1;k++) {
if (worldIn.getBlockState(new BlockPos(pos.getX() + 2, pos.getY(), pos.getZ()+k)).getBlock() != ModBlocks.BLOCKCIRCLE) {
circleIsNotIntact = false;
}
if (worldIn.getBlockState(new BlockPos(pos.getX() - 2, pos.getY(), pos.getZ()+k)).getBlock() != ModBlocks.BLOCKCIRCLE) {
circleIsNotIntact = false;
}
if (worldIn.getBlockState(new BlockPos(pos.getX() + k, pos.getY(), pos.getZ()+2)).getBlock() != ModBlocks.BLOCKCIRCLE) {
circleIsNotIntact = false;
}
if (worldIn.getBlockState(new BlockPos(pos.getX() + k, pos.getY(), pos.getZ()-2)).getBlock() != ModBlocks.BLOCKCIRCLE) {
circleIsNotIntact = false;
}
}
if(circleIsNotIntact == true) {
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 (i.getEntityItem().getItem() == Items.APPLE) {
for (EntityItem j : worldIn.getEntitiesWithinAABB(EntityItem.class, getEntityBoundingBox().expand(2.5D, 2.6D, 2.5D).offset(new BlockPos(pos.getX(), pos.getY(), pos.getZ())))) {
if (j.getEntityItem().getItem() == Items.DIAMOND) {
ItemStack is = i.getEntityItem();
is.shrink(1);
if (is.getCount() <= 0) {
i.setDead();
} else {
i.setEntityItemStack(is);
}
is = j.getEntityItem();
is.shrink(1);
if (is.getCount() <= 0) {
j.setDead();
} else {
j.setEntityItemStack(is);
}
times();
}
}
}
}
}
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
public void times(){
world.setWorldTime(0);
}
for(int k =-1; k<=1;k++) {
if (worldIn.getBlockState(new BlockPos(pos.getX() + 2, pos.getY(), pos.getZ()+k)).getBlock() != ModBlocks.BLOCKCIRCLE) {
circleIsNotIntact = false;
}
if (worldIn.getBlockState(new BlockPos(pos.getX() - 2, pos.getY(), pos.getZ()+k)).getBlock() != ModBlocks.BLOCKCIRCLE) {
circleIsNotIntact = false;
}
if (worldIn.getBlockState(new BlockPos(pos.getX() + k, pos.getY(), pos.getZ()+2)).getBlock() != ModBlocks.BLOCKCIRCLE) {
circleIsNotIntact = false;
}
if (worldIn.getBlockState(new BlockPos(pos.getX() + k, pos.getY(), pos.getZ()-2)).getBlock() != ModBlocks.BLOCKCIRCLE) {
circleIsNotIntact = false;
}
}
if(circleIsNotIntact == true) {
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 (i.getEntityItem().getItem() == Items.APPLE) {
for (EntityItem j : worldIn.getEntitiesWithinAABB(EntityItem.class, getEntityBoundingBox().expand(2.5D, 2.6D, 2.5D).offset(new BlockPos(pos.getX(), pos.getY(), pos.getZ())))) {
if (j.getEntityItem().getItem() == Items.DIAMOND) {
apple = i;
diamond = j;
break;
}
}
}
}
}
if(apple != 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);
}
apple =null;
diamond = null;
worldIn.setWorldTime(0);
}
Не думаю, у тебя два цикла и один break, а должно два: один останавливает второй цикл, второй останавливает первый цикл.так правильней?
Он проверяет целостность конструкции не дуиаю, что он как то мешает и что ему нужен брэйк ибо раньше всё работало.третий цикл есть.
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
for(int k =-1; k<=1;k++) {
if (worldIn.getBlockState(new BlockPos(pos.getX() + 2, pos.getY(), pos.getZ()+k)).getBlock() != ModBlocks.BLOCKCIRCLE) {
circleIsNotIntact = false;
}
if (worldIn.getBlockState(new BlockPos(pos.getX() - 2, pos.getY(), pos.getZ()+k)).getBlock() != ModBlocks.BLOCKCIRCLE) {
circleIsNotIntact = false;
}
if (worldIn.getBlockState(new BlockPos(pos.getX() + k, pos.getY(), pos.getZ()+2)).getBlock() != ModBlocks.BLOCKCIRCLE) {
circleIsNotIntact = false;
}
if (worldIn.getBlockState(new BlockPos(pos.getX() + k, pos.getY(), pos.getZ()-2)).getBlock() != ModBlocks.BLOCKCIRCLE) {
circleIsNotIntact = false;
}
}
if(circleIsNotIntact == true) {
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 (i.getEntityItem().getItem() == Items.APPLE) {
for (EntityItem j : worldIn.getEntitiesWithinAABB(EntityItem.class, getEntityBoundingBox().expand(2.5D, 2.6D, 2.5D).offset(new BlockPos(pos.getX(), pos.getY(), pos.getZ())))) {
if (j.getEntityItem().getItem() == Items.DIAMOND) {
apple = i;
diamond = j;
break;
}
}
break;
}
}
}
if(apple != 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);
}
apple = null;
diamond = null;
worldIn.setWorldTime(0);
}
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (worldIn.isRemote) return true;
EntityItem
apple = null,
diamond = null;
for (int x =-2; x <= 2; x++) {
if (x == 0) {
for (int z =-2; z <= 2; z++) {
if (z == 0) continue;
if (worldIn.getBlockState(new BlockPos(pos.getX(), pos.getY(), pos.getZ()+z)).getBlock() != ModBlocks.BLOCKCIRCLE)) {
return true;
}
}
} else {
if (worldIn.getBlockState(new BlockPos(pos.getX() + x, pos.getY(), pos.getZ())).getBlock() != ModBlocks.BLOCKCIRCLE)) {
return true;
}
}
}
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;
}
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(0L);
}
return true;
}