Cake like Properties

Started by SqueezeTheC4 on Wed, 12/21/2016 - 15:38

Topic category: Help with MCreator's application

Last seen on 19:36, 9. Feb 2018
Joined Sep 2016
User points:

User statistics:

  • Modifications:
  • Mods of the week:
  • Forum topics:
  • Comments:
  • Wiki pages:
  • Tracker tickets:
  • Invalid tickets:
Cake like Properties
Wed, 12/21/2016 - 15:38

Hello there, I am making a Mod in where everytime a certain block is clicked, it will remove a chunk of it. Like a cake!!. However, I cannot seem to make this work. Its not food, it is a block. So does anyone know how to take away chunks of a block when clicked, like cake. Thank You :)

0Upvote this forum topic
Last seen on 19:36, 9. Feb 2018
Joined Sep 2016
User points:

User statistics:

  • Modifications:
  • Mods of the week:
  • Forum topics:
  • Comments:
  • Wiki pages:
  • Tracker tickets:
  • Invalid tickets:
If you mean code for the
Sat, 12/24/2016 - 13:50

If you mean code for the block then here it is:

package mod.mcreator;

import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import net.minecraft.world.World;
import net.minecraft.world.IBlockAccess;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.init.Items;
import net.minecraft.init.Blocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.Minecraft;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.material.Material;
import net.minecraft.block.SoundType;
import net.minecraft.block.Block;

import java.util.Random;

public class mcreator_blueIceTub {

    public mcreator_blueIceTub() {
    }

    public static BlockBlueIceTub block;

    public static Object instance;

    public int addFuel(ItemStack fuel) {
        return 0;
    }

    public void serverLoad(FMLServerStartingEvent event) {
    }

    public void preInit(FMLPreInitializationEvent event) {
    }

    public void registerRenderers() {
    }

    public void load(FMLInitializationEvent event) {
        if (event.getSide() == Side.CLIENT) {
            Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
                    .register(Item.getItemFromBlock(block), 0, new ModelResourceLocation("TestEnvironmentMod:BlueIceTub", "inventory"));
        }

        GameRegistry.addRecipe(new ItemStack(block, 1),
                new Object[]{"012", "345", "678", Character.valueOf('0'), new ItemStack(Blocks.WOOL, 1, 15), Character.valueOf('1'),
                        new ItemStack(Blocks.WOOL, 1, 15), Character.valueOf('2'), new ItemStack(Blocks.WOOL, 1, 15), Character.valueOf('3'),
                        new ItemStack(Items.DYE, 1, 12), Character.valueOf('4'), Blocks.ICE, Character.valueOf('5'), new ItemStack(Items.DYE, 1, 12),
                        Character.valueOf('6'), new ItemStack(Blocks.WOOL, 1, 15), Character.valueOf('7'), new ItemStack(Blocks.WOOL, 1, 15),
                        Character.valueOf('8'), new ItemStack(Blocks.WOOL, 1, 15),});
    }

    static {

        block = (BlockBlueIceTub) (new BlockBlueIceTub().setHardness(2.0F).setResistance(10.0F).setLightLevel(0.0F).setUnlocalizedName("BlueIceTub")
                .setLightOpacity(0).setCreativeTab(mcreator_gfuel.tab));
        block.setHarvestLevel("pickaxe", 0);
    }

    public void generateSurface(World world, Random random, int chunkX, int chunkZ) {
    }

    public void generateNether(World world, Random random, int chunkX, int chunkZ) {
    }

    static class BlockBlueIceTub extends Block {

        int a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, a6 = 0;

        boolean red = false;

        protected BlockBlueIceTub() {
            super(Material.IRON);

            GameRegistry.registerBlock(this, "BlueIceTub");
            setSoundType(SoundType.WOOD);

        }

        @Override
        public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
            int i = pos.getX();
            int j = pos.getY();
            int k = pos.getZ();
            EntityPlayer entity = Minecraft.getMinecraft().thePlayer;
            world.scheduleUpdate(new BlockPos(i, j, k), this, this.tickRate(world));

        }

        @Override
        public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
            return red ? 15 : 0;
        }

        @Override
        public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
            return red ? 15 : 0;
        }

        @Override
        public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entity, EnumHand hand, ItemStack heldItem,
                EnumFacing side, float hitX, float hitY, float hitZ) {
            int i = pos.getX();
            int j = pos.getY();
            int k = pos.getZ();
            if (true) {
                if (entity instanceof EntityPlayer)
                    ((EntityPlayer) entity).inventory.addItemStackToInventory(new ItemStack(mcreator_blueIcePowder.block, 1));
            }

            return true;
        }

        @SideOnly(Side.CLIENT)
        @Override
        public BlockRenderLayer getBlockLayer() {
            return BlockRenderLayer.SOLID;
        }

        @Override
        public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
            return new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
        }

        @Override
        public int tickRate(World world) {
            return 10;
        }

        @Override
        public int quantityDropped(Random par1Random) {
            return 1;
        }

    }
}

 

0Upvote this forum topic
Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

User statistics:

  • Modifications:
  • Mods of the week:
  • Forum topics:
  • Comments:
  • Wiki pages:
  • Tracker tickets:
  • Invalid tickets:
This could work (but you will
Sat, 12/24/2016 - 14:12

This could work (but you will also must edit blockstate .json file , else you will get black-purple block, you can take a look on the vanilla cake .json file):

[spoiler]

package mod.mcreator;

import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import net.minecraft.world.World;
import net.minecraft.world.IBlockAccess;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.init.Items;
import net.minecraft.init.Blocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.Minecraft;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.material.Material;
import net.minecraft.block.SoundType;
import net.minecraft.block.Block;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import java.util.Random;

public class mcreator_blueIceTub {

    public mcreator_blueIceTub() {
    }

    public static BlockBlueIceTub block;

    public static Object instance;

    public int addFuel(ItemStack fuel) {
        return 0;
    }

    public void serverLoad(FMLServerStartingEvent event) {
    }

    public void preInit(FMLPreInitializationEvent event) {
    }

    public void registerRenderers() {
    }

    public void load(FMLInitializationEvent event) {
        if (event.getSide() == Side.CLIENT) {
            Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
                    .register(Item.getItemFromBlock(block), 0, new ModelResourceLocation("TestEnvironmentMod:BlueIceTub", "inventory"));
        }

        GameRegistry.addRecipe(new ItemStack(block, 1),
                new Object[]{"012", "345", "678", Character.valueOf('0'), new ItemStack(Blocks.WOOL, 1, 15), Character.valueOf('1'),
                        new ItemStack(Blocks.WOOL, 1, 15), Character.valueOf('2'), new ItemStack(Blocks.WOOL, 1, 15), Character.valueOf('3'),
                        new ItemStack(Items.DYE, 1, 12), Character.valueOf('4'), Blocks.ICE, Character.valueOf('5'), new ItemStack(Items.DYE, 1, 12),
                        Character.valueOf('6'), new ItemStack(Blocks.WOOL, 1, 15), Character.valueOf('7'), new ItemStack(Blocks.WOOL, 1, 15),
                        Character.valueOf('8'), new ItemStack(Blocks.WOOL, 1, 15),});
    }

    static {

        block = (BlockBlueIceTub) (new BlockBlueIceTub().setHardness(2.0F).setResistance(10.0F).setLightLevel(0.0F).setUnlocalizedName("BlueIceTub")
                .setLightOpacity(0).setCreativeTab(mcreator_gfuel.tab));
        block.setHarvestLevel("pickaxe", 0);
    }

    public void generateSurface(World world, Random random, int chunkX, int chunkZ) {
    }

    public void generateNether(World world, Random random, int chunkX, int chunkZ) {
    }

    static class BlockBlueIceTub extends Block {

        int a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, a6 = 0;
public static final PropertyInteger BITES = PropertyInteger.create("bites", 0, 6);
        boolean red = false;

        protected BlockBlueIceTub() {
            super(Material.IRON);
              this.setDefaultState(this.blockState.getBaseState().withProperty(BITES, Integer.valueOf(0)));
        this.setTickRandomly(true);
            GameRegistry.registerBlock(this, "BlueIceTub");
            setSoundType(SoundType.WOOD);

        }

        @Override
        public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
            int i = pos.getX();
            int j = pos.getY();
            int k = pos.getZ();
            EntityPlayer entity = Minecraft.getMinecraft().thePlayer;
            world.scheduleUpdate(new BlockPos(i, j, k), this, this.tickRate(world));

        }

        public boolean isFullCube(IBlockState state)
    {
        return false;
    }

    public boolean isOpaqueCube(IBlockState state)
    {
        return false;
    }

       @Override
        public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entity, EnumHand hand, ItemStack heldItem,
                EnumFacing side, float hitX, float hitY, float hitZ) {
            int i = pos.getX();
            int j = pos.getY();
            int k = pos.getZ();
            if (true) {
                if (entity instanceof EntityPlayer)
                    ((EntityPlayer) entity).inventory.addItemStackToInventory(new ItemStack(mcreator_blueIcePowder.block, 1));
                  int i = ((Integer)state.getValue(BITES)).intValue();

            if (i < 6)
            {
                world.setBlockState(pos, state.withProperty(BITES, Integer.valueOf(i + 1)), 3);
            }
            else
            {
                world.setBlockToAir(pos);
            }
            }

            return true;
        }

        @SideOnly(Side.CLIENT)
        @Override
        public BlockRenderLayer getBlockLayer() {
            return BlockRenderLayer.SOLID;
        }

        public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(BITES, Integer.valueOf(meta));
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(IBlockState state)
    {
        return ((Integer)state.getValue(BITES)).intValue();
    }

    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {BITES});
    }

    public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos)
    {
        return (7 - ((Integer)blockState.getValue(BITES)).intValue()) * 2;
    }

    }
}
[/spoiler]

0Upvote this forum topic
Last seen on 21:01, 26. Jan 2020
Joined Oct 2013
User points:

User statistics:

  • Modifications:
  • Mods of the week:
  • Forum topics:
  • Comments:
  • Wiki pages:
  • Tracker tickets:
  • Invalid tickets:
RE:Can I see your code I am not
Mon, 09/25/2017 - 18:46

@#9 when i did it it gave me a error

0Upvote this forum topic
Last seen on 21:01, 26. Jan 2020
Joined Oct 2013
User points:

User statistics:

  • Modifications:
  • Mods of the week:
  • Forum topics:
  • Comments:
  • Wiki pages:
  • Tracker tickets:
  • Invalid tickets:
RE:RE:Can I see your code I am not
Mon, 09/25/2017 - 18:48

@#9.1 oh nvm

0Upvote this forum topic