Jump to content

Recommended Posts

Posted

I have a block with a custom model and I have all the code setup so that it renders correctly and the same "front" face points towards the player, depending on from which direction the player places the block (e.g. rotates like a furnace). However, once I exit the world and reload it, the block automatically rotates back to standard position (facing south), instead of staying in the orientation it has been set to. Anyone know what the issue is? I think it has something to do with the NBT data, but i'm not sure why.

CODE:

Block:

package lifemod.blocks.toilet;

import lifemod.LifeMod;
import lifemod.lifepanel.LifePanel;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class BlockToilet extends BlockContainer
{
public BlockToilet()
{
	super(Material.rock);
	this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}

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

    public int getRenderType()
    {
    	return -1;
    }
    
    public boolean isOpaqueCube()
    {
    	return false;
    }

    public boolean renderAsNormalBlock()
    {
    	return false;
    }
    
    @Override
    public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack itemStack)
    {
        int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
        int newFacing = 0;
        if (facing == 0)
        {
        	newFacing = 2;
        }
        if (facing == 1)
        {
        	newFacing = 5;
        }
        if (facing == 2)
        {
        	newFacing = 3;
        }
        if (facing == 3)
        {
        	newFacing = 4;
        }
        TileEntity te = world.getTileEntity(i, j, k);
        if (te != null && te instanceof TileEntityToilet)
        {
        	TileEntityToilet tet = (TileEntityToilet) te;
            tet.setFacingDirection(newFacing);
            world.markBlockForUpdate(i, j, k);
        }
    }
}

TileEntity

package lifemod.blocks.toilet;

import lifemod.packethandler.PacketHandler;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;

public class TileEntityToilet extends TileEntity
{
private int facingDirection;

public int getFacingDirection()
    {
        return this.facingDirection;
    }

public void setFacingDirection(int par1)
    {
        this.facingDirection = par1;
    }

@Override
    public void readFromNBT(NBTTagCompound nbttagcompound)
    {
        super.readFromNBT(nbttagcompound);  
        facingDirection = nbttagcompound.getInteger("facingDirection");
    }

    @Override
    public void writeToNBT(NBTTagCompound nbttagcompound)
    {
        super.writeToNBT(nbttagcompound);
        nbttagcompound.setInteger("facingDirection", facingDirection);
    }
}

TileEntitySpecialRenderer:

package lifemod.blocks.toilet;

import lifemod.LifeMod;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

import org.lwjgl.opengl.GL11;

public class TileEntitySpecialRendererToilet extends TileEntitySpecialRenderer
{
private final ModelToilet model = new ModelToilet();
    private static final ResourceLocation texture = new ResourceLocation("lifemod:textures/blocks/toilet.png");
    
    public void render(TileEntityToilet te, double x, double y, double z, float scale)
    {
    	GL11.glPushMatrix(); 	
        GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
        this.bindTexture(texture);
        //Rotates model, as for some reason it is initially upside (180 = angle, 1.0F at end = about z axis)
        GL11.glRotatef(180, 0.0F, 0.0F, 1.0F);
        int facing = te.getFacingDirection();
        int k = 0;
        //South
        if (facing == 2) {
            k = 0;
        }
        //North
        if (facing == 3) {
            k = 180;
        }
        //East
        if (facing == 4) {
            k = -90;
        }
        //West
        if (facing == 5) {
            k = 90;
        }
        //Rotates model on the spot, depending on direction, making the front always to player) (k = angle, 1.0F in middle = about y axis)
        GL11.glRotatef(k, 0.0F, 1.0F, 0.0F);
        GL11.glDisable(GL11.GL_CULL_FACE);
        GL11.glEnable(GL11.GL_ALPHA_TEST);
        this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        GL11.glPopMatrix();
}

    
    public void renderTileEntityAt(TileEntity p_147500_1_, double p_147500_2_, double p_147500_4_, double p_147500_6_, float p_147500_8_)
    {
    	this.render((TileEntityToilet)p_147500_1_, p_147500_2_, p_147500_4_, p_147500_6_, p_147500_8_);
    }
}

Inside the ClientProxy:

ClientRegistry.bindTileEntitySpecialRenderer(TileEntityToilet.class, new TileEntitySpecialRendererToilet());

 

Thanks in advance

Posted

First have you registered you tileentity? If you have add this to the tileentity code:

 

   @Override
    public Packet getDescriptionPacket()
    {
        NBTTagCompound tag = new NBTTagCompound();
        writeToNBT(tag);
        return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
    }

    @Override
    public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)
    {
        readFromNBT(packet.func_148857_g());
    }

Posted
  On 4/21/2014 at 5:15 PM, Godis_apan said:

First have you registered you tileentity? If you have add this to the tileentity code:

 

   @Override
    public Packet getDescriptionPacket()
    {
        NBTTagCompound tag = new NBTTagCompound();
        writeToNBT(tag);
        return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
    }

    @Override
    public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)
    {
        readFromNBT(packet.func_148857_g());
    }

 

As soon as I placed the block in the world this crash report appeared and the game crashed:

---- Minecraft Crash Report ----
// Who set us up the TNT?

Time: 21/04/14 18:17
Description: Exception ticking world

java.lang.RuntimeException: class lifemod.blocks.toilet.TileEntityToilet is missing a mapping! This is a bug!
at net.minecraft.tileentity.TileEntity.writeToNBT(TileEntity.java:100)
at lifemod.blocks.toilet.TileEntityToilet.writeToNBT(TileEntityToilet.java:37)
at lifemod.blocks.toilet.TileEntityToilet.getDescriptionPacket(TileEntityToilet.java:51)
at net.minecraft.server.management.PlayerManager$PlayerInstance.sendTileToAllPlayersWatchingChunk(PlayerManager.java:521)
at net.minecraft.server.management.PlayerManager$PlayerInstance.sendChunkUpdate(PlayerManager.java:463)
at net.minecraft.server.management.PlayerManager.updatePlayerInstances(PlayerManager.java:94)
at net.minecraft.world.WorldServer.tick(WorldServer.java:194)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:682)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:604)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:742)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at net.minecraft.tileentity.TileEntity.writeToNBT(TileEntity.java:100)
at lifemod.blocks.toilet.TileEntityToilet.writeToNBT(TileEntityToilet.java:37)
at lifemod.blocks.toilet.TileEntityToilet.getDescriptionPacket(TileEntityToilet.java:51)
at net.minecraft.server.management.PlayerManager$PlayerInstance.sendTileToAllPlayersWatchingChunk(PlayerManager.java:521)
at net.minecraft.server.management.PlayerManager$PlayerInstance.sendChunkUpdate(PlayerManager.java:463)
at net.minecraft.server.management.PlayerManager.updatePlayerInstances(PlayerManager.java:94)
at net.minecraft.world.WorldServer.tick(WorldServer.java:194)

-- Affected level --
Details:
Level name: New World
All players: 1 total; [EntityPlayerMP['Player715'/240, l='New World', x=257.46, y=4.00, z=-746.51]]
Chunk stats: ServerChunkCache: 625 Drop: 0
Level seed: -5659666563785698564
Level generator: ID 01 - flat, ver 0. Features enabled: true
Level generator options: 
Level spawn location: World: (254,4,-751), Chunk: (at 14,0,1 in 15,-47; contains blocks 240,0,-752 to 255,255,-737), Region: (0,-2; contains chunks 0,-64 to 31,-33, blocks 0,0,-1024 to 511,255,-513)
Level time: 3368 game time, 3368 day time
Level dimension: 0
Level storage version: 0x04ABD - Anvil
Level weather: Rain time: 143259 (now: false), thunder time: 17049 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true
Stacktrace:
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:682)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:604)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:742)

-- System Details --
Details:
Minecraft Version: 1.7.2
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.8.0_05, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 912588064 bytes (870 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 4715 (264040 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.01-pre FML v7.2.156.1060 Minecraft Forge 10.12.1.1060 4 mods loaded, 4 mods active
mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{7.2.156.1060} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.1.1060.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{10.12.1.1060} [Minecraft Forge] (forgeSrc-1.7.2-10.12.1.1060.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
ss97lifemod{1.0.0} [Life Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Profiler Position: N/A (disabled)
Vec3 Pool Size: 596 (33376 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Player Count: 1 / 8; [EntityPlayerMP['Player715'/240, l='New World', x=257.46, y=4.00, z=-746.51]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'

Posted

Yep that is an unregistred tileentity! You need to add this in your common proxy:

 

GameRegistry.registerTileEntity(MyTileEntity.class, "MyTileEntityName");

 

I recommend in your proxy have a method called registerTileEntities().

 

ClientProxy:

 

@Override
public static void registerTileEntities()
{
    super.registerTileEntities();
    ClientRegistry.bindTileEntitySpecialRenderer(TileEntityToilet.class, new TileEntitySpecialRendererToilet());
}

 

CommonProxy:

 

public static void registerTileEntities()
{
    GameRegistry.registerTileEntity(TileEntityToilet.class, "Toilet");
}

 

And in your mod class in preInit add this:

 

proxy.registerTileEntities();

Posted
  On 4/21/2014 at 5:39 PM, Godis_apan said:

Yep that is an unregistred tileentity! You need to add this in your common proxy:

 

GameRegistry.registerTileEntity(MyTileEntity.class, "MyTileEntityName");

 

I recommend in your proxy have a method called registerTileEntities().

 

ClientProxy:

 

@Override
public static void registerTileEntities()
{
    super.registerTileEntities();
    ClientRegistry.bindTileEntitySpecialRenderer(TileEntityToilet.class, new TileEntitySpecialRendererToilet());
}

 

CommonProxy:

 

public static void registerTileEntities()
{
    GameRegistry.registerTileEntity(TileEntityToilet.class, "Toilet");
}

 

And in your mod class in preInit add this:

 

proxy.registerTileEntities();

 

I had it registered anyway. But, now it works so thank you :D

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

    • Cracked Launchers are not supported
    • After some time minecraft crashes with an error. Here is the log https://drive.google.com/file/d/1o-2R6KZaC8sxjtLaw5qj0A-GkG_SuoB5/view?usp=sharing
    • The specific issue is that items in my inventory wont stack properly. For instance, if I punch a tree down to collect wood, the first block I collected goes to my hand. So when I punch the second block of wood to collect it, it drops, but instead of stacking with the piece of wood already in my hand, it goes to the second slot in my hotbar instead. Another example is that I'll get some dirt, and then when I'm placing it down later I'll accidentally place a block where I don't want it. When I harvest it again, it doesn't go back to the stack that it came from on my hotbar, where it should have gone, but rather into my inventory. That means that if my inventory is full, then the dirt wont be picked up even though there should be space available in the stack I'm holding. The forge version I'm using is 40.3.0, for java 1.18.2. I'll leave the mods I'm using here, and I'd appreciate it if anybody can point me in the right direction in regards to figuring out how to fix this. I forgot to mention that I think it only happens on my server but I'm not entirely sure. PLEASE HELP ME! LIST OF THE MODS. aaa_particles Adorn AdvancementPlaques AI-Improvements AkashicTome alexsdelight alexsmobs AmbientSounds amwplushies Animalistic another_furniture AppleSkin Aquaculture aquamirae architectury artifacts Atlas-Lib AutoLeveling AutoRegLib auudio balm betterfpsdist biggerstacks biomancy BiomesOPlenty blockui blueprint Bookshelf born_in_chaos Botania braincell BrassAmberBattleTowers brutalbosses camera CasinoCraft cfm (MrCrayfish’s Furniture Mod) chat_heads citadel cloth-config Clumps CMDCam CNB cobweb collective comforts convenientcurioscontainer cookingforblockheads coroutil CosmeticArmorReworked CozyHome CrabbersDelight crashexploitfixer crashutilities Create CreativeCore creeperoverhaul cristellib crittersandcompanions Croptopia CroptopiaAdditions CullLessLeaves curios curiouslanterns curiouslights Curses' Naturals CustomNPCs CyclopsCore dannys_expansion decocraft Decoration Mod DecorationDelightRefurbished Decorative Blocks Disenchanting DistantHorizons doubledoors DramaticDoors drippyloadingscreen durabilitytooltip dynamic-fps dynamiclights DynamicTrees DynamicTreesBOP DynamicTreesPlus Easy Dungeons EasyAnvils EasyMagic easy_npc eatinganimation ecologics effective_fg elevatorid embeddium emotecraft enchantlimiter EnchantmentDescriptions EnderMail engineersdecor entityculling entity_model_features entity_texture_features epicfight EvilCraft exlinefurniture expandability explosiveenhancement factory-blocks fairylights fancymenu FancyVideo FarmersDelight fast-ip-ping FastSuite ferritecore finsandtails FixMySpawnR Forge Middle Ages fossil FpsReducer2 furnish GamingDeco geckolib goblintraders goldenfood goodall H.e.b habitat harvest-with-ease hexerei hole_filler huge-structure-blocks HunterIllager iammusicplayer Iceberg illuminations immersive_paintings incubation infinitybuttons inventoryhud InventoryProfilesNext invocore ItemBorders itemzoom Jade jei (Just Enough Items) JetAndEliasArmors journeymap JRFTL justzoom kiwiboi Kobolds konkrete kotlinforforge lazydfu LegendaryTooltips libIPN lightspeed lmft lodestone LongNbtKiller LuckPerms Lucky77 MagmaMonsters malum ManyIdeasCore ManyIdeasDoors marbledsarsenal marg mcw-furniture mcw-lights mcw-paths mcw-stairs mcw-trapdoors mcw-windows meetyourfight melody memoryleakfix Mimic minecraft-comes-alive MineTraps minibosses MmmMmmMmmMmm MOAdecor (ART, BATH, COOKERY, GARDEN, HOLIDAYS, LIGHTS, SCIENCE) MobCatcher modonomicon mods_optimizer morehitboxes mowziesmobs MutantMonsters mysticalworld naturalist NaturesAura neapolitan NekosEnchantedBooks neoncraft2 nerb nifty NightConfigFixes nightlights nocube's_villagers_sell_animals NoSeeNoTick notenoughanimations obscure_api oculus oresabovediamonds otyacraftengine Paraglider Patchouli physics-mod Pillagers Gun PizzaCraft placeableitems Placebo player-animation-lib pneumaticcraft-repressurized polymorph PrettyPipes Prism projectbrazier Psychadelic-Chemistry PuzzlesLib realmrpg_imps_and_demons RecipesLibrary reeves-furniture RegionsUnexplored restrictedportals revive-me Scary_Mobs_And_Bosses selene shetiphiancore ShoulderSurfing smoothboot
    • Hi everyone, I'm currently developing a Forge 1.21 mod for Minecraft and I want to display a custom HUD overlay for a minigame. My goal: When the game starts, all players should see an item/block icon (from the base game, not a custom texture) plus its name/text in the HUD – similar to how the bossbar overlay works. The HUD should appear centered above the hotbar (or at a similar prominent spot), and update dynamically (icon and name change as the target item changes). What I've tried: I looked at many online tutorials and several GitHub repos (e.g. SeasonHUD, MiniHUD), but most of them use NeoForge or Forge versions <1.20 that provide the IGuiOverlay API (e.g. implements IGuiOverlay, RegisterGuiOverlaysEvent). In Forge 1.21, it seems that neither IGuiOverlay nor RegisterGuiOverlaysEvent exist anymore – at least, I can't import them and they are missing from the docs and code completion. I tried using RenderLevelStageEvent as a workaround but it is probably not intended for custom HUDs. I am not using NeoForge, and switching the project to NeoForge is currently not an option for me. I tried to look at the original minecraft source code to see how elements like hearts, hotbar etc are drawn on the screen but I am too new to Minecraft modding to understand. What I'm looking for: What is the correct way to add a custom HUD element (icon + text) in Forge 1.21, given that the previous overlay API is missing? Is there a new recommended event, callback, or method in Forge 1.21 for custom HUD overlays, or is everyone just using a workaround? Is there a minimal open-source example repo for Forge 1.21 that demonstrates a working HUD overlay without relying on NeoForge or deprecated Forge APIs? My ideal solution: Centered HUD element with an in-game item/block icon (from the base game's assets, e.g. a diamond or any ItemStack / Item) and its name as text, with a transparent background rectangle. It should be visible to the players when the mini game is running. Easy to update the item (e.g. static variable or other method), so it can change dynamically during the game. Any help, code snippets, or up-to-date references would be really appreciated! If this is simply not possible right now in Forge 1.21, it would also help to know that for sure. Thank you very much in advance!
  • Topics

×
×
  • Create New...

Important Information

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