Jump to content

[1.8] Automatically Spawning and Despawning Tile Entities


Cyberdragon

Recommended Posts

I want to add swamp gas and wisps (swamp lights, NON LIVING entities) to my mod. The swamp gas would spawn first as an entity inside of a water block. The wisp would have a random chance of spawning over it with a random size and color. Both entities would be animated so would need constant updates. I've only seen how to spawn tile entities either in connection to a block or with a player action. How can I get tile entities to spawn and despawn after awhile on their own like mobs do?

Link to comment
Share on other sites

Mob == Entities

TileEntities => Chest, Furnace, etc and not what you want

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.

Link to comment
Share on other sites

Is it purely for visual effect? Will it ever have to move more than 1-2 blocks' distance? If Yes and No, then make a custom particle (which is a special type of Entity) and spawn that from the Block#randomDisplayTick method.

 

Whether that will work or not really depends on how, exactly, you want the 'wisp' to behave in game, e.g. whether it can be interacted with or not.

Link to comment
Share on other sites

Yes, it is just a decorative effect. It will only do a few things like vanish when you get to close, and have a random chance of being hot enough to set fire to nearby vegetation. If I ever make it able to move it will just jump to a spot of gas bubbles that  is touching the one its on. This won't be a smooth animation of movement though, it would literally just warp. The gas bubbles will vanish if you use a bucket on it's water block and have a random chance of exploding when you right click with flint and steel.

 

The wisp should work as a custom particle. If necessary the effects could be driven from the gas entity in the state of having a wisp flame on it. The problem is that the gas will also spawn and despawn in the water automatically. The flame will vanish if it's gas bubble is destroyed or disturbed (ie turned into moving water), so it can be part of the gas code.

Link to comment
Share on other sites

Well, you could use a TileEntity, then, for the wisp, which would do whatever fancy rendering you need in place and also have the ability to affect things on the server via its update tick.

 

In that case, however, you don't want to really spawn and despawn the TileEntity - your Wisp would be an actual Block that changes state, e.g. one state that is visible and one that is invisible (like air). You should allow other blocks to be placed in this space, just like air.

Link to comment
Share on other sites

In that case the gas would be the block and the wisp would be it's tile entity that spawns above it. They would just be invisible and dormant until a random chance it gets activated. The only problem is it would have to be undetected by anything else when dormant, to prevent weird glitches. I would have to make a way to respawn the blocks though so they never run out. Maybe mobs or players walking in shallow water in swamps would spawn gas blocks.

Link to comment
Share on other sites

You can't just spawn a TileEntity anywhere you want - it is part of the Block, and must be at the same position. You can spawn particles and whatever else anywhere you like, though.

 

TileEntities take a lot more processing power than regular Blocks and should be used only for blocks that truly need them, so I highly suggest making the wisp its own separate Block+TileEntity so that your swamp gas can be a regular (i.e. non-TileEntity) block. Users of your mod will thank you.

Link to comment
Share on other sites

Sort of, but I was thinking more along the lines of each gas block placed has a chance of spawning a wisp block above/near it, and then the wisp block would remain there until the gas block is 'broken' or a block is set in its (or the wisp's) place.

 

The wisp TileEntity would be responsible for determining whether or not to render the wisp; when not rendered, it would be invisible / appear the same as air, even though the wisp block is technically still there. I don't see any reason to set and destroy the block over and over - only when you actually want it to be permanently gone should you destroy it, imo.

Link to comment
Share on other sites

Take a look at the RenderEntityFrame class as it has a lot of hidden wins there for a concept like this. In that EntityFrame acts as a container, and you can then inject an "item" of your choosing (block or item) as its subordinate child.

 

In your case you could make the "ItemFrame" a "plate" and the child either a Block or EntityItem (take your pick either way).  It really is up to you on how you form that relationship but the point is inside that one class there's a lot of code to re-use or poach for your bidding.

 

I did something similar, in that when you place a chest below a "slab" it renders a 3D icon of whats inside above the slab. Giving a "shelf" like visualisation.

 

My concept hasn't got colliders etc in it but the way I "paint" it in 3d space is via this method:

 

        public static void RenderFloatingItemIcon(float x, float y, float z, Item item, float partialTickTime, boolean animate) {
        BlockPos pos = new BlockPos(x,y,z);

        // Create Empty EntityItem to help with Rendering Positionining.
        EntityItem entity = new EntityItem(mc.theWorld,pos.getX(),pos.getY(), pos.getZ());
        if (entity.ticksExisted == 0)
        {
            entity.lastTickPosX = entity.posX;
            entity.lastTickPosY = entity.posY;
            entity.lastTickPosZ = entity.posZ;
        }

        double d0 = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double)partialTickTime;
        double d1 = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)partialTickTime;
        double d2 = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double)partialTickTime;

        // TODO: Keep local version of the renderXYZ positions
        double renderPosX = HaxeUtil.GetFieldByReflection(RenderManager.class, mc.getRenderManager(),"renderPosX");
        double renderPosY = HaxeUtil.GetFieldByReflection(RenderManager.class, mc.getRenderManager(),"renderPosY");
        double renderPosZ = HaxeUtil.GetFieldByReflection(RenderManager.class, mc.getRenderManager(),"renderPosZ");

        GlStateManager.pushMatrix();
        renderPosX = (double)pos.getX() - entity.posX + (d0 - renderPosX);
        renderPosY = (double)pos.getY() - entity.posY + (d1 - renderPosY);
        renderPosZ = (double)pos.getZ() - entity.posZ + (d2 - renderPosZ);
        GlStateManager.translate(renderPosX + 0.5D, renderPosY + 1.3, renderPosZ + 0.5D);
        float time = (mc.thePlayer.ticksExisted % 360);
        GL11.glScaled(0.8D,0.8D,0.8D);

        if(animate)
            GL11.glRotatef(-mc.getRenderManager().playerViewY-time*20, 0.0F,1F, 0.0F);
        else
            GL11.glRotatef(-mc.getRenderManager().playerViewY, 0.0F,1F, 0.0F);

        mc.getRenderItem().renderItem(new ItemStack(item), ItemCameraTransforms.TransformType.FIXED);
        GlStateManager.popMatrix();
    }

 

 

[embed=425,349]<iframe width="560" height="315" src="https://www.youtube.com/embed/yfOUhiZolv4" frameborder="0" allowfullscreen></iframe>[/embed]

Link to comment
Share on other sites

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



×
×
  • Create New...

Important Information

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