Jump to content

[1.12] Minecraft rendering wrong variant/axis


Lennart247

Recommended Posts

 

 

 

 

I am currently trying to make a custom tree, the blocks I created for it (leaves and log) are working, and I think the worldgenerator (which is a modified copy of the birch generator) is working too. However the game sometimes seems to render the wrong blockstate of the log, until I right click the block, or update it otherwise. I added all code I use below (although I think only the WorldGen Code and BlockLog Code are important). AFAIK the Worldgen places the blocks correctly, as I do get the right output in my console ([lennart247.test.lennartsmod.worldgen.WorldGenCherryTree:generate:130]: lennartsmod:block_cherry_bark[axis=y,type=cherry]). But most of the time the game displays the wrong blockstate, until updating the block.

Does anyone have an idea why this is happening?

WorldGen Code:

Spoiler

package lennart247.test.lennartsmod.worldgen;

import java.util.Random;

import lennart247.test.lennartsmod.api.EnumWoodType;
import lennart247.test.lennartsmod.blocks.BlockModBark;
import lennart247.test.lennartsmod.blocks.BlockModLeaves;
import lennart247.test.lennartsmod.init.ModBlocks;
import net.minecraft.block.BlockOldLeaf;
import net.minecraft.block.BlockOldLog;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenAbstractTree;

public class WorldGenCherryTree extends WorldGenAbstractTree{

	
	private static final IBlockState LOG = ModBlocks.block_cherry_bark.getDefaultState().withProperty(BlockModBark.LOG_AXIS, BlockModBark.EnumAxis.Y).withProperty(BlockModBark.TYPE, EnumWoodType.CHERRY);
	private static final IBlockState LEAF = ModBlocks.block_cherry_leaves.getDefaultState().withProperty(BlockModLeaves.TYPE, EnumWoodType.CHERRY);
	private final boolean useExtraRandomHeight;

	public WorldGenCherryTree(boolean notify, boolean useExtraRandomHeightIn) {
		super(notify);
		useExtraRandomHeight = true;
	}

	@Override
	public boolean generate(World worldIn, Random rand, BlockPos position) {
		// TODO Auto-generated method stub
		int i = rand.nextInt(3) + 5;

        if (this.useExtraRandomHeight)
        {
            i += rand.nextInt(7);
        }

        boolean flag = true;

        if (position.getY() >= 1 && position.getY() + i + 1 <= 256)
        {
            for (int j = position.getY(); j <= position.getY() + 1 + i; ++j)
            {
                int k = 1;

                if (j == position.getY())
                {
                    k = 0;
                }

                if (j >= position.getY() + 1 + i - 2)
                {
                    k = 2;
                }

                BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();

                for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l)
                {
                    for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1)
                    {
                        if (j >= 0 && j < worldIn.getHeight())
                        {
                            if (!this.isReplaceable(worldIn, blockpos$mutableblockpos.setPos(l, j, i1)))
                            {
                                flag = false;
                            }
                        }
                        else
                        {
                            flag = false;
                        }
                    }
                }
            }

            if (!flag)
            {
                return false;
            }
            else
            {
                BlockPos down = position.down();
                IBlockState state = worldIn.getBlockState(down);
                boolean isSoil = state.getBlock().canSustainPlant(state, worldIn, down, net.minecraft.util.EnumFacing.UP, (net.minecraft.block.BlockSapling)Blocks.SAPLING);

                if (isSoil && position.getY() < worldIn.getHeight() - i - 1)
                {
                    state.getBlock().onPlantGrow(state, worldIn, down, position);

                    for (int i2 = position.getY() - 3 + i; i2 <= position.getY() + i; ++i2)
                    {
                        int k2 = i2 - (position.getY() + i);
                        int l2 = 1 - k2 / 2;

                        for (int i3 = position.getX() - l2; i3 <= position.getX() + l2; ++i3)
                        {
                            int j1 = i3 - position.getX();

                            for (int k1 = position.getZ() - l2; k1 <= position.getZ() + l2; ++k1)
                            {
                                int l1 = k1 - position.getZ();

                                if (Math.abs(j1) != l2 || Math.abs(l1) != l2 || rand.nextInt(2) != 0 && k2 != 0)
                                {
                                    BlockPos blockpos = new BlockPos(i3, i2, k1);
                                    IBlockState state2 = worldIn.getBlockState(blockpos);

                                    if (state2.getBlock().isAir(state2, worldIn, blockpos) || state2.getBlock().isAir(state2, worldIn, blockpos))
                                    {
                                        this.setBlockAndNotifyAdequately(worldIn, blockpos, LEAF);
                                        System.out.println(LEAF.toString());
                                    }
                                }
                            }
                        }
                    }

                    for (int j2 = 0; j2 < i; ++j2)
                    {
                        BlockPos upN = position.up(j2);
                        IBlockState state2 = worldIn.getBlockState(upN);

                        if (state2.getBlock().isAir(state2, worldIn, upN) || state2.getBlock().isLeaves(state2, worldIn, upN))
                        {
                            this.setBlockAndNotifyAdequately(worldIn, position.up(j2), LOG);
                            System.out.println(LOG.toString());
                        }
                    }

                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
        else
        {
            return false;
        }
		
	}

}

 

BlockLog Code:

Spoiler

package lennart247.test.lennartsmod.blocks;

import java.beans.PropertyDescriptor;

import lennart247.test.lennartsmod.api.EnumWoodType;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLog;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
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.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;

public class BlockModBark extends BlockLog{

	
	public static final PropertyEnum<EnumWoodType> TYPE = PropertyEnum.<EnumWoodType>create("type", EnumWoodType.class);
//	public static final PropertyDirection FACING = PropertyDirection.create("facing");
	 public static final PropertyEnum<BlockModBark.EnumAxis> LOG_AXIS = PropertyEnum.<BlockModBark.EnumAxis>create("axis", BlockModBark.EnumAxis.class);
	
	public BlockModBark(String type) {
		
    	this.blockSoundType = SoundType.WOOD;
    	switch(type.toLowerCase()){
    	case "cherry":
    		this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumWoodType.CHERRY).withProperty(LOG_AXIS, BlockModBark.EnumAxis.Y));
    	case "banana":
    		this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumWoodType.BANANA));
    		
    	}
    	this.setRegistryName("block_" + type + "_bark");
    	this.setUnlocalizedName("block_" + type + "_bark");
        this.setCreativeTab(CreativeTabs.DECORATIONS);
	}
	
	public void initModel(){
    	ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
    }
	public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
    {
    	for(int i = 0; i < EnumWoodType.values().length; i++){
    		items.add(new ItemStack(this, 1, i));
    	}
    }
	
	public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(TYPE, EnumWoodType.values()[meta])/*BlockPlanks.EnumType.byMetadata(meta & 7)*/;
    }
	
	public int getMetaFromState(IBlockState state)
    {
    	
    	EnumWoodType type = (EnumWoodType) state.getValue(TYPE);
    	return type.getID();
//        int i = 0;
//        i = i | (state.getValue(TYPE)).getMetadata();
//        i = i | ((Integer)state.getValue(STAGE)).intValue() << 3;
//        return i;
    }
	protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {TYPE,LOG_AXIS});
    }
	public static enum EnumAxis implements IStringSerializable
    {
        X("x"),
        Y("y"),
        Z("z"),
        NONE("none");

        private final String name;

        private EnumAxis(String name)
        {
            this.name = name;
        }

        public String toString()
        {
            return this.name;
        }

        public static BlockModBark.EnumAxis fromFacingAxis(EnumFacing.Axis axis)
        {
            switch (axis)
            {
                case X:
                    return X;
                case Y:
                    return Y;
                case Z:
                    return Z;
                default:
                    return NONE;
            }
        }

        public String getName()
        {
            return this.name;
        }
    }
	@Override
	public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY,
			float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
		return this.getStateFromMeta(meta).withProperty(LOG_AXIS, BlockModBark.EnumAxis.fromFacingAxis(facing.getAxis()));
	}
	
	
	

}

 

 

 

 

 

 

 

ModBlocks:

Spoiler

import lennart247.test.lennartsmod.lennartsmod;
import lennart247.test.lennartsmod.blocks.BlockModBark;
import lennart247.test.lennartsmod.blocks.BlockModLeaves;
import lennart247.test.lennartsmod.blocks.BlockModSaplings;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@ObjectHolder(lennartsmod.MODID)
public class ModBlocks {
	 @GameRegistry.ObjectHolder("lennartsmod:block_cherry_sapling")
     public static final BlockModSaplings block_cherry_sapling = new BlockModSaplings("cherry");
	 
     @GameRegistry.ObjectHolder("lennartsmod:block_cherry_bark")
     public static final BlockModBark block_cherry_bark = new BlockModBark("cherry");
     
     @GameRegistry.ObjectHolder("lennartsmod:block_cherry_leaves")
     public static final BlockModLeaves block_cherry_leaves = new BlockModLeaves("cherry");
     
	 public static void registerBlocks(){
		 ForgeRegistries.BLOCKS.register(block_cherry_leaves);
		 ForgeRegistries.BLOCKS.register(block_cherry_sapling);
		 ForgeRegistries.BLOCKS.register(block_cherry_bark);
	 }
     public static void registerRenderers(){
    	 
     }
     @SideOnly(Side.CLIENT)
     public static void initModels(){
    	 block_cherry_bark.initModel();
    	 block_cherry_sapling.initModel();
    	 block_cherry_leaves.initModel();
     }
}

 

 

EnumWoodType:

Spoiler

package lennart247.test.lennartsmod.api;
 
public enum EnumWoodType implements IWoodType {
    CHERRY(4, "cherry", 0),
    BANANA(4, "banana", 1);
	
	
	private final int meta;
    private final String name;
    private final String unlocalizedName;

	private final float hardness;
	public static final float DEFAULT_HARDNESS = 2.0f;
	
	EnumWoodType(int carbonization, String name, int meta) {
		this(carbonization, DEFAULT_HARDNESS, name, meta);
	}
	EnumWoodType(int carbonization, float hardness, String name, int meta) {
		this.hardness = hardness;
		this.unlocalizedName = name;
		this.name = name;
		this.meta = meta;
	}
	
	public int getID(){
		return meta;
	}
	
	@Override
	public String getName() {
		return name; //toString()
	}

	@Override
	public int getMetadata() {
		// TODO Auto-generated method stub
		return ordinal();
	}

	@Override
	public float getHardness() {
		// TODO Auto-generated method stub
		return hardness;
	}


	

}

 

 

Proxy:

Spoiler

import lennart247.test.lennartsmod.blocks.BlockModSaplings;
import lennart247.test.lennartsmod.init.ModBlocks;
import lennart247.test.lennartsmod.items.ItemMarihuana;
import lennart247.test.lennartsmod.worldgen.WorldGen;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.common.registry.GameRegistry;
@Mod.EventBusSubscriber
public class CommonProxy {
	public void preInit(FMLPreInitializationEvent e) {
		GameRegistry.registerWorldGenerator(new WorldGen(), 0);
    }
    @SubscribeEvent
    public void init(FMLInitializationEvent e) {
    	
    }

    public void postInit(FMLPostInitializationEvent e) {
    }

    @SubscribeEvent
    public static void registerBlocks(RegistryEvent.Register<Block> event) {
    	ModBlocks.registerBlocks();
    	System.out.println("blocks registriert");
    }

    
    @SubscribeEvent
    public static void registerItems(RegistryEvent.Register<Item> event) {
    	
        event.getRegistry().register(new ItemMarihuana());
		event.getRegistry().register(new          ItemBlock(ModBlocks.block_cherry_sapling).setRegistryName(ModBlocks.block_cherry_sapling.getRegistryName()));
		event.getRegistry().register(new ItemBlock(ModBlocks.block_cherry_bark).setRegistryName(ModBlocks.block_cherry_bark.getRegistryName()));
		event.getRegistry().register(new ItemBlock(ModBlocks.block_cherry_leaves).setRegistryName(ModBlocks.block_cherry_leaves.getRegistryName()));
		System.out.println("items registriert");
	}
    @SubscribeEvent
    public static void registerBiomes(RegistryEvent.Register<Biome> event){
    	
    }
   
    public void genInit(){
    	
    }
    
}

 

 

Main Class:

 

Spoiler

import lennart247.test.lennartsmod.items.ItemMarihuana;
import lennart247.test.lennartsmod.proxy.ClientProxy;
import lennart247.test.lennartsmod.proxy.CommonProxy;
import lennart247.test.lennartsmod.proxy.ServerProxy;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod(modid = lennartsmod.MODID, version = lennartsmod.VERSION)
public class lennartsmod
{
//	@Instance(value="lennartsmod")
//	public static lennartsmod instance;
//	
	@Mod.Instance
	public static lennartsmod instance;
	
    public static final String MODID = "lennartsmod";
    public static final String VERSION = "1.0";
  
    @SidedProxy(clientSide="lennart247.test.lennartsmod.proxy.ClientProxy", serverSide="lennart247.test.lennartsmod.proxy.ServerProxy")
	public static CommonProxy proxy;
	
    @EventHandler
    public void preInit(FMLPreInitializationEvent event){
    	proxy.preInit(event);
    }
    @EventHandler
    public void init(FMLInitializationEvent event)
    {
        proxy.init(event);
        proxy.genInit();
    }
    
    @EventHandler
    public void postInit(FMLPostInitializationEvent event){
    	proxy.postInit(event);
    }
    
}

 

 

2017-09-03_15_19_43.thumb.png.8a53ece7ef4330b3f920c833068b7c40.png

2017-09-03_15_16_58.thumb.png.c53db700ad4b6ec644bb10d1ac191d40.png

 

 

 

 

 

Edited by Lennart247
Link to comment
Share on other sites

public static final PropertyEnum<BlockModBark.EnumAxis> LOG_AXIS = PropertyEnum.<BlockModBark.EnumAxis>create("axis", BlockModBark.EnumAxis.class);
	

You know, you don't need to create a new LOG_AXIS property, you can just reference the one in vanilla's BlockLog.

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

Quote
2 hours ago, Draco18s said:


public static final PropertyEnum<BlockModBark.EnumAxis> LOG_AXIS = PropertyEnum.<BlockModBark.EnumAxis>create("axis", BlockModBark.EnumAxis.class);
	

You know, you don't need to create a new LOG_AXIS property, you can just reference the one in vanilla's BlockLog.

Hmm you're right.. Thx for that. I was able to fix my problem, by changing:


case "cherry":
    		this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, WoodType.CHERRY).withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.Y));
    	case "banana":
    		this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, WoodType.BANANA));
    	}

to:


case "cherry":
    		this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, WoodType.CHERRY).withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.Y));
    		break;
    	case "banana":
    		this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, WoodType.BANANA));
    	}

I don't really understand why it fixed the problem, but it works now.

 

Link to comment
Share on other sites

Has to do with the parent class, likely. BlockLog already declared that LOG_AXIS property was a part of the BlockstateContainer and your one messed that up.

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

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • !warudo.isClientSide() still not a gui not an error just a simple message [06:44:39] [Render thread/WARN] [minecraft/MenuScreens]: Failed to create screen for menu type: mercmod:gem_polishing_menu Not a hint of what the problem is  this silent simple error dont tell much about the problem the code i made don't show errors highlighted   in mi old code 1.19.4 i launch the menu part from client side  but now i recheck the video and kapenjoe does it server side         
    • Hey, for getting your model to show up in Forge, double-check the way you've set up your model registration. Sometimes, it's just a tiny mix-up with where you've put your model file or maybe missing the right event to hook it up. Also, peek at your @Mod.EventBusSubscriber setup; it's gotta be listening in the right place. And don't forget to place your model file in the exact right spot with the correct naming. If in doubt, the Forge docs or forum threads can be super helpful.
    • Since flying mobs like bees and flies aren't affected, the problem likely lies with how ground mob AI interacts with the server environment. Checking the server logs, as you've done, is a good step. You might want to look for errors related to mob AI or pathfinding. Consider removing or updating mods one at a time to isolate the issue. Additionally, ensure your server's performance isn't being overly taxed by the modpack, as this can sometimes lead to unusual behavior with entity AI.
    • I'm having the same issue rn. Hostile mobs wont move until attacked but peaceful land mobs wont move at all. If it swims or flies its unaffected until it touches blocks.
    • Im trying to register model for my item but it doesn't works. First I Created a class where i declared all my items.   public class ModItems { public static final List<Item> ITEMS = new ArrayList<Item>(); public static final Item MY_ITEM = new MyItemClass(); } Then I created the MyItemClass where i describe my item. public class MyItemClass extends Item { public MyItemClass() { this.setRegistryName("my_item"); this.setUnlocalizedName("my_item"); this.setCreativeTab(CreativeTabs.COMBAT); ModItems.ITEMS.add(this); } } And The i created a class where i was trying register the model and where i registered my item @Mod.EventBusSubscriber public class EventsHandler { @SubscribeEvent public void registerItems(RegistryEvent.Register<Item> event) { event.getRegistry().register(new MyItemClass()); } @SubscribeEvent @SideOnly(Side.CLIENT) public static void onRegistryModel(ModelRegistryEvent event) { registryModel(new MyItemClass()); } @SideOnly(Side.CLIENT) private static void registryModel(Item item) { final ResourceLocation regName = item.getRegistryName(); final ModelResourceLocation mr1 = new ModelResourceLocation(regName, "inventory"); ModelBakery.registerItemVariants(item, mr1); ModelLoader.setCustomModelResourceLocation(item, 0, mr1); } } The registerItems method just registers my items. Then im catching ModelRegistryEvent to register my model. And in the last private method im registering models. In The game iitem still has purple-black cube instead of texture. I dont forgot to create the models\item folder and my_item.json file im sorry if this text has a grammatical errors. My english is very low  
  • Topics

×
×
  • Create New...

Important Information

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