Jump to content

Recommended Posts

Posted

Zombie Lantern name is overwriting all other lantern names. Maybe I'm missing something?

 

 

~*Blocks class*~

package lanterns.blocks;

import lanterns.Reference;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

public class Blocks {

public static Block jackolantern;
public static Block creeperlantern;
public static Block zombielantern;

public static void init(){


	jackolantern =  new BlockJackolantern(BlockIds.JACOLANTERN_ID, Material.pumpkin);
	GameRegistry.registerBlock(jackolantern, BlockIds.JACKOLANTERN_KEY);

	  
	  
	creeperlantern = new BlockCreeperLantern(BlockIds.CREEPER_ID, Material.pumpkin);
	GameRegistry.registerBlock(creeperlantern, BlockIds.CREEPER_KEY);


	zombielantern = new BlockZombieLantern(BlockIds.ZOMBIE_ID, Material.pumpkin);
    GameRegistry.registerBlock(zombielantern, BlockIds.ZOMBIE_KEY);

    
}

public static void addNames(){
	LanguageRegistry.addName(jackolantern, BlockIds.JACKOLANTERN_NAME);
	LanguageRegistry.addName(creeperlantern, BlockIds.CREEPER_NAME);
	LanguageRegistry.addName(zombielantern, BlockIds.ZOMBIE_NAME);
}
public static void recipes(){
	GameRegistry.addShapelessRecipe(new ItemStack(Blocks.jackolantern), new ItemStack(Block.pumpkinLantern), new ItemStack(Block.torchWood));
	GameRegistry.addShapelessRecipe(new ItemStack(Blocks.creeperlantern), new ItemStack(Block.pumpkinLantern), new ItemStack(Item.gunpowder));
	GameRegistry.addShapelessRecipe(new ItemStack(Blocks.zombielantern),new ItemStack(Block.pumpkinLantern), new ItemStack(Item.rottenFlesh));
}


}

 

~*BlockIds*~

package lanterns.blocks;

public class BlockIds {


public static final String TEXTURE_LOCATION = "lanterns";

//jackolantern
public static int JACOLANTERN_ID = 1000;
public static final String JACKOLANTERN_UNLOCALIZED_NAME = "jackolantern";
public static final String JACKOLANTERN_KEY = "jackolantern";
public static final String JACKOLANTERN_NAME = "Jack-O-Lantern";
public static final String JACOLANTERNTOP = "jackolantern1";
    public static final String JACKOLANTERNSIDE = "jackolantern2";
    public static final String JACKOLANTERNFRONT = "jackolantern0";
    
    //creeper lantern
public static int CREEPER_ID = 1001;
public static final String CREEPER_UNLOCALIZED_NAME = "creeperlantern";
public static final String CREEPER_KEY = "creeperlantern";
public static final String CREEPER_NAME = "Creeper Lantern";
public static final String CREEPERTOP = "creeper_top";
    public static final String CREEPERSIDE = "creeper_side";
    public static final String CREEPERFRONT = "creeper_front";
    
    //ZOMBIE lantern
  	public static int ZOMBIE_ID = 1002;
  	public static final String ZOMBIE_UNLOCALIZED_NAME = "zombielantern";
  	public static final String ZOMBIE_KEY = "zombielantern";
  	public static final String ZOMBIE_NAME = "Zombie Lantern";
  	public static final String ZOMBIETOP = "zombie_top";
    public static final String ZOMBIESIDE = "zombie_side";
    public static final String ZOMBIEFRONT = "zombie_front";
    

}

 

~*Main Class*~

package lanterns;

import lanterns.blocks.BlockJackolantern;
import lanterns.blocks.Blocks;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = Reference.ID, name = Reference.NAME, version = Reference.VERSION)
@NetworkMod(clientSideRequired = true, serverSideRequired = false, channels = Reference.CHANNEL)
public class Lanterns {

public static final String modid = "lanterns";



@EventHandler
public void load(FMLInitializationEvent event){

Blocks.init();
Blocks.addNames();
Blocks.recipes();
}

}

Posted

Can i see the Jackolantern, Creeperlantern and Zombielantern class?

 

Sure :

 

Jackolantern

package lanterns.blocks;

import java.util.List;

import lanterns.Lanterns;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDirectional;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockJackolantern extends BlockDirectional{

public BlockJackolantern(int id, Material material) {
	super(id, material.pumpkin);
	this.setCreativeTab(CreativeTabs.tabBlock);
	this.setLightValue(1F);

}


//icon junk
@SideOnly(Side.CLIENT)
    private Icon topIcon;
    @SideOnly(Side.CLIENT)
    private Icon faceIcon;
    @SideOnly(Side.CLIENT)
    private Icon blockIcon;
    @SideOnly(Side.CLIENT)
    
    
    @Override
    public void registerIcons(IconRegister register){
    	 topIcon = register.registerIcon(BlockIds.TEXTURE_LOCATION + ":" + BlockIds.JACOLANTERNTOP);
         faceIcon = register.registerIcon(BlockIds.TEXTURE_LOCATION + ":" + BlockIds.JACKOLANTERNFRONT);
         blockIcon = register.registerIcon(BlockIds.TEXTURE_LOCATION + ":" + BlockIds.JACKOLANTERNSIDE);
    }
    
    @SideOnly(Side.CLIENT)
    @Override
    
    /**
     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
     */
    public Icon getIcon(int side, int metadata)
    {
      if (side == 1) return this.topIcon;
      else if (side == 0) return this.topIcon;
      else if (metadata == 2 && side == 2) return this.faceIcon;
      else if (metadata == 3 && side == 5) return this.faceIcon;
      else if (metadata == 0 && side == 3) return this.faceIcon;
      else if (metadata == 1 && side == 4) return this.faceIcon;
      else return this.blockIcon;
    }
    
    public void onBlockPlacedBy(World par1World, int x, int y, int z, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
    {
        int whichDirectionFacing = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
        par1World.setBlockMetadataWithNotify(x, y, z, whichDirectionFacing, 2);
    }
   
}

 

Creeper lantern

package lanterns.blocks;

import net.minecraft.block.BlockDirectional;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockCreeperLantern extends BlockDirectional {
public BlockCreeperLantern(int id, Material material){
	super(id, material.pumpkin);
	this.setCreativeTab(CreativeTabs.tabBlock);
	this.setLightValue(1F);
}

//icon junk

@SideOnly(Side.CLIENT)
private Icon topIcon;
@SideOnly(Side.CLIENT)
private Icon faceIcon;
@SideOnly(Side.CLIENT)
private Icon blockIcon;

@Override
public void registerIcons(IconRegister register){
	topIcon = register.registerIcon(BlockIds.TEXTURE_LOCATION + ":" + BlockIds.CREEPERTOP);
	faceIcon = register.registerIcon(BlockIds.TEXTURE_LOCATION + ":" + BlockIds.CREEPERFRONT);
	blockIcon = register.registerIcon(BlockIds.TEXTURE_LOCATION + ":" + BlockIds.CREEPERSIDE);
}


@SideOnly(Side.CLIENT)
    @Override
    public Icon getIcon(int side, int metadata){
	if (side == 1) return this.topIcon;
	else if (side == 0) return this.topIcon;
	else if (metadata == 2 && side == 2) return this.faceIcon;
      else if (metadata == 3 && side == 5) return this.faceIcon;
      else if (metadata == 0 && side == 3) return this.faceIcon;
      else if (metadata == 1 && side == 4) return this.faceIcon;
      else return this.blockIcon;
}
   public void onBlockPlacedBy(World par1World, int x, int y, int z, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
    {
        int whichDirectionFacing = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
        par1World.setBlockMetadataWithNotify(x, y, z, whichDirectionFacing, 2);
    }
}

 

Zombie Lantern

 package lanterns.blocks;

import net.minecraft.block.BlockDirectional;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockZombieLantern extends BlockDirectional {
public BlockZombieLantern (int id, Material material)
{
	super(id, Material.pumpkin);
	this.setCreativeTab(CreativeTabs.tabBlock);
	this.setLightValue(1F);
}

//icon junk

	@SideOnly(Side.CLIENT)
	private Icon topIcon;
	@SideOnly(Side.CLIENT)
	private Icon faceIcon;
	@SideOnly(Side.CLIENT)
	private Icon blockIcon;

	@Override
	public void registerIcons(IconRegister register){
		topIcon = register.registerIcon(BlockIds.TEXTURE_LOCATION + ":" + BlockIds.ZOMBIETOP);
		faceIcon = register.registerIcon(BlockIds.TEXTURE_LOCATION + ":" + BlockIds.ZOMBIEFRONT);
		blockIcon = register.registerIcon(BlockIds.TEXTURE_LOCATION + ":" + BlockIds.ZOMBIESIDE);
	}


	@SideOnly(Side.CLIENT)
    @Override
    public Icon getIcon(int side, int metadata){
		if (side == 1) return this.topIcon;
		else if (side == 0) return this.topIcon;
		else if (metadata == 2 && side == 2) return this.faceIcon;
	      else if (metadata == 3 && side == 5) return this.faceIcon;
	      else if (metadata == 0 && side == 3) return this.faceIcon;
	      else if (metadata == 1 && side == 4) return this.faceIcon;
	      else return this.blockIcon;
	}
	   public void onBlockPlacedBy(World par1World, int x, int y, int z, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
	    {
	        int whichDirectionFacing = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
	        par1World.setBlockMetadataWithNotify(x, y, z, whichDirectionFacing, 2);
	    }
}

Posted

I seem to be having the same problem (if I'm understanding the OP correctly).

I have 5 blocks.  2 of them are furnaces, so they each have a tile entity and each take up 2 ID's (one for idle, one for active).  2 others are custom crafting tables, one which has a 3x3 grid and another which has a 4x4 grid.  The last is an ore which does have generation code.  The ore and 1st crafting table show up with the exact same name that the 2nd crafting table has.  The two furnaces are fine.

 

Yes they all have different unlocalized names.

 

EDIT: Nevermind, fixed it.  The answer to the problem was that I had the unlocalized names in my Mod ID's class but didn't set them for some of the blocks.  Just put "this.setUnlocalizedName(unlocalized name goes here)" in the constructor of each of your blocks and put the block's unlocalized name in the parentheses.

Posted

I seem to be having the same problem (if I'm understanding the OP correctly).

I have 5 blocks.  2 of them are furnaces, so they each have a tile entity and each take up 2 ID's (one for idle, one for active).  2 others are custom crafting tables, one which has a 3x3 grid and another which has a 4x4 grid.  The last is an ore which does have generation code.  The ore and 1st crafting table show up with the exact same name that the 2nd crafting table has.  The two furnaces are fine.

 

Yes they all have different unlocalized names.

 

EDIT: Nevermind, fixed it.  The answer to the problem was that I had the unlocalized names in my Mod ID's class but didn't set them for some of the blocks.  Just put "this.setUnlocalizedName(unlocalized name goes here)" in the constructor of each of your blocks and put the block's unlocalized name in the parentheses.

 

Thank you that worked. I dont know why it worked but it did... If you know why let me know I'd love an explanation of that one.

Posted

Hi

 

It worked because the LanguageRegistry uses the Block's unlocalized_name field to identify the Block.  This is set by the this.setUnlocalizedName() in the Block's constructor.

 

 

LanguageRegistry::
    public void addNameForObject(Object objectToName, String lang, String name)
    {
        String objectName;
        if (objectToName instanceof Item) {
            objectName=((Item)objectToName).getUnlocalizedName();
        } else if (objectToName instanceof Block) {
            objectName=((Block)objectToName).getUnlocalizedName();
        } else if (objectToName instanceof ItemStack) {
            objectName=((ItemStack)objectToName).getItem().getUnlocalizedName((ItemStack)objectToName);
        } else {
            throw new IllegalArgumentException(String.format("Illegal object for naming %s",objectToName));
        }
        objectName+=".name";
        addStringLocalization(objectName, lang, name);

 

i.e.

            objectName=((Block)objectToName).getUnlocalizedName();

// ....

        addStringLocalization(objectName, lang, name);

 

So - if you don't set the unlocalizedname inside the Block, all three of your blocks have the same default unlocalizedname.  So each time you add a new name

eg

LanguageRegistry.addName(jackolantern, BlockIds.JACKOLANTERN_NAME);

 

it just overwrites the same spot in the LanguageRegistry.

 

-TGG

Posted

so do I always set unlocalized name in the constructor regardless of block, item, tile entity, etc.?

 

...Yes, or it will have a default unlocalized name.

 

If it has the default unlocalized name, then it will be identical to every other block with the default unlocalized name and that can't be uniquely localized!

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.

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 managed to fix it by reinstalling the modpack and re-add all the extra mods I've had previously.
    • Ah, it appears I spoke too soon, I still need a little help here. I now have the forceloading working reliably.  However, I've realized it's not always the first tick that loads the entity.  I've seen it take anywhere from 2-20ish to actually go through, in which time my debugging has revealed that the chunk is loaded, but during which time calling  serverLevelIn.getEntity(uuidIn) returns a null result.  I suspect this has to do with queuing and how entities are loaded into the game.  While not optimal, it's acceptable, and I don't think there's a whole ton I can do to avoid it. However, my concern is that occasionally teleporting an entity in this manner causes a lag spike.  It's not every time and gives the appearance of being correlated with when other chunks are loading in.  It's also not typically a long spike, but can last a second or two, which is less than ideal.  The gist of how I'm summoning is here (although I've omitted some parts that weren't relevant.  The lag occurs before the actual summon so I'm pretty confident it's the loading, and not the actual summon call). ChunkPos chunkPos = new ChunkPos(entityPosIn); if (serverLevelIn.areEntitiesLoaded(chunkPos.toLong())) { boolean isSummoned = // The method I'm using for actual summoning is called here. Apart from a few checks, the bulk of it is shown later on. if (isSummoned) { // Code that runs here just notifies the player of the summon, clears it from the queue, and removes the forceload } } else { // I continue forcing the chunk until the summon succeeds, to make sure it isn't inadvertently cleared ForgeChunkManager.forceChunk(serverLevelIn, MODID, summonPosIn, chunkPos.x, chunkPos.z, true, true); } The summon code itself uses serverLevelIn.getEntity(uuidIn) to retrieve the entity, and moves it as such.  It is then moved thusly: if (entity.isAlive()) { entity.moveTo(posIn.getX(), posIn.getY(), posIn.getZ()); serverLevelIn.playSound(null, entity, SoundEvents.ENDERMAN_TELEPORT, SoundSource.NEUTRAL, 1.0F, 1.0F); return true; } I originally was calling .getEntity() more frequently and didn't have the check for whether or not entities were loaded in place to prevent unnecessary code calls, but even with those safety measures in place, the lag still persists.  Could this just be an issue with 1.18's lack of optimization in certain areas?  Is there anything I can do to mitigate it?  Is there a performance boosting mod I could recommend alongside my own to reduce the chunk loading lag? At the end of the day, it does work, and I'm putting measures in place to prevent players from abusing the system to cause lag (i.e. each player can only have one queued summon at a time-- trying to summon another replaces the first call).  It's also not an unacceptable level of lag, IMO, given the infrequency of such calls, and the fact that I'm providing the option to toggle off the feature if server admins don't want it used.  However, no amount of lag is ideal, so if possible I'd love to find a more elegant solution-- or at least a mod recommendation to help improve it. Thanks!
    • When i start my forge server its on but when i try to join its come a error Internal Exception: java.lang.OutOfMemoryError: Requested array size exceeds VM limit Server infos: Linux Minecraft version 1.20.1 -Xmx11G -Xms8G
    • Also add the latest.log from your logs-folder
  • Topics

×
×
  • Create New...

Important Information

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