Jump to content

My custom oak log won't orientate to face the player [1.7.10][SOLVED]


Recommended Posts

Posted

My custom oak log won't orientate to face the player

 

 

BlockOakLog Class:

package com.hardwareplus.mod;

import javax.swing.Icon;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.tileentity.TileEntityPiston;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class BlockOakLog extends Block {

public IIcon Side0;
public IIcon Side1;
public IIcon Side2;
public IIcon Side3;
public IIcon Side4;
public IIcon Side5;
private IIcon[] icons;

protected BlockOakLog(Material material) {
	super(material);
	this.setHardness(2F);
	this.setResistance(10F);
	this.setStepSound(soundTypeWood);
}
public void registerBlockIcons(IIconRegister icon){
//BottomFace
Side0 = icon.registerIcon("hardwareplus:oaklogside0");
//TopFace
Side1 = icon.registerIcon("hardwareplus:oaklogside1");
//NorthFace
Side2 = icon.registerIcon("hardwareplus:oaklogside2");
//SouthFace
Side3 = icon.registerIcon("hardwareplus:oaklogside3");
//WestFace
Side4 = icon.registerIcon("hardwareplus:oaklogside4");
//EastFace
Side5 = icon.registerIcon("hardwareplus:oaklogside5");
}

public IIcon getIcon(int side, int meta){
if(side == 0){
	return Side0;
}else if(side == 1){
	return Side1;
}else if(side == 2){
	return Side2;
}else if(side == 3){
	return Side3;
}else if(side == 4){
	return Side4;
}else if(side == 5){
	return Side5;
}return null;
  }
public IIcon getIcon1(int side, int meta) {
    
    if (meta == 0 && side == 1)
            return Side0;
    else if (meta == 1 && side == 1)
            return Side1;
    else if (meta == 2 && side == 1)
            return Side0;
    else if (meta == 3 && side == 1)
            return Side1;
    return null;
  }
}

Posted

Sorry for being mean, i am just angry that i can't find a solution. Anyway i changed the code, am i close to the solution or am i still completely wrong?

 

Code

package com.hardwareplus.mod;

import javax.swing.Icon;

import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.tileentity.TileEntityPiston;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class BlockOakLog extends Block {

public IIcon top0;
public IIcon top1;
public IIcon sides;


protected BlockOakLog(Material material) {
	super(material);
	this.setHardness(2F);
	this.setResistance(10F);
	this.setStepSound(soundTypeWood);
}
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack) {
    
    int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
    par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);
}
@Override
public void registerBlockIcons(IIconRegister iconRegister) {

    top0 = iconRegister.registerIcon("hardwareplus:oaklogside0");
    top1 = iconRegister.registerIcon("hardwareplus:oaklogside0");
    sides = iconRegister.registerIcon("hardwareplus:oaklogside2");
}
@Override
public IIcon getIcon(int side, int meta) {
    
    if (meta == 0 && side == 1)
            return top0;
    else if (meta == 1 && side == 1)
            return top1;
    else if (meta == 2 && side == 1)
            return top0;
    else if (meta == 3 && side == 1)
            return top1;
    return sides;
   
}
}

Posted

Tried this sort of code but no luck the bottom of the log texture is the side texture...

 

package com.hardwareplus.mod;

import javax.swing.Icon;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.tileentity.TileEntityPiston;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

public class BlockOakLog extends Block {

private  IIcon top, bottom;

protected BlockOakLog(Material material) {
	super(material);
	this.setHardness(2F);
	this.setResistance(10F);
	this.setStepSound(soundTypeWood);
}
    public  void registerBlockIcons (IIconRegister iiconRegister)
    {
    	this.blockIcon = iiconRegister.registerIcon("hardwareplus:oaklogside2");
    	this.top = iiconRegister.registerIcon("hardwareplus:oaklogside0");
    	this.bottom = iiconRegister.registerIcon("hardwareplus:oaklogside1");
    }
    public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)
    {
        int direction = MathHelper.floor_double((double)(living.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
        world.setBlockMetadataWithNotify(x, y, z, direction, 2);
    }
    @SideOnly(Side.CLIENT)
    public IIcon getIcon(int side, int metadata)
    {
        return side == 3 && metadata == 0 ? this.top : (side == 1 && metadata == 0 ? this.top : (side == 4 && metadata == 1 ? this.top : (side == 2 && metadata == 2 ? this.top : (side == 5 && metadata == 3 ? this.top : this.blockIcon))));
    }
        public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis)
        {
            if((axis == ForgeDirection.UP || axis == ForgeDirection.DOWN) && !world.isRemote)
            {
                int direction = world.getBlockMetadata(x, y, z) + 1;
                if(direction > 3)
                {
                    direction = 0;
                }
                world.setBlockMetadataWithNotify(x, y, z, direction, 3);
                return true;
            }
            return false;
        }
        
        public ForgeDirection[] getValidRotations(World world, int x, int y, int z)
        {
            return new ForgeDirection[] {ForgeDirection.UP, ForgeDirection.DOWN};
        }
}

 

Can someone tell me what is wrong plz

Posted

So you want the block the behave like a log block? Why don't you extend the existing log block? Why re-invent the wheel?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Crashed:

 

---- Minecraft Crash Report ----
// Don't do that.

Time: 03/09/15 11:17 AM
Description: Rendering item

java.lang.NullPointerException: Rendering item
at net.minecraft.block.BlockLog.getTopIcon(BlockLog.java:80)
at net.minecraft.block.BlockRotatedPillar.getIcon(BlockRotatedPillar.java:64)
at net.minecraft.block.Block.getBlockTextureFromSide(Block.java:686)
at net.minecraft.item.ItemBlock.getIconFromDamage(ItemBlock.java:51)
at net.minecraft.item.Item.getIconIndex(Item.java:457)
at net.minecraft.item.ItemStack.getIconIndex(ItemStack.java:131)
at net.minecraft.client.renderer.entity.RenderItem.renderItemIntoGUI(RenderItem.java:420)
at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:585)
at net.minecraft.client.gui.GuiIngame.renderInventorySlot(GuiIngame.java:973)
at net.minecraftforge.client.GuiIngameForge.renderHotbar(GuiIngameForge.java:209)
at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:144)
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1114)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1067)
at net.minecraft.client.Minecraft.run(Minecraft.java:962)
at net.minecraft.client.main.Main.main(Main.java:164)
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)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at net.minecraft.block.BlockLog.getTopIcon(BlockLog.java:80)
at net.minecraft.block.BlockRotatedPillar.getIcon(BlockRotatedPillar.java:64)
at net.minecraft.block.Block.getBlockTextureFromSide(Block.java:686)
at net.minecraft.item.ItemBlock.getIconFromDamage(ItemBlock.java:51)
at net.minecraft.item.Item.getIconIndex(Item.java:457)
at net.minecraft.item.ItemStack.getIconIndex(ItemStack.java:131)
at net.minecraft.client.renderer.entity.RenderItem.renderItemIntoGUI(RenderItem.java:420)

-- Item being rendered --
Details:
Item Type: net.minecraft.item.ItemBlock@64f1e9f8
Item Aux: 0
Item NBT: null
Item Foil: false
Stacktrace:
at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:585)
at net.minecraft.client.gui.GuiIngame.renderInventorySlot(GuiIngame.java:973)
at net.minecraftforge.client.GuiIngameForge.renderHotbar(GuiIngameForge.java:209)
at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:144)

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityClientPlayerMP['Player769'/291, l='MpServer', x=-803.91, y=5.62, z=-349.24]]
Chunk stats: MultiplayerChunkCache: 0, 0
Level seed: 0
Level generator: ID 01 - flat, ver 0. Features enabled: false
Level generator options: 
Level spawn location: World: (-782,4,-319), Chunk: (at 2,0,1 in -49,-20; contains blocks -784,0,-320 to -769,255,-305), Region: (-2,-1; contains chunks -64,-32 to -33,-1, blocks -1024,0,-512 to -513,255,-1)
Level time: 359990 game time, 359990 day time
Level dimension: 0
Level storage version: 0x00000 - Unknown?
Level weather: Rain time: 0 (now: true), thunder time: 0 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
Forced entities: 1 total; [EntityClientPlayerMP['Player769'/291, l='MpServer', x=-803.91, y=5.62, z=-349.24]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2566)
at net.minecraft.client.Minecraft.run(Minecraft.java:984)
at net.minecraft.client.main.Main.main(Main.java:164)
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)

-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 10 (amd64) version 10.0
Java Version: 1.8.0_60, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 849252096 bytes (809 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1448 4 mods loaded, 4 mods active
States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
UCHIJAAAA	mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) 
UCHIJAAAA	FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1448-1.7.10.jar) 
UCHIJAAAA	Forge{10.13.4.1448} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1448-1.7.10.jar) 
UCHIJAAAA	hardwareplus{0.1} [Hardware Plus] (bin) 
GL info: ' Vendor: 'Intel' Version: '4.0.0 - Build 10.18.10.4252' Renderer: 'Intel(R) HD Graphics'
Launched Version: 1.7.10
LWJGL: 2.9.1
OpenGL: Intel(R) HD Graphics GL version 4.0.0 - Build 10.18.10.4252, Intel
GL Caps: Using GL 1.3 multitexturing.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Anisotropic filtering is supported and maximum anisotropy is 16.
Shaders are available because OpenGL 2.1 is supported.

Is Modded: Definitely; Client brand changed to 'fml,forge'
Type: Client (map_client.txt)
Resource Packs: []
Current Language: English (US)
Profiler Position: N/A (disabled)
Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Anisotropic Filtering: Off (1)

 

My BlockOakLog class:

 

package com.hardwareplus.mod;

import java.util.Random;

import javax.swing.Icon;

import net.minecraft.block.Block;
import net.minecraft.block.BlockLog;
import net.minecraft.block.material.Material;
import net.minecraft.item.Item;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;

public class BlockOakLog extends BlockLog {
    protected IIcon[] field_150167_a;
    protected IIcon[] field_150166_b;
    private static final String __OBFID = "CL_00000266";

    public BlockOakLog()
    {
        super();
        this.setCreativeTab(HardwarePlus.tabHardwarePlus);
        this.setHardness(2.0F);
        this.setStepSound(soundTypeWood);
    }

    public static int func_150165_c(int p_150165_0_)
    {
        return p_150165_0_ & 3;
    }

    /**
     * Returns the quantity of items to drop on block destruction.
     */
    public int quantityDropped(Random p_149745_1_)
    {
        return 1;
    }

    public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
    {
        return Item.getItemFromBlock(this);
    }

    public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_)
    {
        byte var7 = 4;
        int var8 = var7 + 1;

        if (p_149749_1_.checkChunksExist(p_149749_2_ - var8, p_149749_3_ - var8, p_149749_4_ - var8, p_149749_2_ + var8, p_149749_3_ + var8, p_149749_4_ + var8))
        {
            for (int var9 = -var7; var9 <= var7; ++var9)
            {
                for (int var10 = -var7; var10 <= var7; ++var10)
                {
                    for (int var11 = -var7; var11 <= var7; ++var11)
                    {
                        if (p_149749_1_.getBlock(p_149749_2_ + var9, p_149749_3_ + var10, p_149749_4_ + var11).getMaterial() == Material.leaves)
                        {
                            int var12 = p_149749_1_.getBlockMetadata(p_149749_2_ + var9, p_149749_3_ + var10, p_149749_4_ + var11);

                            if ((var12 &  == 0)
                            {
                                p_149749_1_.setBlockMetadataWithNotify(p_149749_2_ + var9, p_149749_3_ + var10, p_149749_4_ + var11, var12 | 8, 4);
                            }
                        }
                    }
                }
            }
        }
    }

    protected IIcon func_150163_b(int p_150163_1_)
    {
        return this.field_150167_a[p_150163_1_ % this.field_150167_a.length];
    }

    protected IIcon func_150161_d(int p_150161_1_)
    {
        return this.field_150166_b[p_150161_1_ % this.field_150166_b.length];
    }
protected BlockOakLog(Material material) {
      
}
}

 

What did i do wrong?

Posted

I solved it!!!

 

The new code:

 

package com.hardwareplus.mod;

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

import javax.swing.Icon;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLog;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockOakLog extends BlockLog {
    public static final String[] field_150169_M = new String[] {"new_oak"};
    private static final String __OBFID = "CL_00000277";

    public void getSubBlocks(Item p_149666_1_, List p_149666_3_)
    {
        p_149666_3_.add(new ItemStack(p_149666_1_, 1, 0));
        p_149666_3_.add(new ItemStack(p_149666_1_, 1, 1));
    }

    public void registerBlockIcons(IIconRegister p_149651_1_)
    {
        this.field_150167_a = new IIcon[field_150169_M.length];
        this.field_150166_b = new IIcon[field_150169_M.length];

        for (int var2 = 0; var2 < this.field_150167_a.length; ++var2)
        {
            this.field_150167_a[var2] = p_149651_1_.registerIcon("hardwareplus:oaklogside2");
            this.field_150166_b[var2] = p_149651_1_.registerIcon("hardwareplus:oaklogside0");
        }
    }
}

 

Thx larsgerrits for the idea man :) I appreciate it!!!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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