- 41
- 3
- 3
Сделал тикающий тайл, который по кд спавнит мобов рядом с блоком. Проблема только в том, что после перезахода в игру оно перестает работать. Не совсем понимаю что я сделал не так.
Сам тайл:
package com.miv2nir.basalt.tile;
import net.minecraft.entity.monster.EntityPigZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.concurrent.ThreadLocalRandom;
import javax.annotation.Nullable;
import java.util.Iterator;
import java.util.List;
import com.miv2nir.basalt.entity.EntityPigZombieAngry;
import com.mojang.authlib.GameProfile;
public class TileEntityCounter extends TileEntity implements ITickable
{
private int count;
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
tagCompound.setInteger("count", this.count);
return super.writeToNBT(tagCompound);
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
this.count = tagCompound.getInteger("count");
super.readFromNBT(tagCompound);
}
@Override
public void update() {
this.count++;
if (this.count >=200)
{
this.count=0;
if (!world.isRemote)
{
EntityPigZombie zombie= new EntityPigZombie(world);
if (zombie != null)
{
if (world instanceof WorldServer)
((WorldServer) world).spawnParticle(EnumParticleTypes.FLAME, pos.getX(), pos.getY(), pos.getZ(), (int) 15, 0, 1, 0, 0.1, new int[0]);
int randomNumX = ThreadLocalRandom.current().nextInt(-1, 2);
//int randomNumY = ThreadLocalRandom.current().nextInt(-1, 2);
int randomNumZ = ThreadLocalRandom.current().nextInt(-1, 2);
zombie.setLocationAndAngles(pos.getX()+randomNumX, pos.getY(), pos.getZ()+randomNumZ, world.rand.nextFloat() * 360F, 0.0F);
zombie.setHeldItem(zombie.getActiveHand(), new ItemStack(Items.GOLDEN_SWORD,(int)(1)));
world.spawnEntity(zombie);
}
}
}
}
}