How to make minecraft-like slab?

Started by Dary on Thu, 11/14/2019 - 13:56

Topic category: Advanced modding

Last seen on 12:23, 6. Dec 2019
Joined Nov 2019
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
How to make minecraft-like slab?
Thu, 11/14/2019 - 13:56

Hello,

I'm trying to create slab like in vanilla minecraft.When I tried to modify slab class to extend .BlockSlab it doesn't compile:

C:\Users\Dary\MCreatorWorkspaces\travelers_dream_blocks\build\sources\main\java\net\mcreator\travelers_dream_blocks\MCreatorSlabAlter.java:59: error: BlockCustom is not abstract and does not override abstract method getTypeForItem(ItemStack) in BlockSlab
	public static class BlockCustom extends BlockSlab {
	              ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

When I made some changes, this log and the next ones asked me (mostly changing some static to abstract etc) to make it built without showing any errors,the client shut up on initialization silently.I exported .jar and tested in other client and it crashes with that:

PM
Description: Initializing game

java.lang.NullPointerException: Initializing game
	at net.mcreator.travelers_dream_blocks.MCreatorSlabAlter.lambda$initElements$0(MCreatorSlabAlter.java:43)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:545)
	at java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
	at java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:438)
	at net.mcreator.travelers_dream_blocks.travelers_dream_blocks.registerItems(travelers_dream_blocks.java:92)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_261_travelers_dream_blocks_registerItems_Register.invoke(.dynamic)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
	at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:144)
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
	at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:807)
	at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:628)
	at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:252)
	at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:467)
	at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:378)
	at net.minecraft.client.main.Main.main(SourceFile:123)
	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:498)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

 

0Upvote this forum topic
Last seen on 12:23, 6. Dec 2019
Joined Nov 2019
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
slab class: package net…
Thu, 11/14/2019 - 13:59

slab class:


package net.mcreator.travelers_dream_blocks;

import net.minecraftforge.oredict.OreDictionary;
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.FMLInitializationEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.event.ModelRegistryEvent;

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.ItemBlock;
import net.minecraft.item.Item;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.material.Material;
import net.minecraft.block.SoundType;
import net.minecraft.block.BlockDirectional;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;


@Elementstravelers_dream_blocks.ModElement.Tag
public class MCreatorSlabAlter extends Elementstravelers_dream_blocks.ModElement {
	@GameRegistry.ObjectHolder("travelers_dream_blocks:slabalter")
	public static final Block block = null;

	public MCreatorSlabAlter(Elementstravelers_dream_blocks instance) {
		super(instance, 19);
	}

	@Override
	public void initElements() {
		elements.blocks.add(() -> new BlockCustom());
		elements.items.add(() -> new ItemBlock(block).setRegistryName(block.getRegistryName()));
	}

	@Override
	public void init(FMLInitializationEvent event) {
		OreDictionary.registerOre("slabWood", block);
	}

	@SideOnly(Side.CLIENT)
	@Override
	public void registerModels(ModelRegistryEvent event) {
		ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation("travelers_dream_blocks:slabalter",
				"inventory"));
	}

	public static class BlockCustom extends BlockSlab {
		public static final PropertyDirection FACING = BlockDirectional.FACING;

		public BlockCustom() {
			super(Material.WOOD);
			setRegistryName("slabalter");
			setUnlocalizedName("slabalter");
			setSoundType(SoundType.WOOD);
			setHarvestLevel("axe", 1);
			setHardness(2F);
			setResistance(15F);
			setLightLevel(0F);
			setLightOpacity(0);
			setCreativeTab(MCreatorTravelersDream.tab);
			this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.SOUTH));
		}

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

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

		@Override
		public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
			switch ((EnumFacing) state.getValue(BlockDirectional.FACING)) {
				case SOUTH :
				default :
					return new AxisAlignedBB(1D, 0D, 1D, 0D, 0.5D, 0D);
				case NORTH :
					return new AxisAlignedBB(0D, 0D, 0D, 1D, 0.5D, 1D);
				case WEST :
					return new AxisAlignedBB(0D, 0D, 1D, 1D, 0.5D, 0D);
				case EAST :
					return new AxisAlignedBB(1D, 0D, 0D, 0D, 0.5D, 1D);
				case UP :
					return new AxisAlignedBB(0D, 1D, 0D, 1D, 0D, 0.5D);
				case DOWN :
					return new AxisAlignedBB(0D, 0D, 1D, 1D, 1D, 0.5D);
			}
		}

		@Override
		protected net.minecraft.block.state.BlockStateContainer createBlockState() {
			return new net.minecraft.block.state.BlockStateContainer(this, new IProperty[]{FACING});
		}

		@Override
		public IBlockState getStateFromMeta(int meta) {
			return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta));
		}

		@Override
		public int getMetaFromState(IBlockState state) {
			return ((EnumFacing) state.getValue(FACING)).getIndex();
		}

		@Override
		public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta,
				EntityLivingBase placer) {
			if (facing == EnumFacing.WEST || facing == EnumFacing.EAST)
				facing = EnumFacing.UP;
			else if (facing == EnumFacing.NORTH || facing == EnumFacing.SOUTH)
				facing = EnumFacing.EAST;
			else
				facing = EnumFacing.SOUTH;
			return this.getDefaultState().withProperty(FACING, facing);
		}

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

		@Override
		public boolean isFlammable(IBlockAccess blockAccess, BlockPos pos, EnumFacing face) {
			return true;
		}

		@Override
		public boolean canSilkHarvest(World world, BlockPos pos, IBlockState state, EntityPlayer player) {
			return false;
		}
	}
}

 

0Upvote this forum topic
Last seen on 12:23, 6. Dec 2019
Joined Nov 2019
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
* that class is after adding…
Thu, 11/14/2019 - 14:01

* that class is after adding import and extending BlockSlab, but before any other changes, which I did without any understanding))

0Upvote this forum topic
There is a lot to do to…
Thu, 11/14/2019 - 18:22

There is a lot to do to override vanilla slab. We would add support for them if we had it figured out but we did not yet.

0Upvote this forum topic
Last seen on 12:23, 6. Dec 2019
Joined Nov 2019
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Thank you for the reply!
Fri, 11/22/2019 - 13:57

Thank you for the reply!

0Upvote this forum topic