"Спавн" вещей

Статус
В этой теме нельзя размещать новые ответы.
Может уже и была тема, но я что-то не нашел, как "спавнить" каждый час какую-либо вещь в определенном блоке?
 
2,955
12
Код:
public class BlockBla extends BlockContainer { 
public BlockBla(Material m) {
                 super(m);
   setTickRandomly(true);
   ........
 }
  public TileEntity createTileEntity() {
     return new TileEntityBla();
 }
  public void onUpdate(World w, int x, int y, int z, Random r) {
     TileEntityBla tile = (TileEntityBla)w.getBlockTileEntity(x, y, z);
     if(tile.time == 72000) {
      EntityItem i = new EntityItem(w, x, y, z, new ItemStack(item, meta, count));
      world.spawnEntityInWorld(i);
       tile.time = 0;
     } else {
       tile.time++;
       }
          }
    }
Код:
     public class TileEntityBla extends TileEntity {
          
     public int time;

      public void readFromNBT(NBTTagCompound tag) {
          if(tag.hasKey("time")) {
            time = tag.getInteger("time");
             } else {
             time = 0;
              }
            }
      public void writeToNBT(NBTTagCompound tag) {
        tag.setInteger("time", time);
        }
     }
 
2,955
12
Переделал на нормальный код
Код:
public class BlockBla extends BlockContainer { 
public BlockBla(Material m) {
                 super(m);
   ........
 }
  public TileEntity createTileEntity() {
     return new TileEntityBla();
 }
    }
Код:
public class TileEntityBla extends TileEntity {
          
     public int time;
 public void readFromNBT(NBTTagCompound tag) {
          if(tag.hasKey("time")) {
            time = tag.getInteger("time");
             } else {
             time = 0;
              }
            }
      public void writeToNBT(NBTTagCompound tag) {
        tag.setInteger("time", time);
        }
        public void  updateEntity() {
     if(time == 72000) {
      EntityItem entityItem = new EntityItem(worldObj, posX, posY, posZ, new ItemStack(item, meta, count));
      world.spawnEntityInWorld(entityItem);
       time = 0;
     } else {
       time++;
       }
          }
     }
 
771
5
Код:
public void updateEntity(){
    super.updateEntity();
    if(worldObj.isRemote){
        return;
    }
    if(worldObj.getTotalWorldTime() % 72000 == 0){
        worldObj.spawnEntityInWorld(new EntityItem(worldObj, xCoord, yCoord, zCoord, new ItemStack(Items.gold_ingot)));
    }
}
Хотя, в дне майнкрафтовском же 24999 тиков, то все таки ты прав, переменную ввести нужно.
 
2,955
12
я никогда не юзал WorldTime, уж слишком он ненадежный (лично для меня)
Ведь юзер всегда может сделать /time set <time>
 
Dragon2488 написал(а):
Переделал на нормальный код
Код:
public class BlockBla extends BlockContainer { 
public BlockBla(Material m) {
                 super(m);
   ........
 }
  public TileEntity createTileEntity() {
     return new TileEntityBla();
 }
    }
Код:
public class TileEntityBla extends TileEntity {
          
     public int time;
 public void readFromNBT(NBTTagCompound tag) {
          if(tag.hasKey("time")) {
            time = tag.getInteger("time");
             } else {
             time = 0;
              }
            }
      public void writeToNBT(NBTTagCompound tag) {
        tag.setInteger("time", time);
        }
        public void  updateEntity() {
     if(time == 72000) {
      EntityItem entityItem = new EntityItem(worldObj, posX, posY, posZ, new ItemStack(item, meta, count));
      world.spawnEntityInWorld(entityItem);
       time = 0;
     } else {
       time++;
       }
          }
     }
Огромное спасибо, можно закрывать!
 

necauqua

когда-то был anti344
Администратор
1,216
27
172
Господи, а нельзя при поставке вызвать апдейт через сколько там надо тиков и при апдейте спаунить и опть вызывать апдейт через сколько там надо тиков?
 
Статус
В этой теме нельзя размещать новые ответы.
Сверху