Jump to content

Recommended Posts

Posted

Hi.

 

My problem is that when I create a block, it's metadata matches the one from the material it's been made, but when I reset the game, that information is gone.

 

I followed the metadaba based subblocks tutorial and the block and item i followed another tutorial:

 

Block:

 

package pablisMod.blocks;

import java.util.List;
import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import pablisMod.entities.TableOneEntity;
import pablisMod.items.TableOneItem;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class TableOneBlock extends BlockContainer {

public static int id;

public TableOneBlock(int id) {
	super(id, Material.wood);
	this.id = id;
	this.setBlockName("Table");
	this.setCreativeTab(CreativeTabs.tabDecorations);
	this.setStepSound(Block.soundWoodFootstep);
	this.setHardness(0.5F);
	this.setTextureFile("/pablisMod/textures/TableOneIcon.png");
	this.setRequiresSelfNotify(); // absolutely needed
}	

public int quantityDropped(Random par1Random) {
	return 1;
}

@Override
public int getRenderType() {
	return -1;
}

@Override
public int getBlockTextureFromSideAndMetadata (int side, int metadata) {
	return 16 + metadata;
}

@Override
public TileEntity createNewTileEntity(World var1) {
	return null;
}	

@Override
public TileEntity createTileEntity(World world, int metadata) {
	return new TableOneEntity();
}

@Override
public boolean renderAsNormalBlock() {
	return false;
}

@Override
public boolean isBlockSolid(IBlockAccess par1iBlockAccess, int par2,
		int par3, int par4, int par5) {		
	return super.isBlockSolid(par1iBlockAccess, par2, par3, par4, par5);
}

@Override
public boolean isOpaqueCube() {
	return false;
}	

@Override
public boolean canPlaceTorchOnTop(World world, int x, int y, int z) {		
	return super.canPlaceTorchOnTop(world, x, y, z);
}

@Override
public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i,
		int j, int k, int l) {
	return false;
}

@SideOnly(Side.CLIENT)
public void getSubBlocks(int par1, CreativeTabs tab, List subItems) {
	for (int ix = 0; ix < 4; ix++) {
		subItems.add(new ItemStack(this, 1, ix));
	}	

}

@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4,
		EntityLiving par5EntityLiving) {
	int var6 = MathHelper
			.floor_double((double) (par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

	switch (var6) {
	case 0:
		par1World.setBlockMetadataWithNotify(par2, par3, par4, 2);
		break;
	case 1:
		par1World.setBlockMetadataWithNotify(par2, par3, par4, 5);
		break;
	case 2:
		par1World.setBlockMetadataWithNotify(par2, par3, par4, 4);
		break;
	case 3:
		par1World.setBlockMetadataWithNotify(par2, par3, par4, 3);
		break;
	}
}

public static Block registerBlock(int id) {
	Block m_fieldName = new TableOneBlock(id);


	GameRegistry.registerBlock(m_fieldName, TableOneItem.class,
			"TableOneItem");
	GameRegistry.registerTileEntity(TableOneEntity.class, "TableOneEntity");

	ItemStack stack = new ItemStack(m_fieldName, 1, 0);
	LanguageRegistry.addName(stack, "Oak Table");
	GameRegistry.addRecipe(stack, "yyy", "x x", "x x", 'x', new ItemStack(
			Item.stick, 1, 0), 'y', new ItemStack(Block.woodSingleSlab, 1,
			0));		

	stack = new ItemStack(m_fieldName, 1, 1);
	LanguageRegistry.addName(stack, "Spruce Table");
	GameRegistry.addRecipe(stack, "yyy", "x x", "x x", 'x', new ItemStack(
			Item.stick, 1, 0), 'y', new ItemStack(Block.woodSingleSlab, 1,
			1));

	stack = new ItemStack(m_fieldName, 1, 2);
	LanguageRegistry.addName(stack, "Birch Table");
	GameRegistry.addRecipe(stack, "yyy", "x x", "x x", 'x', new ItemStack(
			Item.stick, 1, 0), 'y', new ItemStack(Block.woodSingleSlab, 1,
			2));

	stack = new ItemStack(m_fieldName, 1, 3);
	LanguageRegistry.addName(stack, "Jungle Table");
	GameRegistry.addRecipe(stack, "yyy", "x x", "x x", 'x', new ItemStack(
			Item.stick, 1, 0), 'y', new ItemStack(Block.woodSingleSlab, 1,
			3));

	return m_fieldName;
}
}

 

Item:

 

package pablisMod.items;

import java.util.List;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;

public class TableOneItem extends ItemBlock {

private static final String[] subTypes = {"Oak ", "Spruce ", "Birch ", "Jungle "};

public TableOneItem(int id) {
	super(id);

	maxStackSize = 16;
	setCreativeTab(CreativeTabs.tabDecorations);
	setItemName("Table");
	setHasSubtypes(true);
}

public static String[] getSubtypes() {
	return subTypes;
}

@Override
public int getMetadata (int damageValue) {
	return damageValue;
}

@Override
public String getItemNameIS(ItemStack par1ItemStack) {

	return subTypes[par1ItemStack.getItemDamage()] + getItemName();
}
}

 

Renderer (The renderer doesn't use the metadata yet because is always changing):

 

package pablisMod.renderers;

import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11;
import pablisMod.models.TableOneModel;

public class TableOneRenderer extends TileEntitySpecialRenderer {

private TableOneModel model;
private String texture;

public TableOneRenderer() {
	model = new TableOneModel();	
	texture = "/pablisMod/textures/SpruceTableOne.png";
}

int ang = 0;

public void renderTileEntityAt(TileEntity entity, double d, double d1,
		double d2, float f) {

	int metadata = entity.getBlockMetadata();

	int rotationAngle = 0;

	switch(metadata % 4){
	case 0:
		rotationAngle = 0;
		break;
	case 1:
		rotationAngle = 90;
		break;
	case 2:
		rotationAngle = 180;
		break;
	case 3:
		rotationAngle = 270;
		break;
	}

	int i = 0;

	if (entity.worldObj != null)
	{
		i = (entity.worldObj.getBlockMetadata(entity.xCoord, entity.yCoord,
				entity.zCoord));
	}

	GL11.glPushMatrix();
	GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F,
			(float) d2 + 0.5F);
	GL11.glRotatef(rotationAngle, 0.0F, 1.0F, 0.0F);		
	GL11.glScalef(1.0F, -1F, -1F);
	bindTextureByName(texture);
	model.renderModel(0.0625F);
	GL11.glPopMatrix();
}

}

 

How can I save the metadata of the block and mantain the same number on every world load.

Posted

ok

1, if you're not doing any animation and only renderign based on metadata, use ISBRH not TESR

2, dont use this, "@SideOnly(Side.CLIENT)" ever, it only causes confusion

nothing good ever came out of that

3, dont override this method: "public TileEntity createNewTileEntity(World var1) "

3, to read/write from TE you need to implement readFromNBT and writeToNBT

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted
  On 8/14/2013 at 7:56 PM, hydroflame said:

ok

1, if you're not doing any animation and only renderign based on metadata, use ISBRH not TESR

2, dont use this, "@SideOnly(Side.CLIENT)" ever, it only causes confusion

nothing good ever came out of that

3, dont override this method: "public TileEntity createNewTileEntity(World var1) "

3, to read/write from TE you need to implement readFromNBT and writeToNBT

 

I forgot to mention that I'm using minecraft 1.4.7 because of some mods that are incompatible (or don't exists) for 1.6.x and I have a big world and I don't want to lose it.

 

I cant find those interfaces you mentioned (readFromNBT, writeFromNBT) and what does ISBRH stand for?

 

I'm a noob at Minecraft code yet...

Posted
  Quote
ISBRH is hydroflame way of calling ISimpleBlockRenderingHandler.

 

ISimpleBlockRenderingHandler

ISBRH ... i wouldnt say its my way but i probably should be more clear whenever someone might not know about it :(

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

Now, here's another thing I don't understand and it's the final thing i need to grasp:

 

I've found the Basic Tile Entity tutorial on the forge tutorials page and it says to do the following:

 

@Override
public TileEntity createTileEntity(World world, int metadata) {
	try
    {			
		TableOneEntity entity = new TableOneEntity();
		entity.setTextureID(metadata);
		//System.out.println("metadata " + metadata);
		return entity;
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }		
}

 

That's fine. I can save the block's TileEntity with the metadata from the block, but whenever the world restarts, the entity get's overwritten by a new one and the metadata changes to some other thing and I can't get the old TileEntity from the block instead of creating a new one with the params provided by this method.

 

How do you do it usually?

 

 

Posted
  Quote

Anybody?

 

Can't figure this out.

 

Whenever i reload my world, the tile entity of the block gets overwritten by the new block metadata wich equals (apparently) to the direction that the block was placed.

 

Nevermind this. It was because I followed some tutorial and at some point it was changing the block's metadata. I'm able now to render the texture based on metadata.

 

 

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

    • 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&#39;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!
    • The simple answer is there is not an easy way. You would need to know how to program in Java, as well as at least some familiarity with how Forge works so you could port the differences. You would also need the sourcecode for the original mod, and permission from the author to modify it, if they did not use some sort of open source license. So it's not impossible, but it would take some effort, but doing so would open up a whole new world of possibilities for you!
  • Topics

×
×
  • Create New...

Important Information

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