Jump to content

JimiIT92

Members
  • Posts

    866
  • Joined

  • Last visited

  • Days Won

    3

Posts posted by JimiIT92

  1. I don't know how to use field instead of reflection to access specific private values. I know that using this

    Field[] fields = RenderGlobal.class.getFields();
    System.out.println(fields.length);
    

    it gives me the fields of a class but the system out return 0 (so is not returning anything at all). How can i access the damagedBlocks value using field?

  2. Ok, so i've done what you said but now i give this error

    
    java.lang.IllegalArgumentException: Don't know how to convert null[damage=0] back into data...
    at net.minecraft.block.Block.getMetaFromState(Block.java:272)
    at net.minecraft.block.Block.setHarvestLevel(Block.java:2201)
    at net.minecraft.block.Block.setHarvestLevel(Block.java:2183)
    at blaze.blocks.BlockCoalBlock.<init>(BlockCoalBlock.java:40)
    at blaze.core.BLBlocks.addBlocks(BLBlocks.java:108)
    at blaze.core.BL.preInit(BL.java:33)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:536)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
    at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
    at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
    at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
    at com.google.common.eventbus.EventBus.post(EventBus.java:275)
    at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:208)
    at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:187)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
    at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
    at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
    at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
    at com.google.common.eventbus.EventBus.post(EventBus.java:275)
    at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:118)
    at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:514)
    at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:243)
    at net.minecraft.client.Minecraft.startGame(Minecraft.java:446)
    at net.minecraft.client.Minecraft.run(Minecraft.java:356)
    at net.minecraft.client.main.Main.main(Main.java:117)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
    at GradleStart.main(Unknown Source)
    

     

    I see is related to the getMetaFromState method (wich you told me to not add it), so how can i fix that?

    This is the updated block class

    package blaze.blocks;
    
    import java.util.Random;
    
    import blaze.core.BLItems;
    import blaze.items.ItemHammer;
    import blaze.tileentities.TileEntityCoalBlock;
    import net.minecraft.block.Block;
    import net.minecraft.block.material.Material;
    import net.minecraft.block.properties.IProperty;
    import net.minecraft.block.properties.PropertyInteger;
    import net.minecraft.block.state.BlockState;
    import net.minecraft.block.state.IBlockState;
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.renderer.RenderGlobal;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.projectile.EntityArrow;
    import net.minecraft.init.Blocks;
    import net.minecraft.item.Item;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.BlockPos;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.world.IBlockAccess;
    import net.minecraft.world.World;
    import net.minecraftforge.fml.relauncher.ReflectionHelper;
    import net.minecraftforge.fml.relauncher.Side;
    import net.minecraftforge.fml.relauncher.SideOnly;
    
    public class BlockCoalBlock extends Block{
    
    public static Item drop;
    
    public static final PropertyInteger DAMAGE = PropertyInteger.create("damage", 0, 10);
    
    public BlockCoalBlock() {
    	super(Material.rock);
    	this.setCreativeTab(CreativeTabs.tabBlock);
    	this.setDefaultState(this.blockState.getBaseState().withProperty(DAMAGE, Integer.valueOf(0)));
    	this.setHarvestLevel("pickaxe", 0);
    	this.setHardness(3.0F);
    	this.setResistance(15.0F);
    }
    
    /**
         * Get the actual Block state of this Block at the given position. This applies properties not visible in the
         * metadata, such as fence connections.
         */
    @Override
    @SideOnly(Side.CLIENT)
        public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
        {
        	IBlockState newState = state;
        	
        	RenderGlobal render = Minecraft.getMinecraft().renderGlobal;
        	
        	int damage = ReflectionHelper.getPrivateValue(RenderGlobal.class, render, 21);
        	
        	System.out.println(damage);
        	
            return newState;
        }
    
    @SideOnly(Side.CLIENT)
        public Item getItem(World worldIn, BlockPos pos)
        {
            return Item.getItemFromBlock(this);
        }
    
    /**
         * Get the Item that this Block should drop when harvested.
         *  
         * @param fortune the level of the Fortune enchantment on the player's tool
         */
        public Item getItemDropped(IBlockState state, Random rand, int fortune)
        {
            return drop == null ? Item.getItemFromBlock(this) : drop;
        }
        
        public static Item setItemToDrop(EntityPlayer player, World world, BlockPos pos)
        {
        	Block down = world.getBlockState(pos.down()).getBlock();
        	Item item = player.getHeldItem().getItem();
        	
        	if(item instanceof ItemHammer && down.equals(Blocks.anvil))
        	{
        		drop = BLItems.carbon;
        	}
        	else
        	{
        		drop = null;
        	}
        	return null;
        }
    
       
        protected BlockState createBlockState()
        {
            return new BlockState(this, new IProperty[] {DAMAGE});
        }
        
    }
    

  3. Ok, this is my class for custom sapling

    
    public class BlockCorruptedSapling extends BlockBush implements IGrowable
    {
        public static final PropertyEnum TYPE = PropertyEnum.create("type", BlockCorruptedWood.EnumType.class);
        public static final PropertyInteger STAGE = PropertyInteger.create("stage", 0, 1);
    
        
        public BlockCorruptedSapling()
        {
            this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, BlockCorruptedWood.EnumType.NORMAL).withProperty(STAGE, Integer.valueOf(0)));
            this.setTickRandomly(true);
        }
    
        
        
        public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
        {
            if (!worldIn.isRemote)
            {
                super.updateTick(worldIn, pos, state, rand);
    
                if (worldIn.getLightFromNeighbors(pos.up()) >= 9 && rand.nextInt(7) == 0)
                {
                    this.grow(worldIn, pos, state, rand);
                }
            }
        }
    
        public void grow(World worldIn, BlockPos pos, IBlockState state, Random rand)
        {
            if (((Integer)state.getValue(STAGE)).intValue() == 0)
            {
                worldIn.setBlockState(pos, state.cycleProperty(STAGE), 4);
            }
            else
            {
                this.generateTree(worldIn, pos, state, rand);
            }
        }
    
        public void generateTree(World worldIn, BlockPos pos, IBlockState state, Random rand)
        {
            if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(worldIn, rand, pos)) return;
            Object object = rand.nextInt(10) == 0 ? new WorldGenBigCorruptedTree(true) : new WorldGenCorruptedTree(true);
            int i = 0;
            int j = 0;
            boolean flag = false;
    
            IBlockState iblockstate1 = Blocks.air.getDefaultState();
    
            if (flag)
            {
                worldIn.setBlockState(pos.add(i, 0, j), iblockstate1, 4);
                worldIn.setBlockState(pos.add(i + 1, 0, j), iblockstate1, 4);
                worldIn.setBlockState(pos.add(i, 0, j + 1), iblockstate1, 4);
                worldIn.setBlockState(pos.add(i + 1, 0, j + 1), iblockstate1, 4);
            }
            else
            {
                worldIn.setBlockState(pos, iblockstate1, 4);
            }
    
            if (!((WorldGenerator)object).generate(worldIn, rand, pos.add(i, 0, j)))
            {
                if (flag)
                {
                    worldIn.setBlockState(pos.add(i, 0, j), state, 4);
                    worldIn.setBlockState(pos.add(i + 1, 0, j), state, 4);
                    worldIn.setBlockState(pos.add(i, 0, j + 1), state, 4);
                    worldIn.setBlockState(pos.add(i + 1, 0, j + 1), state, 4);
                }
                else
                {
                    worldIn.setBlockState(pos, state, 4);
                }
            }
        }
    
        /**
         * Check whether the given BlockPos has a Sapling of the given type
         */
        public boolean isTypeAt(World worldIn, BlockPos pos, BlockCorruptedWood.EnumType type)
        {
            IBlockState iblockstate = worldIn.getBlockState(pos);
            return iblockstate.getBlock() == this && iblockstate.getValue(TYPE) == type;
        }
    
        /**
         * Get the damage value that this Block should drop
         */
        public int damageDropped(IBlockState state)
        {
            return ((BlockCorruptedWood.EnumType)state.getValue(TYPE)).getMetadata();
        }
    
        /**
         * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
         */
        @SideOnly(Side.CLIENT)
        public void getSubBlocks(Item itemIn, CreativeTabs tab, List list)
        {
            BlockCorruptedWood.EnumType[] aenumtype = BlockCorruptedWood.EnumType.values();
            int i = aenumtype.length;
    
            for (int j = 0; j < i; ++j)
            {
                BlockCorruptedWood.EnumType enumtype = aenumtype[j];
                list.add(new ItemStack(itemIn, 1, enumtype.getMetadata()));
            }
        }
    
        /**
         * Whether this IGrowable can grow
         */
        public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
        {
            return true;
        }
    
        public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
        {
            return (double)worldIn.rand.nextFloat() < 0.45D;
        }
    
        public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
        {
            this.grow(worldIn, pos, state, rand);
        }
    
        /**
         * Convert the given metadata into a BlockState for this Block
         */
        public IBlockState getStateFromMeta(int meta)
        {
            return this.getDefaultState().withProperty(TYPE, BlockCorruptedWood.EnumType.byMetadata(meta & 7)).withProperty(STAGE, Integer.valueOf((meta &  >> 3));
        }
    
        /**
         * Convert the BlockState into the correct metadata value
         */
        public int getMetaFromState(IBlockState state)
        {
            byte b0 = 0;
            int i = b0 | ((BlockCorruptedWood.EnumType)state.getValue(TYPE)).getMetadata();
            i |= ((Integer)state.getValue(STAGE)).intValue() << 3;
            return i;
        }
    
        protected BlockState createBlockState()
        {
            return new BlockState(this, new IProperty[] {TYPE, STAGE});
        }
    
        static final class SwitchEnumType
            {
                static final int[] WOOD_TYPE_LOOKUP = new int[blockCorruptedWood.EnumType.values().length];
    
                static
                {
                    try
                    {
                        WOOD_TYPE_LOOKUP[blockCorruptedWood.EnumType.NORMAL.ordinal()] = 0;
                    }
                    catch (NoSuchFieldError var6)
                    {
                        ;
                    }
    
                    
                }
            }
    }
    

     

    What you are missing is to extend BlockBush class, not just Block

  4. Alright, solved by doing this

    public boolean isInGround()
        {
        	double x = this.posX - this.lastTickPosX;
        	double y = this.posY - this.lastTickPosY;
        	double z = this.posZ - this.lastTickPosZ;
        	
        	return (x == 0.0D && y == 0.0D && z == 0.0D);
        }
        
    /**
         * Called by a player entity when they collide with an entity
         */
        @Override
        public void onCollideWithPlayer(EntityPlayer entityIn)
        {
            if (!this.worldObj.isRemote && this.isInGround() && this.arrowShake <= 0)
            {
                boolean flag = this.canBePickedUp == 1 || this.canBePickedUp == 2 && entityIn.capabilities.isCreativeMode;
    
                if (this.canBePickedUp == 1 && !entityIn.inventory.addItemStackToInventory(new ItemStack(BLItems.onice_spear, 1)))
                {
                    flag = false;
                }
    
                if (flag)
                {
                    this.playSound("random.pop", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
                    entityIn.onItemPickup(this, 1);
                    this.setDead();
                }
            }
        }
    

     

    Thanks for the help you gave me :D

  5. any suggest? :) I want to make something similar to how the discs works on pixelmon (so i place a block down, i keep hitting it and sometimes it change it's model), i figured out how to change its drop if i'm using a certain tool or a condition is true, but how can i also "make it visual", how can i change it's model the more the breaking progress goes up (so the more i breaking it the more the model will be smaller)

  6. If you don't want to grow your tree even using the bonemeal than you need to overrid the canGrow method like this

    **
         * Whether this IGrowable can grow
         */
        public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
        {
            return false;
        }
    

     

    So you can use the bonemeal on sapling but it will never grow. If you want instead to generate your tree than look into the BlockSapling vanilla class, or use this

    public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
        {
            this.grow(worldIn, pos, state, rand);
        }
    public void grow(World worldIn, BlockPos pos, IBlockState state, Random rand)
        {
            if (((Integer)state.getValue(STAGE)).intValue() == 0)
            {
                worldIn.setBlockState(pos, state.cycleProperty(STAGE), 4);
            }
            else
            {
                this.generateTree(worldIn, pos, state, rand);
            }
        }
    
        public void generateTree(World worldIn, BlockPos pos, IBlockState state, Random rand)
        {
            if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(worldIn, rand, pos)) return;
            Object object = new WorldGenMyTree(true);
    
            IBlockState iblockstate1 = Blocks.air.getDefaultState();
    
            worldIn.setBlockState(pos, iblockstate1, 4);
            
    
            if (!((WorldGenerator)object).generate(worldIn, rand, pos.add(i, 0, j)))
            {
                if (flag)
                {
                    worldIn.setBlockState(pos.add(i, 0, j), state, 4);
                    worldIn.setBlockState(pos.add(i + 1, 0, j), state, 4);
                    worldIn.setBlockState(pos.add(i, 0, j + 1), state, 4);
                    worldIn.setBlockState(pos.add(i + 1, 0, j + 1), state, 4);
                }
                else
                {
                    worldIn.setBlockState(pos, state, 4);
                }
            }
        }
    

     

    WorldGenMyTree is your custom tree generator (wich you can use whatever you want, even a custom tree "designed" like a structure

  7. Instead of using "parent": "block/wall_post", define your own json file for that and use that as a parent

    So for example, you define a json file called "my_wall.json"

    {
        "textures": {
            "particle": "#wall"
        },
        "elements": [
            {   "from": [ 4, 0, 4 ],
                "to": [ 12, 16, 12 ],
                "faces": {
                    "down":  { "uv": [ 4, 4, 12, 12 ], "texture": "#wall", "cullface": "down" },
                    "up":    { "uv": [ 4, 4, 12, 12 ], "texture": "#up", "cullface": "up"   },
                    "north": { "uv": [ 4, 0, 12, 16 ], "texture": "#wall" },
                    "south": { "uv": [ 4, 0, 12, 16 ], "texture": "#wall" },
                    "west":  { "uv": [ 4, 0, 12, 16 ], "texture": "#wall" },
                    "east":  { "uv": [ 4, 0, 12, 16 ], "texture": "#wall" }
                },
            }
        ]
    }
    

     

    With this code you have a different texture on the upper side, so in your wall json file (the one that you've posted) you need to do this

    {
        "parent": "ID:block/my_wall",
        "textures": {
            "wall": "blocks/log_oak",
            "up" :  "blocks/stone"
        }
    }
    

     

    ID is your modid, my_wall is the file that "replace" the wall_post of before, and with this you can make a wall that has a stone texture on the upper side ;)

    [/code]

  8. Ok, so i've added the event handler, so i now have this

    package blaze.core;
    
    import net.minecraft.block.Block;
    import net.minecraftforge.event.entity.player.PlayerEvent;
    import net.minecraftforge.event.entity.player.PlayerInteractEvent;
    import net.minecraftforge.event.world.BlockEvent;
    import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
    
    public class Events
    {
    @SubscribeEvent
    public void breakSpeed(PlayerEvent.BreakSpeed event)
    {
    	if (   (event.state == null || event.state.getBlock() != BLBlocks.coal_block)
    			&& (event.entityPlayer == null || event.entityPlayer.getCurrentEquippedItem() == null || event.entityPlayer.getCurrentEquippedItem().getItem() != BLItems.topaz_hammer)) {
    		return;
    	}
    	else
    	{
    		System.out.println("BREAKING");
    		Block block = event.state.getBlock();
    
    	}
    }
    
    }
    

     

    So now how can i tell the game "change the block model while breaking"? :)

  9. Of course, here is the entity class :)

    package blaze.entities;
    
    import blaze.core.BLItems;
    import io.netty.buffer.ByteBuf;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.EntityLivingBase;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.projectile.EntityArrow;
    import net.minecraft.item.ItemStack;
    import net.minecraft.util.MathHelper;
    import net.minecraft.world.World;
    import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
    
    public class EntityOniceSpear extends EntityArrow implements IEntityAdditionalSpawnData 
    {
        private boolean inGround;
    
        public EntityOniceSpear(World worldIn)
        {
            super(worldIn);
        }
    
        public EntityOniceSpear(World worldIn, EntityLivingBase shooter, EntityLivingBase par3, float par4, float par5)
        {
            super(worldIn, shooter, par3, par4, par5);
        }
        
        public EntityOniceSpear(World worldIn, EntityLivingBase shooter, float par3)
        {
            super(worldIn, shooter, par3);
        }
    
    /**
         * Called by a player entity when they collide with an entity
         */
        @Override
        public void onCollideWithPlayer(EntityPlayer entityIn)
        {
            if (!this.worldObj.isRemote && this.inGround && this.arrowShake <= 0)
            {
                boolean flag = this.canBePickedUp == 1 || this.canBePickedUp == 2 && entityIn.capabilities.isCreativeMode;
    
                if (this.canBePickedUp == 1 && !entityIn.inventory.addItemStackToInventory(new ItemStack(BLItems.onice_spear, 1)))
                {
                    flag = false;
                }
    
                if (flag)
                {
                    this.playSound("random.pop", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
                    entityIn.onItemPickup(this, 1);
                    this.setDead();
                }
            }
        }
    
        @Override
    public void writeSpawnData(ByteBuf buffer) {
    	buffer.writeInt(shootingEntity != null ? shootingEntity.getEntityId() : -1);
    }
    
    @Override
    public void readSpawnData(ByteBuf buffer) {
    	Entity shooter = worldObj.getEntityByID(buffer.readInt());
    	if (shooter instanceof EntityLivingBase) {
    		shootingEntity = (EntityLivingBase) shooter;
    	}
    }
    }
    

  10. This is the item class from where i shoot the spear

    package blaze.items;
    
    import blaze.core.BLTabs;
    import blaze.entities.EntityMalachiteSpear;
    import blaze.entities.EntityOniceSpear;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.init.Items;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemBow;
    import net.minecraft.item.ItemStack;
    import net.minecraft.stats.StatList;
    import net.minecraft.world.World;
    import net.minecraftforge.fml.relauncher.Side;
    import net.minecraftforge.fml.relauncher.SideOnly;
    
    public class ItemSpear extends ItemBow
    {
    
    private int type;
    
    public ItemSpear(int type)
    {
    	this.setMaxDamage(0);
    	this.setMaxStackSize(16);
    	this.type = type;
    	this.setCreativeTab(BLTabs.tabCombat);
    }
    
    /**
         * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
         */
    @Override
        public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
        {
            net.minecraftforge.event.entity.player.ArrowNockEvent event = new net.minecraftforge.event.entity.player.ArrowNockEvent(playerIn, itemStackIn);
            if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) return event.result;
            playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn));
    
            return itemStackIn;
        }
    
    /**
     * How long it takes to use or consume an item
     */
    @Override
    public int getMaxItemUseDuration(ItemStack stack)
    {
    	return 72000;
    }
    
    /**
     * Called when the player stops using an Item (stops holding the right mouse button).
     *  
     * @param timeLeft The amount of ticks left before the using would have been complete
     */
    @Override
    public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityPlayer playerIn, int timeLeft)
    {
    	int j = this.getMaxItemUseDuration(stack) - timeLeft;
    	net.minecraftforge.event.entity.player.ArrowLooseEvent event = new net.minecraftforge.event.entity.player.ArrowLooseEvent(playerIn, stack, j);
    	if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) return;
    	j = event.charge;
    
    	boolean flag = playerIn.capabilities.isCreativeMode;
    		float f = (float)j / 20.0F;
    		f = (f * f + f * 2.0F) / 3.0F;
    
    		if ((double)f < 0.1D)
    		{
    			return;
    		}
    
    		if (f > 1.0F)
    		{
    			f = 1.0F;
    		}
    
    		if(this.type == 0)
    		{
    			EntityOniceSpear entityspear = new EntityOniceSpear(worldIn, playerIn, f * 2.0F);
    			if (flag)
    			{
    				entityspear.canBePickedUp = 2;
    			}
    			else
    			{
    				playerIn.inventory.consumeInventoryItem(this);
    			}
    
    			playerIn.triggerAchievement(StatList.objectUseStats[item.getIdFromItem(this)]);
    
    			if (!worldIn.isRemote)
    			{
    				worldIn.spawnEntityInWorld(entityspear);
    			}
    		}
    		else
    		{
    			EntityMalachiteSpear entityspear = new EntityMalachiteSpear(worldIn, playerIn, f * 2.0F);
    			if (flag)
    			{
    				entityspear.canBePickedUp = 2;
    			}
    			else
    			{
    				playerIn.inventory.consumeInventoryItem(this);
    			}
    
    			playerIn.triggerAchievement(StatList.objectUseStats[item.getIdFromItem(this)]);
    
    			if (!worldIn.isRemote)
    			{
    				worldIn.spawnEntityInWorld(entityspear);
    			}
    		}
    
    }
    
    @Override
    @SideOnly(Side.CLIENT)
    public boolean isFull3D()
    {
    	return true;
    }
    }
    

  11. Thanks, i'll check it out :) I found another method but i don't know if is correct. Overriding this function

    @SideOnly(Side.CLIENT)
        public boolean addHitEffects(World world, MovingObjectPosition target, net.minecraft.client.particle.EffectRenderer effectRenderer)
        {
    return false;
    }
    

    lets me handle what happens when breaking the block. Is it correct doing stuff here?

  12. Is there any way to see how a block is damaged? I mean, you hit the block for a period of time and then it breaks, is there a way to see

    "if the block has been hitten for X time than use this model, if it has been hitten for Z time than use this other model"

    I've tried using the damageValue but it always return the metadata (wich in my case is 0). So basically how can i check if a player is breaking a block and from how long he's doing it?

  13. Thanks for your reply :) I've added these methods but now the entity is not rendering ad eclipse gives me this error :/

    [22:27:36] [Client thread/ERROR] [FML]: A severe problem occurred during the spawning of an entity at ( 558.0625,5.5, -549.84375)
    java.lang.NoSuchMethodException: blaze.entities.EntityOniceSpear.<init>(net.minecraft.world.World)
    at java.lang.Class.getConstructor0(Unknown Source) ~[?:1.8.0_51]
    at java.lang.Class.getConstructor(Unknown Source) ~[?:1.8.0_51]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:98) [EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:56) [EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.access$000(EntitySpawnHandler.java:31) [EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler$1.run(EntitySpawnHandler.java:46) [EntitySpawnHandler$1.class:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_51]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_51]
    at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:709) [FMLCommonHandler.class:?]
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1070) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
    at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]
    at GradleStart.main(Unknown Source) [start/:?]
    [22:27:36] [Client thread/FATAL] [FML]: Exception caught executing FutureTask: java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.lang.NoSuchMethodException: blaze.entities.EntityOniceSpear.<init>(net.minecraft.world.World)
    java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.lang.NoSuchMethodException: blaze.entities.EntityOniceSpear.<init>(net.minecraft.world.World)
    at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_51]
    at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_51]
    at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:710) [FMLCommonHandler.class:?]
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1070) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
    at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]
    at GradleStart.main(Unknown Source) [start/:?]
    Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: blaze.entities.EntityOniceSpear.<init>(net.minecraft.world.World)
    at com.google.common.base.Throwables.propagate(Throwables.java:160) ~[guava-17.0.jar:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:147) ~[EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:56) ~[EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.access$000(EntitySpawnHandler.java:31) ~[EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler$1.run(EntitySpawnHandler.java:46) ~[EntitySpawnHandler$1.class:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_51]
    at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_51]
    at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:709) ~[FMLCommonHandler.class:?]
    ... 11 more
    Caused by: java.lang.NoSuchMethodException: blaze.entities.EntityOniceSpear.<init>(net.minecraft.world.World)
    at java.lang.Class.getConstructor0(Unknown Source) ~[?:1.8.0_51]
    at java.lang.Class.getConstructor(Unknown Source) ~[?:1.8.0_51]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:98) ~[EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:56) ~[EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.access$000(EntitySpawnHandler.java:31) ~[EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler$1.run(EntitySpawnHandler.java:46) ~[EntitySpawnHandler$1.class:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_51]
    at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_51]
    at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:709) ~[FMLCommonHandler.class:?]
    ... 11 more
    

     

    QUICK UPDATE: i've solved that problem by adding the other constructors, but now i can't pickup the spear when on ground

    public EntityOniceSpear(World worldIn)
        {
            super(worldIn);
        }
    
        public EntityOniceSpear(World worldIn, double x, double y, double z)
        {
            super(worldIn);
        }
    
        public EntityOniceSpear(World worldIn, EntityLivingBase shooter, EntityLivingBase p_i1755_3_, float p_i1755_4_, float p_i1755_5_)
        {
            super(worldIn);
        }
    

  14. I have a spear that acts like an arrow, but when i shoot it in a block it has a strange behavior. It "moves" up after it hit the block. Here is a video to show you what i mean

    https://www.youtube.com/watch?v=RUIcAT-zqTc&feature=youtu.be

     

    This is my entity class

    package blaze.entities;
    
    import blaze.core.BLItems;
    import io.netty.buffer.ByteBuf;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.EntityLivingBase;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.projectile.EntityArrow;
    import net.minecraft.item.ItemStack;
    import net.minecraft.util.MathHelper;
    import net.minecraft.world.World;
    import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
    
    public class EntityOniceSpear extends EntityArrow implements IEntityAdditionalSpawnData 
    {
        private boolean inGround;
    
        public EntityOniceSpear(World worldIn)
        {
            super(worldIn);
        }
    
        public EntityOniceSpear(World worldIn, EntityLivingBase shooter, EntityLivingBase par3, float par4, float par5)
        {
            super(worldIn, shooter, par3, par4, par5);
        }
        
        public EntityOniceSpear(World worldIn, EntityLivingBase shooter, float par3)
        {
            super(worldIn, shooter, par3);
        }
    
    /**
         * Called by a player entity when they collide with an entity
         */
        @Override
        public void onCollideWithPlayer(EntityPlayer entityIn)
        {
            if (!this.worldObj.isRemote && this.inGround && this.arrowShake <= 0)
            {
                boolean flag = this.canBePickedUp == 1 || this.canBePickedUp == 2 && entityIn.capabilities.isCreativeMode;
    
                if (this.canBePickedUp == 1 && !entityIn.inventory.addItemStackToInventory(new ItemStack(BLItems.onice_spear, 1)))
                {
                    flag = false;
                }
    
                if (flag)
                {
                    this.playSound("random.pop", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
                    entityIn.onItemPickup(this, 1);
                    this.setDead();
                }
            }
        }
    
        @Override
    public void writeSpawnData(ByteBuf buffer) {
    	buffer.writeInt(shootingEntity != null ? shootingEntity.getEntityId() : -1);
    }
    
    @Override
    public void readSpawnData(ByteBuf buffer) {
    	Entity shooter = worldObj.getEntityByID(buffer.readInt());
    	if (shooter instanceof EntityLivingBase) {
    		shootingEntity = (EntityLivingBase) shooter;
    	}
    }
    }
    

     

    And this is how i register the entity

    EntityRegistry.registerModEntity(EntityMalachiteSpear.class, "malachiteSpear", 2 , BL.instance, 64, 20, true);
    

    The value 64 and 20 has been taken from the registration of the EntityArrow class in EntityTracker (here it also set false the last value, but if i do the arrow doesn't do the moving animation)

     

    So why has this behavior? :/ Thanks in advance to all who will help me :)

  15. Just fixed that by chaging the two functions above with this

    @Override
    public void writeSpawnData(ByteBuf buffer) {
    	buffer.writeInt(this.art.ordinal());
    
            buffer.writeInt(this.hangingPosition.getX());       // x
            buffer.writeInt(this.hangingPosition.getY());       // y
            buffer.writeInt(this.hangingPosition.getZ());       // z
            buffer.writeByte(this.getHorizontalFacing().getIndex());
    }
    
    @Override
    public void readSpawnData(ByteBuf buffer) {
    	EntityPaintingEB.EnumArt[] aenumart = EntityPaintingEB.EnumArt.values();
    	this.art = aenumart[buffer.readInt()];
    
            int x = buffer.readInt();
            int y = buffer.readInt();
            int z = buffer.readInt();
            
            BlockPos pos = new BlockPos(x, y, z);
            this.hangingPosition = pos;
            this.func_174859_a(EnumFacing.getFront((buffer.readByte())));
    }
    

     

    Finally this problem is solved, thanks to everyone of you!!!! Hope this will help you jeffryfisher in your updating process :)

  16. OH MY GOD! I've just solved this! Or well... the painting finally spawns! Ive just let the EntityClass implements the IEntityAdditionalSpawnData  interface, and then add it's related method and IT WORKED!

    So this is now my class for the entity

    package blaze.entities;
    
    import java.util.ArrayList;
    
    import com.google.common.collect.Lists;
    
    import blaze.core.BLItems;
    import io.netty.buffer.ByteBuf;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.EntityHanging;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.ItemStack;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.util.BlockPos;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.world.World;
    import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
    import net.minecraftforge.fml.relauncher.Side;
    import net.minecraftforge.fml.relauncher.SideOnly;
    
    public class EntityPaintingEB extends EntityHanging implements IEntityAdditionalSpawnData 
    {
        public EntityPaintingEB.EnumArt art;
    
        public EntityPaintingEB(World worldIn)
        {
            super(worldIn);
        }
    
        public EntityPaintingEB(World worldIn, BlockPos pos, EnumFacing side)
        {
            super(worldIn, pos);
            ArrayList arraylist = Lists.newArrayList();
            EntityPaintingEB.EnumArt[] aenumart = EntityPaintingEB.EnumArt.values();
            int i = aenumart.length;
    
            for (int j = 0; j < i; ++j)
            {
                EntityPaintingEB.EnumArt enumart = aenumart[j];
                this.art = enumart;
                this.func_174859_a(side);
    
                if (this.onValidSurface())
                {
                    arraylist.add(enumart);
                }
            }
    
            if (!arraylist.isEmpty())
            {
                this.art = (EntityPaintingEB.EnumArt)arraylist.get(this.rand.nextInt(arraylist.size()));
            }
    
            this.func_174859_a(side);
        }
    
        @SideOnly(Side.CLIENT)
        public EntityPaintingEB(World worldIn, BlockPos pos, EnumFacing side, String name)
        {
            this(worldIn, pos, side);
            EntityPaintingEB.EnumArt[] aenumart = EntityPaintingEB.EnumArt.values();
            int i = aenumart.length;
    
            for (int j = 0; j < i; ++j)
            {
                EntityPaintingEB.EnumArt enumart = aenumart[j];
    
                if (enumart.title.equals(name))
                {
                    this.art = enumart;
                    break;
                }
            }
    
            this.func_174859_a(side);
        }
    
    
    /**
         * (abstract) Protected helper method to write subclass entity data to NBT.
         */
        public void writeEntityToNBT(NBTTagCompound tagCompound)
        {
            tagCompound.setString("Motive", this.art.title);
            super.writeEntityToNBT(tagCompound);
        }
    
        /**
         * (abstract) Protected helper method to read subclass entity data from NBT.
         */
        public void readEntityFromNBT(NBTTagCompound tagCompund)
        {
            String s = tagCompund.getString("Motive");
            EntityPaintingEB.EnumArt[] aenumart = EntityPaintingEB.EnumArt.values();
            int i = aenumart.length;
    
            for (int j = 0; j < i; ++j)
            {
                EntityPaintingEB.EnumArt enumart = aenumart[j];
    
                if (enumart.title.equals(s))
                {
                    this.art = enumart;
                }
            }
    
            if (this.art == null)
            {
                this.art = EntityPaintingEB.EnumArt.KEBAB;
            }
    
            super.readEntityFromNBT(tagCompund);
        }
    
        public int getWidthPixels()
        {
            return this.art.sizeX;
        }
    
        public int getHeightPixels()
        {
            return this.art.sizeY;
        }
    
        /**
         * Called when this entity is broken. Entity parameter may be null.
         */
        public void onBroken(Entity entity)
        {
            if (this.worldObj.getGameRules().getGameRuleBooleanValue("doTileDrops"))
            {
                if (entity instanceof EntityPlayer)
                {
                    EntityPlayer entityplayer = (EntityPlayer)entity;
    
                    if (entityplayer.capabilities.isCreativeMode)
                    {
                        return;
                    }
                }
    
                this.entityDropItem(new ItemStack(BLItems.painting_eb), 0.0F);
            }
        }
    
        /**
         * Sets the location and Yaw/Pitch of an entity in the world
         */
        public void setLocationAndAngles(double x, double y, double z, float yaw, float pitch)
        {
            BlockPos blockpos = new BlockPos(x - this.posX, y - this.posY, z - this.posZ);
            BlockPos blockpos1 = this.hangingPosition.add(blockpos);
            this.setPosition((double)blockpos1.getX(), (double)blockpos1.getY(), (double)blockpos1.getZ());
        }
    
        @SideOnly(Side.CLIENT)
        public void func_180426_a(double par1, double par2, double par3, float par4, float par5, int par6, boolean par7)
        {
            BlockPos blockpos = new BlockPos(par1 - this.posX, par2 - this.posY, par3 - this.posZ);
            BlockPos blockpos1 = this.hangingPosition.add(blockpos);
            this.setPosition((double)blockpos1.getX(), (double)blockpos1.getY(), (double)blockpos1.getZ());
        }
    
        public static enum EnumArt
        {
            KEBAB("Kebab", 16, 16, 0, 0),
            AZTEC("Aztec", 16, 16, 16, 0),
            ALBAN("Alban", 16, 16, 32, 0),
            AZTEC_2("Aztec2", 16, 16, 48, 0),
            BOMB("Bomb", 16, 16, 64, 0),
            PLANT("Plant", 16, 16, 80, 0),
            WASTELAND("Wasteland", 16, 16, 96, 0),
            POOL("Pool", 32, 16, 0, 32),
            COURBET("Courbet", 32, 16, 32, 32),
            SEA("Sea", 32, 16, 64, 32),
            SUNSET("Sunset", 32, 16, 96, 32),
            CREEBET("Creebet", 32, 16, 128, 32),
            WANDERER("Wanderer", 16, 32, 0, 64),
            GRAHAM("Graham", 16, 32, 16, 64),
            MATCH("Match", 32, 32, 0, 128),
            BUST("Bust", 32, 32, 32, 128),
            STAGE("Stage", 32, 32, 64, 128),
            VOID("Void", 32, 32, 96, 128),
            SKULL_AND_ROSES("SkullAndRoses", 32, 32, 128, 128),
            WITHER("Wither", 32, 32, 160, 128),
            FIGHTERS("Fighters", 64, 32, 0, 96),
            POINTER("Pointer", 64, 64, 0, 192),
            PIGSCENE("Pigscene", 64, 64, 64, 192),
            BURNING_SKULL("BurningSkull", 64, 64, 128, 192),
            SKELETON("Skeleton", 64, 48, 192, 64),
            DONKEY_KONG("DonkeyKong", 64, 48, 192, 112),
            EB("EB", 32, 32, 96, 80),
        	SUBSCRIBE("Subscribe", 64, 16, 96, 64);
            public static final int field_180001_A = "SkullAndRoses".length();
            /** Painting Title. */
            public final String title;
            public final int sizeX;
            public final int sizeY;
            public final int offsetX;
            public final int offsetY;
    
    
            private EnumArt(String name, int par1, int par2, int par3, int par4)
            {
                this.title = name;
                this.sizeX = par1;
                this.sizeY = par2;
                this.offsetX = par3;
                this.offsetY = par4;
            }
        }
    
    @Override
    public void writeSpawnData(ByteBuf buffer) {
    	buffer.writeInt(this.art.ordinal());
            buffer.writeInt(this.chunkCoordX);       // x
            buffer.writeInt(this.chunkCoordY);       // y
            buffer.writeInt(this.chunkCoordZ);       // z
            buffer.writeByte(this.getHorizontalFacing().getIndex());
    }
    
    @Override
    public void readSpawnData(ByteBuf buffer) {
    	EntityPaintingEB.EnumArt[] aenumart = EntityPaintingEB.EnumArt.values();
    	this.art = aenumart[buffer.readInt()];
            this.chunkCoordX = buffer.readInt();
            this.chunkCoordY = buffer.readInt();
            this.chunkCoordZ = buffer.readInt();
            this.func_174859_a(EnumFacing.getFront((buffer.readByte())));
    }
    }
    

     

    I've also changed the Item class to this

    package blaze.items;
    
    import blaze.entities.EntityPaintingEB;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.entity.EntityHanging;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.util.BlockPos;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.world.World;
    
    public class ItemCustomPainting extends Item
    {
        private final Class hangingEntityClass;
    
        public ItemCustomPainting(Class entityClass)
        {
        	super();
            this.hangingEntityClass = entityClass;
            this.setCreativeTab(CreativeTabs.tabDecorations);
        }
    
        /**
         * Called when a Block is right-clicked with this Item
         *  
         * @param pos The block being right-clicked
         * @param side The side being right-clicked
         */
        public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
        {
            if (side == EnumFacing.DOWN)
            {
                return false;
            }
            else if (side == EnumFacing.UP)
            {
                return false;
            }
            else
            {
                BlockPos blockpos1 = pos.offset(side);
    
                if (!playerIn.canPlayerEdit(blockpos1, side, stack))
                {
                    return false;
                }
                else
                {
                	EntityHanging entityhanging = this.createHangingEntity(worldIn, blockpos1, side);
    
                    if (entityhanging != null && entityhanging.onValidSurface())
                    {
                        if (!worldIn.isRemote)
                        {
                            worldIn.spawnEntityInWorld(entityhanging);
                        }
    
                        --stack.stackSize;
                    }
    
                    return true;
                }
            }
        }
    
        private EntityHanging createHangingEntity(World worldIn, BlockPos pos, EnumFacing clickedSide)
        {
            return new EntityPaintingEB(worldIn, pos, clickedSide);
        }
    }
    

     

    Now, the only issue remained is that if a painting of 32x32 pixels is spawned (for example the wither painting), it will actually spawns 1 block higher than where i clicked. So here is a picture of a 32x32 painting

    nCc0brS.png

    As you can see rendering is fine but i have clicked with the painting on the block above (so the first log block starting from bottom). It only happens with big painting, if a small painting or a "banner" painting is placed everything works fine :) Hope to find soon what is the problem and post here the solution. Thanks to all who show me support doing this, probably i will never figured out without you :) And for who is asking himself, i looked into the AtelierCanvas mod source code on Github :)

×
×
  • Create New...

Important Information

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