Тайл перестает правильно работать после перезахода в игру

Версия Minecraft
1.12.2
API
Forge
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);
                }
            }
        }
        
    }
    }
 
Решение
Это и написано в заголовке и в самом вопросе...

Неважно где лежит этот метод. Я спросил из какого другого метода и когда он вызывается.
Прошу меня простить, я просто забыл зарегестрировать тайл. Почему-то подумал, что и так заработает почему-то. Спасибо за наводящий вопрос
41
3
3
Как-то вот так
Класс Блока:
package com.miv2nir.basalt.blocks;

import java.util.Random;

import com.miv2nir.basalt.Main;
import com.miv2nir.basalt.init.ModBlocks;
import com.miv2nir.basalt.init.ModItems;
import com.miv2nir.basalt.tile.BlockTileEntity;
import com.miv2nir.basalt.util.handlers.SoundsHandler;

import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.command.ICommandSender;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Enchantments;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.ITickable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.EntityPigZombie;
import com.mojang.authlib.GameProfile;
import com.miv2nir.basalt.tile.TileEntityCounter;

public class PiglinTotem <T extends TileEntity> extends BlockTileEntity{

    public PiglinTotem(String name, Material material)
    {
        super(name, material);
        setSoundType(new SoundType(1.0F, 1.0F, SoundsHandler.BLOCK_PIGLIN_TOTEM_BREAK, SoundEvents.BLOCK_STONE_STEP, SoundEvents.BLOCK_STONE_PLACE, SoundEvents.BLOCK_STONE_HIT, SoundEvents.BLOCK_STONE_FALL));
        setHardness(3F);
        setResistance(6F);
        setHarvestLevel("pickaxe",1);
        setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
        setLightLevel(0.7F);

        //ModBlocks.BLOCKS.add(this);
        //ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
        }
    @Override
    public void registerModels()
    {
        Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
    }
    @Override
    public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
        drops.add(new ItemStack(Items.GOLD_NUGGET, (int) (3)));
    }

    
    @Override
    public TileEntityCounter createTileEntity(World world, IBlockState blockState) {

        return new TileEntityCounter();
    }
    @SubscribeEvent
    public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
    {
        if (!worldIn.isRemote)
        {
            worldIn.createExplosion(null, pos.getX(), pos.getY(), pos.getZ(), 2F, true);
        EntityPigZombie zombie= new EntityPigZombie(worldIn);
        EntityPigZombie zombie2= new EntityPigZombie(worldIn);
        EntityPigZombie zombie3= new EntityPigZombie(worldIn);
        EnumHand hand = zombie.getActiveHand();
        ItemStack item = new ItemStack(Items.GOLDEN_SWORD,(int)(1));
        item.addEnchantment(Enchantments.KNOCKBACK, 1);
        if (zombie != null)
        {
            zombie.setLocationAndAngles(pos.getX(), pos.getY(), pos.getZ(), worldIn.rand.nextFloat() * 360F, 0.0F);
            zombie.setAttackTarget(player);
            zombie.setHeldItem(hand, item);
            worldIn.spawnEntity(zombie);
        }
        if (zombie2 != null)
        {
            zombie2.setLocationAndAngles(pos.getX()+2, pos.getY(), pos.getZ()+2, worldIn.rand.nextFloat() * 360F, 0.0F);
            zombie2.setAttackTarget(player);
            zombie2.setHeldItem(hand, item);
            worldIn.spawnEntity(zombie2);
        }
        if (zombie3 != null)
        {
            zombie3.setLocationAndAngles(pos.getX()-2, pos.getY(), pos.getZ()-2, worldIn.rand.nextFloat() * 360F, 0.0F);
            zombie3.setAttackTarget(player);
            zombie3.setHeldItem(hand, item);
            worldIn.spawnEntity(zombie3);
        }
        }

    
    }
    @Override
    public Class<TileEntityCounter> getTileEntityClass() {

        return TileEntityCounter.class;
    }

}
 
1,560
86
204
вроде как тайл сам на месте и работает ровно до перезапуска мира
Это и написано в заголовке и в самом вопросе...
registerTiles У меня лежит в ModBlocks
Неважно где лежит этот метод. Я спросил из какого другого метода и когда он вызывается.
 

sk9zist :l

Исправился
981
18
157
  • Like
Реакции: jopi
41
3
3
Это и написано в заголовке и в самом вопросе...

Неважно где лежит этот метод. Я спросил из какого другого метода и когда он вызывается.
Прошу меня простить, я просто забыл зарегестрировать тайл. Почему-то подумал, что и так заработает почему-то. Спасибо за наводящий вопрос
 
Сверху