How to make Rotatable Block [VIDEO TUTORIAL]

Started by Nuparu00 on

Topic category: User side tutorials

Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to make Rotatable Block [VIDEO TUTORIAL]
Wed, 01/04/2017 - 20:31 (edited)

Hi. Because there is not his feature in MCreater itself and many of you need it for your mod , I decided to make a video tutorial how to make custom block rotatable , using PropertyDirection.
LINK

 

 

Edited by Klemen on Wed, 01/04/2017 - 20:31
Joined Jul 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I couldn't make much sense…
Fri, 08/24/2018 - 00:44

I couldn't make much sense of the video tutorial, even after rewatching it like 3 times, i'm proberally just being an idiot...

Joined Aug 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yeah, this tutorial needs an…
Mon, 09/17/2018 - 01:03

Yeah, this tutorial needs an update, the descrption of the video is tangled I can't tell where each part of the coe goes.

Joined Aug 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Here, since you rather work…
Mon, 09/17/2018 - 21:32

Here, since you rather work with code, becoue I can't understand the instructions in the description whatsoever!

package mod.mcreator;

import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
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.EnumFacing;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.Item;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.Minecraft;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.material.Material;
import net.minecraft.block.SoundType;
import net.minecraft.block.Block;

import java.util.Random;

public class mcreator_rottableInfuser {

    public mcreator_rottableInfuser() {
    }

    public static BlockRottableInfuser block;
    public static Item item;
    public static Object instance;

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

    public void serverLoad(FMLServerStartingEvent event) {
    }

    public void preInit(FMLPreInitializationEvent event) {
        block.setRegistryName("rottableinfuser");
        ForgeRegistries.BLOCKS.register(block);
        item = new ItemBlock(block).setRegistryName(block.getRegistryName());
        ForgeRegistries.ITEMS.register(item);
    }

    public void registerRenderers() {
    }

    public void load(FMLInitializationEvent event) {
        if (event.getSide() == Side.CLIENT) {
            Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
                    .register(item, 0, new ModelResourceLocation("testenvironmentmod:rottableinfuser", "inventory"));
        }
    }

    static {
        block = (BlockRottableInfuser) (new BlockRottableInfuser().setHardness(2.0F).setResistance(10.0F).setLightLevel(0.0F)
                .setUnlocalizedName("rottableinfuser").setLightOpacity(0).setCreativeTab(CreativeTabs.BUILDING_BLOCKS));
        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 BlockRottableInfuser extends Block {

        int a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, a6 = 0;
        boolean red = false;
        public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);

        protected BlockRottableInfuser() {
            super(Material.ROCK);
            setSoundType(SoundType.STONE);
            this.setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
        }

        @Override
        public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
            int i = pos.getX();
            int j = pos.getY();
            int k = pos.getZ();
            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;
        }

        @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;
        }

        @Override
        public IBlockState getStateFromMeta(int meta) {
            EnumFacing facing = EnumFacing.getFront(meta);
            if (facing.getAxis() == EnumFacing.Axis.Y) {
                facing = EnumFacing.NORTH;
            }
            return getDefaultState().withProperty(FACING, facing);
        }
          @Override
          public int getMetaFromState(IBlockState state) {
          return ((EnumFacing) state.getValue(FACING)).getIndex();
          }
          getStateForPlacement
          @Override
          protected BlockStateContainer createBlockState() {
          return new BlockStateContainer(this, new IProperty[]{FACING});
          }
          @Override
          public IBlockState getStateForPlacement(World worldIn, BlockPos pos,
          EnumFacing facing, float hitX, float hitY, float hitZ, int meta,
          EntityLivingBase placer) {
          return getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
          }
        
    }
}