Jump to content

[1.8] [SOLVED] Property not setting correctly


saxon564

Recommended Posts

I am working on adding a new log and am trying to get directional textures like that of normal Minecraft logs. The issue is, for some reason, the property is getting set to 'none' and not keeping the value it's supposed to have.

 

package com.teamrune.symbology.blocks;

import java.util.Iterator;

import scala.reflect.internal.Trees.This;

import net.minecraft.block.BlockLog;
import net.minecraft.block.BlockRotatedPillar;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.util.IStringSerializable;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import com.teamrune.symbology.Symbology;

public class BlockAshLog extends BlockRotatedPillar
{
    public static final PropertyEnum LOG_AXIS = PropertyEnum.create("axis", BlockAshLog.EnumAxis.class);
    
    public BlockAshLog()
    {
        super(Material.leaves);
        setCreativeTab(Symbology.symbologyTab);
        setUnlocalizedName("ash_log");
    }
    
    @SideOnly(Side.CLIENT)
    public EnumWorldBlockLayer getBlockLayer() {
    	return EnumWorldBlockLayer.SOLID;
    }
    
    @Override
    public boolean isOpaqueCube() {
    	return false;
    }
    
    @Override
    public boolean isFullCube() {
    	return true;
    }
    
    @Override
    public int getRenderType() {
    	return 3;
    }
    
    public int getMetaFromState(IBlockState state) {
	return 0;
}
    
    public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
    {
    	System.out.println(state.getProperties().toString());
        byte b0 = 4;
        int i = b0 + 1;

        if (worldIn.isAreaLoaded(pos.add(-i, -i, -i), pos.add(i, i, i)))
        {
            Iterator iterator = BlockPos.getAllInBox(pos.add(-b0, -b0, -b0), pos.add(b0, b0, b0)).iterator();

            while (iterator.hasNext())
            {
                BlockPos blockpos1 = (BlockPos)iterator.next();
                IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);

                if (iblockstate1.getBlock().isLeaves(worldIn, blockpos1))
                {
                    iblockstate1.getBlock().beginLeavesDecay(worldIn, blockpos1);
                }
            }
        }
    }
    
    @Override
    public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
    {
    	System.out.println(facing.toString());
    	EnumAxis face = BlockAshLog.EnumAxis.fromFacingAxis(facing.getAxis());
    	System.out.println(face);
    	System.out.println(super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(LOG_AXIS, face).toString());
        return super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(LOG_AXIS, face);
    }

    @Override public boolean canSustainLeaves(net.minecraft.world.IBlockAccess world, BlockPos pos){ return true; }
    @Override public boolean isWood(net.minecraft.world.IBlockAccess world, BlockPos pos){ return true; }
    
    protected BlockState createBlockState() {
	//return new ExtendedBlockState(this, new IProperty[]{LISTED_PROPERTIES}, new IUnlistedProperty[]{JAI});
	return new BlockState(this, new IProperty[] { 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 BlockAshLog.EnumAxis fromFacingAxis(EnumFacing.Axis axis)
        {
            switch (BlockAshLog.SwitchAxis.AXIS_LOOKUP[axis.ordinal()])
            {
                case 1:
                	System.out.println("Case 1");
                    return X;
                case 2:
                	System.out.println("Case 2");
                    return Y;
                case 3:
                	System.out.println("Case 3");
                    return Z;
                default:
                	System.out.println("Default");
                    return NONE;
            }
        }

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

    static final class SwitchAxis
        {
            static final int[] AXIS_LOOKUP = new int[EnumFacing.Axis.values().length];

            static
            {
                try
                {
                	System.out.println("Ordinal 1");
                    AXIS_LOOKUP[EnumFacing.Axis.X.ordinal()] = 1;
                }
                catch (NoSuchFieldError var3)
                {
                    ;
                }

                try
                {
                	System.out.println("Ordinal 2");
                    AXIS_LOOKUP[EnumFacing.Axis.Y.ordinal()] = 2;
                }
                catch (NoSuchFieldError var2)
                {
                    ;
                }

                try
                {
                	System.out.println("Ordinal 3");
                    AXIS_LOOKUP[EnumFacing.Axis.Z.ordinal()] = 3;
                }
                catch (NoSuchFieldError var1)
                {
                    ;
                }
            }
        }
}

 

here is the logs I get when I place the block

[03:03:20] [Client thread/INFO] [sTDOUT]: [com.teamrune.symbology.blocks.BlockAshLog:onBlockPlaced:87]: up
[03:03:20] [Client thread/INFO] [sTDOUT]: [com.teamrune.symbology.blocks.BlockAshLog$EnumAxis:fromFacingAxis:128]: Case 2
[03:03:20] [Client thread/INFO] [sTDOUT]: [com.teamrune.symbology.blocks.BlockAshLog:onBlockPlaced:89]: y
[03:03:20] [Client thread/INFO] [sTDOUT]: [com.teamrune.symbology.blocks.BlockAshLog:onBlockPlaced:90]: symbology:ash_log[axis=y]
[03:03:20] [server thread/INFO] [sTDOUT]: [com.teamrune.symbology.blocks.BlockAshLog:onBlockPlaced:87]: up
[03:03:20] [server thread/INFO] [sTDOUT]: [com.teamrune.symbology.blocks.BlockAshLog$EnumAxis:fromFacingAxis:128]: Case 2
[03:03:20] [server thread/INFO] [sTDOUT]: [com.teamrune.symbology.blocks.BlockAshLog:onBlockPlaced:89]: y
[03:03:20] [server thread/INFO] [sTDOUT]: [com.teamrune.symbology.blocks.BlockAshLog:onBlockPlaced:90]: symbology:ash_log[axis=y]

 

then this is what I get when I break it

[03:03:18] [server thread/INFO] [sTDOUT]: [com.teamrune.symbology.blocks.BlockAshLog:breakBlock:63]: {PropertyEnum{name=axis, clazz=class com.teamrune.symbology.blocks.BlockAshLog$EnumAxis, values=[x, y, z, none]}=none}

 

As you can see, when I place the block, it gets the right property, but it is getting reset at some point after it leaves my class and becomes none. I have spent the last couple hours trying to find where the issue was coming from, but the final print in the onBlockPlaced method was as far as I could really go into seeing what was being returned. So I have run into a dead end on this one.

Link to comment
Share on other sites

ok, thanks. That helped. Now I'm working on the leaf and can't seem to get it to render transparency like normal leaves. I have crossed it with all 3 of the classes for normal leaves, and the block is always rendering solid.  I've even tried doing isOpaqueCube(){return false;} instead of using the fancyGraphics variable, and that didn't do anything.

 

package com.teamrune.symbology.blocks;

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

import net.minecraft.block.Block;
import net.minecraft.block.BlockLeavesBase;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import com.teamrune.symbology.Symbology;


public class BlockAshLeafBlock extends BlockLeavesBase implements net.minecraftforge.common.IShearable
{

public static final PropertyBool DECAYABLE = PropertyBool.create("decayable");
    public static final PropertyBool CHECK_DECAY = PropertyBool.create("check_decay");
    int[] surroundings;
    @SideOnly(Side.CLIENT)
    protected int iconIndex;
    @SideOnly(Side.CLIENT)
    protected boolean isTransparent;
    
    public BlockAshLeafBlock()
    {
    	super(Material.leaves, false);
        setCreativeTab(Symbology.symbologyTab);
        setUnlocalizedName("ash_leaves");
        this.setHardness(0.2F);
        this.setLightOpacity(1);
        this.setStepSound(soundTypeGrass);
        this.setTickRandomly(true);
    }
    
    @SideOnly(Side.CLIENT)
    public EnumWorldBlockLayer getBlockLayer() {
    	return this.isTransparent ? EnumWorldBlockLayer.CUTOUT_MIPPED : EnumWorldBlockLayer.SOLID;
    }
    
    @Override
    public boolean isOpaqueCube() {
    	return !this.fancyGraphics;
    }
    
    @Override
    public boolean isFullCube() {
    	return true;
    }
    
    @Override
    public int getRenderType() {
    	return 3;
    }
    
    public IBlockState getStateFromMeta(int meta)
    {
    	System.out.println(isTransparent);
        return this.getDefaultState().withProperty(DECAYABLE, Boolean.valueOf(meta == 0)).withProperty(CHECK_DECAY, Boolean.valueOf(meta > 0));
    }
    
    public int getMetaFromState(IBlockState state)
    {
        byte b0 = 0;
        int i = b0;
    	
        if (!((Boolean)state.getValue(DECAYABLE)).booleanValue())
        {
            i = 0;
        }

        if (((Boolean)state.getValue(CHECK_DECAY)).booleanValue())
        {
            i = 1;
        }
        
        

        return i;
    }
    
    public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
    {
        byte b0 = 1;
        int i = b0 + 1;
        int j = pos.getX();
        int k = pos.getY();
        int l = pos.getZ();

        if (worldIn.isAreaLoaded(new BlockPos(j - i, k - i, l - i), new BlockPos(j + i, k + i, l + i)))
        {
            for (int i1 = -b0; i1 <= b0; ++i1)
            {
                for (int j1 = -b0; j1 <= b0; ++j1)
                {
                    for (int k1 = -b0; k1 <= b0; ++k1)
                    {
                        BlockPos blockpos1 = pos.add(i1, j1, k1);
                        IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);

                        if (iblockstate1.getBlock().isLeaves(worldIn, blockpos1))
                        {
                            iblockstate1.getBlock().beginLeavesDecay(worldIn, blockpos1);
                        }
                    }
                }
            }
        }
    }
    
    protected BlockState createBlockState() {
	return new BlockState(this, new IProperty[] { CHECK_DECAY, DECAYABLE });
}

    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
        if (!worldIn.isRemote)
        {
            if (((Boolean)state.getValue(CHECK_DECAY)).booleanValue() && ((Boolean)state.getValue(DECAYABLE)).booleanValue())
            {
                byte b0 = 4;
                int i = b0 + 1;
                int j = pos.getX();
                int k = pos.getY();
                int l = pos.getZ();
                byte b1 = 32;
                int i1 = b1 * b1;
                int j1 = b1 / 2;

                if (this.surroundings == null)
                {
                    this.surroundings = new int[b1 * b1 * b1];
                }

                int k1;

                if (worldIn.isAreaLoaded(new BlockPos(j - i, k - i, l - i), new BlockPos(j + i, k + i, l + i)))
                {
                    int l1;
                    int i2;

                    for (k1 = -b0; k1 <= b0; ++k1)
                    {
                        for (l1 = -b0; l1 <= b0; ++l1)
                        {
                            for (i2 = -b0; i2 <= b0; ++i2)
                            {
                                BlockPos tmp = new BlockPos(j + k1, k + l1, l + i2);
                                Block block = worldIn.getBlockState(tmp).getBlock();

                                if (!block.canSustainLeaves(worldIn, tmp))
                                {
                                    if (block.isLeaves(worldIn, tmp))
                                    {
                                        this.surroundings[(k1 + j1) * i1 + (l1 + j1) * b1 + i2 + j1] = -2;
                                    }
                                    else
                                    {
                                        this.surroundings[(k1 + j1) * i1 + (l1 + j1) * b1 + i2 + j1] = -1;
                                    }
                                }
                                else
                                {
                                    this.surroundings[(k1 + j1) * i1 + (l1 + j1) * b1 + i2 + j1] = 0;
                                }
                            }
                        }
                    }

                    for (k1 = 1; k1 <= 4; ++k1)
                    {
                        for (l1 = -b0; l1 <= b0; ++l1)
                        {
                            for (i2 = -b0; i2 <= b0; ++i2)
                            {
                                for (int j2 = -b0; j2 <= b0; ++j2)
                                {
                                    if (this.surroundings[(l1 + j1) * i1 + (i2 + j1) * b1 + j2 + j1] == k1 - 1)
                                    {
                                        if (this.surroundings[(l1 + j1 - 1) * i1 + (i2 + j1) * b1 + j2 + j1] == -2)
                                        {
                                            this.surroundings[(l1 + j1 - 1) * i1 + (i2 + j1) * b1 + j2 + j1] = k1;
                                        }

                                        if (this.surroundings[(l1 + j1 + 1) * i1 + (i2 + j1) * b1 + j2 + j1] == -2)
                                        {
                                            this.surroundings[(l1 + j1 + 1) * i1 + (i2 + j1) * b1 + j2 + j1] = k1;
                                        }

                                        if (this.surroundings[(l1 + j1) * i1 + (i2 + j1 - 1) * b1 + j2 + j1] == -2)
                                        {
                                            this.surroundings[(l1 + j1) * i1 + (i2 + j1 - 1) * b1 + j2 + j1] = k1;
                                        }

                                        if (this.surroundings[(l1 + j1) * i1 + (i2 + j1 + 1) * b1 + j2 + j1] == -2)
                                        {
                                            this.surroundings[(l1 + j1) * i1 + (i2 + j1 + 1) * b1 + j2 + j1] = k1;
                                        }

                                        if (this.surroundings[(l1 + j1) * i1 + (i2 + j1) * b1 + (j2 + j1 - 1)] == -2)
                                        {
                                            this.surroundings[(l1 + j1) * i1 + (i2 + j1) * b1 + (j2 + j1 - 1)] = k1;
                                        }

                                        if (this.surroundings[(l1 + j1) * i1 + (i2 + j1) * b1 + j2 + j1 + 1] == -2)
                                        {
                                            this.surroundings[(l1 + j1) * i1 + (i2 + j1) * b1 + j2 + j1 + 1] = k1;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                k1 = this.surroundings[j1 * i1 + j1 * b1 + j1];

                if (k1 >= 0)
                {
                    worldIn.setBlockState(pos, state.withProperty(CHECK_DECAY, Boolean.valueOf(false)), 4);
                }
                else
                {
                    this.destroy(worldIn, pos);
                }
            }
        }
    }

    @SideOnly(Side.CLIENT)
    public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
        if (worldIn.canLightningStrike(pos.up()) && !World.doesBlockHaveSolidTopSurface(worldIn, pos.down()) && rand.nextInt(15) == 1)
        {
            double d0 = (double)((float)pos.getX() + rand.nextFloat());
            double d1 = (double)pos.getY() - 0.05D;
            double d2 = (double)((float)pos.getZ() + rand.nextFloat());
            worldIn.spawnParticle(EnumParticleTypes.DRIP_WATER, d0, d1, d2, 0.0D, 0.0D, 0.0D, new int[0]);
        }
    }

    private void destroy(World worldIn, BlockPos pos)
    {
        this.dropBlockAsItem(worldIn, pos, worldIn.getBlockState(pos), 0);
        worldIn.setBlockToAir(pos);
    }

    public int quantityDropped(Random random)
    {
        return random.nextInt(20) == 0 ? 1 : 0;
    }
    
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        //return Item.getItemFromBlock(Symbology.ash_sapling);
    	return null;
    }
    
    public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
    {
        super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);
    }

    protected void dropApple(World worldIn, BlockPos pos, IBlockState state, int chance) {}

    protected int getSaplingDropChance(IBlockState state)
    {
        return 20;
    }
    
    @SideOnly(Side.CLIENT)
    public void setGraphicsLevel(boolean fancy)
    {
        this.isTransparent = fancy;
        this.fancyGraphics = fancy;
        this.iconIndex = fancy ? 0 : 1;
    }

    public boolean isVisuallyOpaque()
    {
        return false;
    }

    @Override public boolean isShearable(ItemStack item, IBlockAccess world, BlockPos pos){ return true; }
    @Override public boolean isLeaves(IBlockAccess world, BlockPos pos){ return true; }

    @Override
    public void beginLeavesDecay(World world, BlockPos pos)
    {
        IBlockState state = world.getBlockState(pos);
        if (!(Boolean)state.getValue(CHECK_DECAY))
        {
            world.setBlockState(pos, state.withProperty(CHECK_DECAY, true), 4);
        }
    }

    @Override
    public java.util.List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
    {
        java.util.List<ItemStack> ret = new java.util.ArrayList<ItemStack>();
        Random rand = world instanceof World ? ((World)world).rand : new Random();
        int chance = this.getSaplingDropChance(state);

        if (fortune > 0)
        {
            chance -= 2 << fortune;
            if (chance < 10) chance = 10;
        }

        if (rand.nextInt(chance) == 0)
            ret.add(new ItemStack(getItemDropped(state, rand, fortune), 1, damageDropped(state)));

        chance = 200;
        if (fortune > 0)
        {
            chance -= 10 << fortune;
            if (chance < 40) chance = 40;
        }

        this.captureDrops(true);
        if (world instanceof World)
            this.dropApple((World)world, pos, state, chance); // Dammet mojang
        ret.addAll(this.captureDrops(false));
        return ret;
    }

@Override
public List<ItemStack> onSheared(ItemStack item, IBlockAccess world,
		BlockPos pos, int fortune) {
	return new java.util.ArrayList(java.util.Arrays.asList(new ItemStack(this, 1, 0)));
}
}

Link to comment
Share on other sites

ok, cool. I added a call to setGraphicsLevel to the updateTick method. Now the issue with rendering I'm having is, if you swap your graphics setting to fast is on fancy or vica versa, the render of the block doesn't update. I have tried everything I can think of to try and cause the leaves to update their texture. The only way I have been able to get their render to update has been by placing a block next to them.

Link to comment
Share on other sites

Hi

 

The reason for the render of the block not updating is because blocks are compiled into a rendering "list" which is cached/reused until the blocks change (eg you place a block nearby, which causes the rendering list to be recompiled).  Changing the graphics level does recompile all the rendering list (I think), but your setGraphicsLevel probably is not called before the recompilation, so it uses the old setting.  Might be worth looking how the vanilla leaves do it, exactly.

 

-TGG

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I create my mod pack,yesterday my mod pack is fine but i add one mod and error. I'm delete this mmod but minecraft is still stop on CONFIG_LOAD then I tried to delete config and restart it but again. If you can pleace help me. https://imgur.com/ngZBzuv
    • game crashes before even opening (log:https://mclo.gs/M8xvX7c)
    • I have created a custom entity that extends "TamableAnimal", but I am wanting to have it spawn in the ocean. I have it spawning right now, but it spawns way too frequently even with weight set to 1. I am guessing it is because it is rolling in the spawn pool of land animals since TameableAnimal extends Animal and is different than WaterAnimal, and since no land animals spawn in the ocean it just fills every inch up with my custom entity. I have followed basic tutorials for spawning entities with Forge, but I feel like I am missing something about how to change what spawn pool this custom entity ends up in. Is it possible to change that or do I need to refactor it to be based off of WaterAnimal to get those spawn? My biome modifier JSON file: { "type": "forge:add_spawns", "biomes": "#minecraft:is_ocean", "spawners": { "type": "darwinsmysticalmounts:water_wyvern", "weight": 20, "minCount": 1, "maxCount": 1 } } My client event: event.register(ModEntityTypes.WATER_WYVERN.get(), SpawnPlacements.Type.NO_RESTRICTIONS, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, WaterWyvernEntity::checkWaterWyvernSpawnRules, SpawnPlacementRegisterEvent.Operation.REPLACE); And the actual custom spawn rule that makes it spawn in the water: public static boolean checkWaterWyvernSpawnRules(EntityType<WaterWyvernEntity> pAnimal, LevelAccessor pLevel, MobSpawnType pSpawnType, BlockPos pPos, RandomSource pRandom) { return pPos.getY() > pLevel.getSeaLevel() - 16 && pLevel.getFluidState(pPos.below()).is(FluidTags.WATER); }  
    • Starting today, I am unable to load my modded minecraft world. Forge crash log initially said it was a specific mod called Doggy Talents, which I disabled. Then it blamed JEI, and when that was disabled it blamed another mod so I assume it's something more than a specific mod. Minecraft launcher log claims "Exit Code 1". Nothing had changed since last night when it was working fine Forge Log: https://pastebin.com/S1GiBGVJ Client Log: https://pastebin.com/aLwuGUNL  
    • I am using AMD, yes. I downloaded the website's drivers and am still having the issue. I also used the Cleanup Utility just in case. 
  • Topics

×
×
  • Create New...

Important Information

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