Jump to content

Recommended Posts

Posted

When I place my block it updates itself perfectly well, but when I leave and re-enter the world, updateTick doesn't get called any more. I'm using roughly the same code as I did in 1.7.10 when it was fine. Could anyone tell me what I've missed out please?

Code if needed:

 

 

public class BlockFloowerPot extends BlockContainer
{
    private static final AxisAlignedBB POTBOX = new AxisAlignedBB(0.3125F, 0.0F, 0.3125F, 0.6875F, 0.375F, 0.6875F);

    public BlockFloowerPot()
    {
        super(Material.CIRCUITS);
    }

    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
    {
        return POTBOX;
    }

    @Override
    public TileEntity createNewTileEntity(World var1, int var2)
    {
        return new TileEntityFloowerPot();
    }

    public boolean isOpaqueCube(IBlockState state)
    {
        return false;
    }

    @Override
    /**
     * Called upon block activation (right click on the block.)
     */
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
    {
        TileEntity tileEntity = worldIn.getTileEntity(pos);
        if (tileEntity == null || player.isSneaking())
        {
            return false;
        }
        player.openGui(FloocraftBase.instance, 0, worldIn, pos.getX(), pos.getY(), pos.getZ());
        return true;
    }

    @Override
    public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
    {
        this.dropItems(worldIn, pos);
        super.breakBlock(worldIn, pos, state);
    }

    private void dropItems(World world, BlockPos pos){
        Random rand = new Random();

        TileEntity tileEntity = world.getTileEntity(pos);
        if (!(tileEntity instanceof IInventory)) {
            return;
        }
        IInventory inventory = (IInventory) tileEntity;

        for (int i = 0; i < inventory.getSizeInventory(); i++) {
            ItemStack item = inventory.getStackInSlot(i);

            if (item != null && item.stackSize > 0) {
                float rx = rand.nextFloat() * 0.8F + 0.1F;
                float ry = rand.nextFloat() * 0.8F + 0.1F;
                float rz = rand.nextFloat() * 0.8F + 0.1F;

                EntityItem entityItem = new EntityItem(world,
                        pos.getX() + rx, pos.getY() + ry, pos.getZ() + rz,
                        new ItemStack(item.getItem(), item.stackSize, item.getItemDamage()));

                if (item.hasTagCompound()) {
                    entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy());
                }

                float factor = 0.05F;
                entityItem.motionX = rand.nextGaussian() * factor;
                entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
                entityItem.motionZ = rand.nextGaussian() * factor;
                world.spawnEntityInWorld(entityItem);
                item.stackSize = 0;
            }
        }
    }

    @Override
    public int tickRate(World par1World)
    {
        return 50;
    }

    @Override
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
        if(!worldIn.isRemote)
        {
            TileEntityFloowerPot pot = (TileEntityFloowerPot) worldIn.getTileEntity(pos);
            ItemStack stack = pot.getStackInSlot(0);
            if (stack != null)
            {
                int par2 = pos.getX();
                int par3 = pos.getY();
                int par4 = pos.getZ();
                BlockPos currentPos;
                Block currentBlock;
                for (int x = par2 - 5; x < par2 + 6; x++)
                {
                    for (int y = par3 - 5; y < par3 + 6; y++)
                    {
                        for (int z = par4 - 5; z < par4 + 6; z++)
                        {
                            if(stack.stackSize > 0) {
                                currentPos = new BlockPos(x, y, z);
                                currentBlock = worldIn.getBlockState(currentPos).getBlock();
                                if (currentBlock == Blocks.FIRE) {
                                    worldIn.setBlockState(currentPos, FloocraftBase.greenFlamesTemp.getDefaultState());
                                    GreenFlamesTemp tempFire = (GreenFlamesTemp) worldIn.getBlockState(currentPos).getBlock();
                                    if (tempFire.isInFireplace(worldIn, currentPos)) {
                                        Item i = stack.getItem();
                                        worldIn.setBlockState(currentPos, FloocraftBase.greenFlamesIdle.getDefaultState().withProperty(GreenFlamesIdle.AGE, (int) ((ItemFlooPowder) i).getConcentration()), 3);
                                        worldIn.playSound(null, currentPos, greened, SoundCategory.BLOCKS, 1.0F, 1.0F);
                                        stack.stackSize--;
                                        pot.setInventorySlotContents(0, stack.stackSize == 0 ? null : stack.splitStack(stack.stackSize));
                                    } else {
                                        worldIn.setBlockState(currentPos, Blocks.FIRE.getDefaultState());
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn) + rand.nextInt(100));
    }

    @Override
    public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
    {
        worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
    }

    /**
     * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render
     */
    public EnumBlockRenderType getRenderType(IBlockState state)
    {
        return EnumBlockRenderType.MODEL;
    }

    /**
     * Checks to see if its valid to put this block at the specified coordinates. Args: world, pos
     */
    @Override
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
    {
        return super.canPlaceBlockAt(worldIn, pos) && worldIn.isSideSolid(pos.offset(EnumFacing.DOWN), EnumFacing.UP);
    }

    /**
     * Called when a neighboring block changes.
     */
    @Override
    public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn)
    {
        if (!worldIn.isSideSolid(pos.offset(EnumFacing.DOWN), EnumFacing.UP))
        {
            this.dropBlockAsItem(worldIn, pos, state, 0);
            worldIn.setBlockToAir(pos);
        }
    }
}

 

 

 

EDIT: Solved by using scheduleBlockUpdate instead of scheduleUpdate. Thank you for your advice anyway!

Posted

Its funny how you don't override writeToNBT or readFromNBT and still expect your data to get saved.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Its funny how you don't override writeToNBT or readFromNBT and still expect your data to get saved.

I override writeToNBT and readFromNBT in the tile entity, and the data I need is definitely saved there. The issue is that updateTick isn't being called.

Also, you shouldn't be using BlockContainer, it sucks.

What do you recommend instead? Just extending Block and implementing ITileEntityProvider?

Posted

What do you recommend instead? Just extending Block and implementing ITileEntityProvider?

 

Extend

Block

and override

Block#hasTileEntity(IBlockState)

and

Block#createTileEntity

. Don't implement

ITileEntityProvider

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have used mixins once before, and it was with @At RETURN, so it worked fine. Now im trying to use it as INVOKE, and the compilation is successful, but the client crashes almost on startup (just a couple seconds after running runClient)   Im trying to inject the method finishConversion inside the ZombieVillager class. This is my Mixin class important stuff:   import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.monster.ZombieVillager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ZombieVillager.class) public class ZombieVillagerCures { @Inject(method = "finishConversion", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z")) private void addZombieVillagerCuredAmmount(ServerLevel level, CallbackInfo info) { System.out.println("The Mixin Worked!!! " + level); } // Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z } I'm sure the issue lies in the @At cuz other @At values work fine. Its probably the fully qualified name thing. idk how to get it in VS code
    • I'm wayy less skilled than you i bet, but maybe u could try to just convert one into the other?
    • wildbackport is not working
    • Through Betafort Recovery, Bitcoin scam victims can retrieve their money. I recommend Betafort Recovery to anyone who has fallen victim to a scam and has been looking for methods and techniques to recover their lost cryptocurrency or wallets. Betafort Recovery is a reliable cryptocurrency recovery firm that assists victims in recovering their stolen cryptocurrency and offers secure solutions to protect your wallets from online scammers. I must admit that I was deeply melancholy and had given up on life until these experts could restore my $23,400 to my wallet. If you've lost your cryptocurrency and you are helpless about it, contact Betafort Recovery to get your money back. One key aspect that makes Betafort Recovery stand out is its focus on providing secure solutions to protect wallets from online scammers. It's not just about recovering lost funds; it's also about preventing future incidents and ensuring that clients' digital assets are safeguarded against potential threats. This proactive approach demonstrates their commitment to the long-term financial security of their clients. Furthermore, for individuals who have lost their cryptocurrency and are feeling helpless, reaching out to Betafort Recovery could be a turning point in their situation. The reassurance that they are legitimate for seeking help and recovering lost funds can provide much-needed relief and a sense of empowerment. Betafort Recovery as a reliable cryptocurrency recovery firm is certainly well-founded. Their ability to assist scam victims in recovering stolen cryptocurrency, their focus on providing secure solutions, and their commitment to supporting clients through challenging situations make them a valuable resource for individuals navigating the complex world of digital currencies. If you or someone you know has fallen victim to a cryptocurrency scam, contacting Betafort Recovery could be the first step towards reclaiming lost funds and regaining peace of mind.  
    • Idk how i didn't notice that, but I deleted it and fixed some other issues and now I get this https://mclo.gs/YsWacqq
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.