Jump to content

Recommended Posts

Posted

Hello! My block Drill's name is not displaying correctly. The block has the three properties, PropertyEnum for types, PropertyDirection for model rotation and PropertyBool for redstone activation. For some reason, both the basic drill and advanced drill, in the inventory show the same block.drill.basic.name. Yet, the placed blocks display (using Waila) the block.drill.basic.name and block.drill.advanced.name. I'm presuming it's an issue with it's unlocalized name in my block's BlockDrill.java?

Basic Drill Image https://ibb.co/jpWM16

Advanced Drill Image https://ibb.co/d1XiER

BlockDrill.java 

package archieab.andustry.blocks;

import java.util.List;

import archieab.andustry.Reference;
import archieab.andustry.blocks.item.IMetaBlockName;
import archieab.andustry.handlers.EnumHandler.MacTypes;
import net.minecraft.block.Block;
import net.minecraft.block.BlockPistonBase;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;

public class BlockDrill extends Block implements IMetaBlockName {

	public static final PropertyEnum TYPE = PropertyEnum.create("type", MacTypes.class);
	public static final PropertyDirection FACING = PropertyDirection.create("facing");
	public static final PropertyBool ACTIVATED = PropertyBool.create("activated");
	
	public BlockDrill(String unlocalizedName) {
		super(Material.IRON);
		this.setUnlocalizedName(unlocalizedName);
		this.setRegistryName(new ResourceLocation(Reference.MODID, unlocalizedName));
		this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, MacTypes.BASIC).withProperty(FACING, EnumFacing.NORTH).withProperty(ACTIVATED, Boolean.valueOf(false)));
	}
	
	@Override
	protected BlockStateContainer createBlockState() {
		return new BlockStateContainer(this, new IProperty[] {TYPE,FACING,ACTIVATED});
	}
	
	@Override
	public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY,
			float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
		return this.getDefaultState().withProperty(FACING, EnumFacing.getDirectionFromEntityLiving(pos, placer)).withProperty(ACTIVATED, Boolean.valueOf(false)).withProperty(TYPE, getStateFromMeta(meta * EnumFacing.values().length).getValue(TYPE));
	}
	
	@Override
	public int getMetaFromState(IBlockState state) {
		MacTypes type = (MacTypes) state.getValue(TYPE);
		EnumFacing facing = (EnumFacing) state.getValue(FACING);
		int meta = type.getID() * EnumFacing.values().length + facing.ordinal();
		return meta;
	}
	
	@Override
	public IBlockState getStateFromMeta(int meta) {
		MacTypes type = MacTypes.values()[(int)(meta / EnumFacing.values().length) % MacTypes.values().length];
		EnumFacing facing = EnumFacing.values()[meta % EnumFacing.values().length];
		return this.getDefaultState().withProperty(TYPE, type).withProperty(FACING, facing);
	}
	
	@Override
	public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos,
			EntityPlayer player) {
		return new ItemStack(Item.getItemFromBlock(this), 1, (int) (getMetaFromState(world.getBlockState(pos)) / EnumFacing.values().length));
	}
	
	@Override
	public int damageDropped(IBlockState state) {
		return (int) (getMetaFromState(state) / EnumFacing.values().length);
	}

	@Override
	public String getSpecialName(ItemStack stack) {
		return MacTypes.values()[stack.getItemDamage() / EnumFacing.values().length].getName();
	}

    @Override
    public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list) {
        for (int i = 0; i < MacTypes.values().length; i++) {
            list.add(new ItemStack(itemIn, 1, i));
        }
    }
	
}

Any help would be greatly appreciated!

Posted
Just now, Sunser said:

Can you show us your language file (en_US.lang I guess) ?

It's not to do with the lang. I haven't added the block's into the lang purely so you can see the raw name. I'm almost certain the issue is to do with it's SpecialName or UnlocalizedName.

Posted
1 minute ago, Sunser said:

Sorry, my bad.

Have you check when you register your blocks that the String is correct ? It could be a copy/paste which has not been edited.

Are you talking about my ModBlocks.java? If so, here's the code:

package archieab.andustry.init;

import archieab.andustry.Andustry;
import archieab.andustry.Reference;
import archieab.andustry.blocks.BlockCopperOre;
import archieab.andustry.blocks.BlockDrill;
import archieab.andustry.blocks.BlockMachineFrameAdvanced;
import archieab.andustry.blocks.BlockMachineFrameBasic;
import archieab.andustry.blocks.BlockTinOre;
import archieab.andustry.blocks.BlockCoalCatalystBlock;
import archieab.andustry.blocks.item.ItemBlockDrill;
import archieab.andustry.handlers.EnumHandler;
import archieab.andustry.util.Utils;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class ModBlocks {

	public static Block copper_ore;
	public static Block tin_ore;
	public static Block machineframebasic;
	public static Block machineframeadvanced;
	public static Block drill;
	public static Block coalcatalystblock;
	
	public static void init() {
		copper_ore = new BlockCopperOre("copper_ore", "copper_ore");
		tin_ore = new BlockTinOre("tin_ore", "tin_ore");
		machineframebasic = new BlockMachineFrameBasic("machineframebasic", "machineframebasic");
		machineframeadvanced = new BlockMachineFrameAdvanced("machineframeadvanced", "machineframeadvanced");
		drill = new BlockDrill("drill");
		coalcatalystblock = new BlockCoalCatalystBlock("coal_catalyst_block", "coal_catalyst_block");
	}
	
	public static void register() {
		registerBlock(copper_ore);
		registerBlock(tin_ore);
		registerBlock(machineframebasic);
		registerBlock(machineframeadvanced);
		registerBlock(drill, new ItemBlockDrill(drill));
		registerBlock(coalcatalystblock);
	}
	
	public static void registerRenders() {
		registerRender(copper_ore);
		registerRender(tin_ore);
		registerRender(machineframebasic);
		registerRender(machineframeadvanced);
		for(int i = 0; i < EnumHandler.MacTypes.values().length; i++) {
			registerRender(drill, i, "block_drill_" + EnumHandler.MacTypes.values()[i].getName());
		}
		registerRender(coalcatalystblock);
	}
	
	public static void registerBlock(Block block) {
		block.setCreativeTab(Andustry.Blocks);
		GameRegistry.register(block);
		GameRegistry.register(new ItemBlock(block).setRegistryName(block.getRegistryName()));
		Utils.getLogger().info("Registered Block: " + block.getUnlocalizedName().substring(5));
	}
	
	public static void registerBlock(Block block, ItemBlock itemBlock) {
		block.setCreativeTab(Andustry.Blocks);
		GameRegistry.register(block);
		GameRegistry.register(itemBlock.setRegistryName(block.getRegistryName()));
		Utils.getLogger().info("Registered Block: " + block.getUnlocalizedName().substring(5));
	}
	
	public static void registerRender(Block block) {
		ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(new ResourceLocation(Reference.MODID, block.getUnlocalizedName().substring(5)), "inventory"));
		Utils.getLogger().info("Registered render for " + block.getUnlocalizedName().substring(5));
	}
	
	public static void registerRender(Block block, int meta, String fileName) {
		ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), meta, new ModelResourceLocation(new ResourceLocation(Reference.MODID, fileName), "inventory"));
		Utils.getLogger().info("Register render for " + block.getUnlocalizedName().substring(5));
	}
	
}

 

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

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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