Jump to content

[1.8.9] Technical Blocks as Items


Tschipp

Recommended Posts

It works for all blocks but the Double Slabs.

They crash when I try to place them, giving me this error:

 ---- Minecraft Crash Report ----
// Hey, that tickles! Hehehe!

Time: 10.08.16 14:40
Description: Unexpected error

java.lang.IllegalArgumentException: Cannot set property PropertyEnum{name=half, clazz=class net.minecraft.block.BlockSlab$EnumBlockHalf, values=[top, bottom]} as it does not exist in BlockState{block=minecraft:double_stone_slab, properties=[seamless, variant]}
                at net.minecraft.block.state.BlockState$StateImplementation.withProperty(BlockState.java:156)
                at net.minecraft.block.BlockSlab.onBlockPlaced(BlockSlab.java:120)
                at tschipp.creativePlus.items.FakeItem.onItemUse(FakeItem.java:64)
                at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:149)
                at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerRightClick(PlayerControllerMP.java:438)
                at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1569)
                at net.minecraft.client.Minecraft.runTick(Minecraft.java:2123)
                at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1080)
                at net.minecraft.client.Minecraft.run(Minecraft.java:380)
                at net.minecraft.client.main.Main.main(Main.java:116)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:497)
                at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
                at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:497)
                at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
                at GradleStart.main(GradleStart.java:26)


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

-- Head --
Stacktrace:
                at net.minecraft.block.state.BlockState$StateImplementation.withProperty(BlockState.java:156)
                at net.minecraft.block.BlockSlab.onBlockPlaced(BlockSlab.java:120)
                at tschipp.creativePlus.items.FakeItem.onItemUse(FakeItem.java:64)
                at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:149)
                at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerRightClick(PlayerControllerMP.java:438)
                at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1569)

-- Affected level --
Details:
                Level name: MpServer
                All players: 1 total; [EntityPlayerSP['Player753'/45, l='MpServer', x=76.35, y=5.79, z=716.28]]
                Chunk stats: MultiplayerChunkCache: 400, 400
                Level seed: 0
                Level generator: ID 01 - flat, ver 0. Features enabled: false
                Level generator options:
                Level spawn location: 121.00,4.00,657.00 - World: (121,4,657), Chunk: (at 9,0,1 in 7,41; contains blocks 112,0,656 to 127,255,671), Region: (0,1; contains chunks 0,32 to 31,63, blocks 0,0,512 to 511,255,1023)
                Level time: 42045 game time, 42045 day time
                Level dimension: 0
                Level storage version: 0x00000 - Unknown?
                Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
                Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
                Forced entities: 9 total; [EntityItem['item.tile.sapling.jungle'/16, l='MpServer', x=49.81, y=4.00, z=711.72], EntityPlayerSP['Player753'/45, l='MpServer', x=76.35, y=5.79, z=716.28], EntityRabbit['Rabbit'/22, l='MpServer', x=117.44, y=4.00, z=734.91], EntityItem['item.tile.sapling.jungle'/10, l='MpServer', x=33.34, y=18.00, z=702.13], EntityItem['item.tile.sapling.jungle'/11, l='MpServer', x=44.88, y=4.00, z=705.56], EntityItem['item.tile.sapling.jungle'/12, l='MpServer', x=32.31, y=26.00, z=706.69], EntityHorse['Horse'/13, l='MpServer', x=53.72, y=4.00, z=642.06], EntitySheep['Sheep'/14, l='MpServer', x=65.00, y=4.00, z=675.76], EntitySheep['Sheep'/15, l='MpServer', x=58.78, y=4.00, z=686.66]]
                Retry entities: 0 total; []
                Server brand: fml,forge
                Server type: Integrated singleplayer server
Stacktrace:
                at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:383)
                at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2645)
                at net.minecraft.client.Minecraft.run(Minecraft.java:409)
                at net.minecraft.client.main.Main.main(Main.java:116)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:497)
                at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
                at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:497)
                at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
                at GradleStart.main(GradleStart.java:26)

-- System Details --
Details:
                Minecraft Version: 1.8.9
                Operating System: Windows 10 (amd64) version 10.0
                Java Version: 1.8.0_65, Oracle Corporation
                Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
                Memory: 588351208 bytes (561 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)
                JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
                IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
                FML: MCP 9.19 Powered by Forge 11.15.1.1875 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.19} [Minecraft Coder Pack] (minecraft.jar)
                UCHIJAAAA        FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.8.9-11.15.1.1875.jar)
                UCHIJAAAA        Forge{11.15.1.1875} [Minecraft Forge] (forgeSrc-1.8.9-11.15.1.1875.jar)
                UCHIJAAAA        creativeplus{0.1} [§2Creative §6+] (bin)
                Loaded coremods (and transformers):
                GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.5.0 NVIDIA 364.72' Renderer: 'GeForce 840M/PCIe/SSE2'
                Launched Version: 1.8.9
                LWJGL: 2.9.4
                OpenGL: GeForce 840M/PCIe/SSE2 GL version 4.5.0 NVIDIA 364.72, NVIDIA Corporation
                GL Caps: Using GL 1.3 multitexturing.
Using GL 1.3 texture combiners.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Shaders are available because OpenGL 2.1 is supported.
VBOs are available because OpenGL 1.5 is supported.

                Using VBOs: No
                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)
                CPU: 8x Intel(R) Core(TM) i7-4710MQ CPU @ 2.50GHz

 

I can see that it has something to do with its properties, but I can't really resolve it. This is my code:

 

 package tschipp.creativePlus.items;

import net.minecraft.block.BlockDoubleStoneSlab;
import net.minecraft.block.BlockDoubleStoneSlabNew;
import net.minecraft.block.BlockDoubleWoodSlab;
import net.minecraft.block.BlockStoneSlab;
import net.minecraft.block.BlockStoneSlabNew;
import net.minecraft.block.BlockWoodSlab;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemSword;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class CustomItems {
     
     
      public static Item flyingSpeed;
      public static Item walkSpeed;
      public static Item superBonemeal;
      public static ItemSword godSword;
     
      public static FakeItem fire;
      public static FakeItem litFurnace;
      public static FakeItem endPortal;
      public static FakeItem portal;
      public static FakeItem doubleStoneSlab;
      public static FakeItem doubleStoneSlab2;
      public static FakeItem doubleWoodenSlab;
      public static FakeItem water;
      public static FakeItem lava;

     
      //public static ToolMaterial godMaterial = EnumHelper.addToolMaterial("godMaterial", 100, 10000000, 25.0F, 1000000000.0F, 15);

     
      public static void createItems() {
           
            GameRegistry.registerItem(flyingSpeed = new FlyingSpeed("flyingSpeed"), "flyingSpeed");
            GameRegistry.registerItem(walkSpeed = new WalkSpeed("walkSpeed"), "walkSpeed");
            GameRegistry.registerItem(superBonemeal = new SuperBonemeal("superBonemeal"), "superBonemeal");
      //    GameRegistry.registerItem(godSword = new GodSword(godMaterial), "godSword");
           
            GameRegistry.registerItem(fire = new FakeItem(Blocks.fire), "fire");
            GameRegistry.registerItem(litFurnace = new FakeItem(Blocks.lit_furnace), "lit_furnace");
            GameRegistry.registerItem(endPortal = new FakeItem(Blocks.end_portal), "end_portal");
            GameRegistry.registerItem(portal = new FakeItem(Blocks.portal), "portal");
            GameRegistry.registerItem(doubleStoneSlab = new FakeItem((BlockStoneSlab)Blocks.double_stone_slab), "double_stone_slab");
            GameRegistry.registerItem(doubleStoneSlab2 = new FakeItem((BlockStoneSlabNew)Blocks.double_stone_slab2), "double_stone_slab2");
            GameRegistry.registerItem(doubleWoodenSlab = new FakeItem((BlockWoodSlab)Blocks.double_wooden_slab), "double_wooden_slab");
            GameRegistry.registerItem(water = new FakeItem(Blocks.water), "water");
            GameRegistry.registerItem(lava = new FakeItem(Blocks.lava), "lava");

           
      //    EnumHelper.addToolMaterial(name, harvestLevel, maxUses, efficiency, damage, enchantability)
           
           

      }

}




 

package tschipp.creativePlus.items;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class FakeItem extends Item
{
    public final Block block;

    public FakeItem(Block block)
    {
        this.block = block;
    }

    /**
     * Sets the unlocalized name of this item to the string passed as the parameter, prefixed by "item."
     */
    public FakeItem setUnlocalizedName(String unlocalizedName)
    {
        super.setUnlocalizedName(unlocalizedName);
        return this;
    }

    /**
     * Called when a Block is right-clicked with this Item
     */
    public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();

        if (!block.isReplaceable(worldIn, pos))
        {
            pos = pos.offset(side);
        }

        if (stack.stackSize == 0)
        {
            return false;
        }
        else if (!playerIn.canPlayerEdit(pos, side, stack))
        {
            return false;
        }
        else if (worldIn.canBlockBePlaced(this.block, pos, false, side, (Entity)null, stack))
        {
            int i = this.getMetadata(stack.getMetadata());
            IBlockState iblockstate1 = this.block.onBlockPlaced(worldIn, pos, side, hitX, hitY, hitZ, i, playerIn);

            if (placeBlockAt(stack, playerIn, worldIn, pos, side, hitX, hitY, hitZ, iblockstate1))
            {
                worldIn.playSoundEffect((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), this.block.stepSound.getPlaceSound(), (this.block.stepSound.getVolume() + 1.0F) / 2.0F, this.block.stepSound.getFrequency() * 0.8F);
                --stack.stackSize;
            }

            return true;
        }
        else
        {
            return false;
        }
    }

    public static boolean setTileEntityNBT(World worldIn, EntityPlayer pos, BlockPos stack, ItemStack p_179224_3_)
    {
        MinecraftServer minecraftserver = MinecraftServer.getServer();

        if (minecraftserver == null)
        {
            return false;
        }
        else
        {
            if (p_179224_3_.hasTagCompound() && p_179224_3_.getTagCompound().hasKey("BlockEntityTag", 10))
            {
                TileEntity tileentity = worldIn.getTileEntity(stack);

                if (tileentity != null)
                {
                    if (!worldIn.isRemote && tileentity.func_183000_F() && !minecraftserver.getConfigurationManager().canSendCommands(pos.getGameProfile()))
                    {
                        return false;
                    }

                    NBTTagCompound nbttagcompound = new NBTTagCompound();
                    NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttagcompound.copy();
                    tileentity.writeToNBT(nbttagcompound);
                    NBTTagCompound nbttagcompound2 = (NBTTagCompound)p_179224_3_.getTagCompound().getTag("BlockEntityTag");
                    nbttagcompound.merge(nbttagcompound2);
                    nbttagcompound.setInteger("x", stack.getX());
                    nbttagcompound.setInteger("y", stack.getY());
                    nbttagcompound.setInteger("z", stack.getZ());

                    if (!nbttagcompound.equals(nbttagcompound1))
                    {
                        tileentity.readFromNBT(nbttagcompound);
                        tileentity.markDirty();
                        return true;
                    }
                }
            }

            return false;
        }
    }

    @SideOnly(Side.CLIENT)
    public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack)
    {
        Block block = worldIn.getBlockState(pos).getBlock();

        if (block == Blocks.snow_layer && block.isReplaceable(worldIn, pos))
        {
            side = EnumFacing.UP;
        }
        else if (!block.isReplaceable(worldIn, pos))
        {
            pos = pos.offset(side);
        }

        return worldIn.canBlockBePlaced(this.block, pos, false, side, (Entity)null, stack);
    }

    /**
     * Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
     * different names based on their damage or NBT.
     */
    public String getUnlocalizedName(ItemStack stack)
    {
        return this.block.getUnlocalizedName();
    }

    /**
     * Returns the unlocalized name of this item.
     */
    public String getUnlocalizedName()
    {
        return this.block.getUnlocalizedName();
    }

    /**
     * gets the CreativeTab this item is displayed on
     */
    @SideOnly(Side.CLIENT)
    public CreativeTabs getCreativeTab()
    {
        return this.block.getCreativeTabToDisplayOn();
    }

    /**
     * returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
     */
    @SideOnly(Side.CLIENT)
    public void getSubItems(Item itemIn, CreativeTabs tab, List<ItemStack> subItems)
    {
        this.block.getSubBlocks(itemIn, tab, subItems);
    }

    public Block getBlock()
    {
        return this.block;
    }

    /**
     * Called to actually place the block, after the location is determined
     * and all permission checks have been made.
     *
     * @param stack The item stack that was used to place the block. This can be changed inside the method.
     * @param player The player who is placing the block. Can be null if the block is not being placed by a player.
     * @param side The side the player (or machine) right-clicked on.
     */
    public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState)
    {
        if (!world.setBlockState(pos, newState, 3)) return false;

        IBlockState state = world.getBlockState(pos);
        if (state.getBlock() == this.block)
        {
            setTileEntityNBT(world, player, pos, stack);
            this.block.onBlockPlacedBy(world, pos, state, player, stack);
        }

        return true;
    }
}

(Basically a copy of the ItemBlock class)

Link to comment
Share on other sites

Join the conversation

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

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

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

×   Your previous content has been restored.   Clear editor

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



×
×
  • Create New...

Important Information

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