Jump to content

[1.12] Half slabs display issue when smooth lighting is off?


Recommended Posts

Posted

Hi all,

 

I have custom slabs that should normally behave exactly like normal ones as far as the display is concerned. When smooth lightning is on (minimum or maximum), it works fine. When smooth lightning is off, the top part of the slab (or the bottom if it's a top slab) is shown as a dark area.

 

Here is my class:

package org.millenaire.common.block;

import java.util.Random;

import org.millenaire.common.forge.Mill;
import org.millenaire.common.item.IMetaBlockName;

import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public abstract class BlockPath extends BlockSlab implements IMetaBlockName {

	public static class BlockPathDouble extends BlockPath {
		public BlockPathDouble(final String blockName, MapColor color) {
			super(blockName, color);
		}

		@Override
		public boolean isDouble() {
			return true;
		}
	}

	public static class BlockPathSlab extends BlockPath {
		public BlockPathSlab(final String blockName, MapColor color) {
			super(blockName, color);
		}

		@Override
		public boolean isDouble() {
			return false;
		}
	}
	
	public static enum Variant implements IStringSerializable {
		DEFAULT;

		@Override
		public String getName() {
			return "default";
		}
	}

	//Variant with only default as slab-related blocks need them
	public static final PropertyEnum<Variant> VARIANT = PropertyEnum.<Variant>create("variant", Variant.class);
	//whether the path is "stable", i.e. villagers won't clear it. All player-laid pathes are stable.
	public static final PropertyBool STABLE = PropertyBool.create("stable");

	
	private final String singleSlabBlockName, doubleSlabName;

	/**
	 * singleSlabBlockName to have a reference to it for item drops
	 */
	public BlockPath(final String blockName, MapColor color) {
		super(Material.GROUND, color);
		
		singleSlabBlockName = blockName + "_slab";
		doubleSlabName = blockName;
		
		//same for single and double slabs
		setUnlocalizedName(Mill.MODID + "." + doubleSlabName);
		
		if (this.isDouble()) {			
			setRegistryName(doubleSlabName);
		} else {
			setRegistryName(singleSlabBlockName);
		}

		IBlockState iblockstate = this.blockState.getBaseState();

		iblockstate = iblockstate.withProperty(STABLE, false);

		if (!this.isDouble()) {
			iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM);
		}

		this.setDefaultState(iblockstate);

		setHarvestLevel("shovel", 0);
		setHardness(0.8F);
		setCreativeTab(MillBlocks.tabMillenaire);
		setSoundType(SoundType.GROUND);
	}

	@Override
	protected BlockStateContainer createBlockState() {
		return this.isDouble() ? new BlockStateContainer(this, new IProperty[] { VARIANT, STABLE })
				: new BlockStateContainer(this, new IProperty[] { VARIANT, HALF, STABLE });
	}

	/**
	 * Gets the metadata of the item this Block can drop. This method is called when
	 * the block gets destroyed. It returns the metadata of the dropped item based
	 * on the old metadata of the block.
	 */
	@Override
	public int damageDropped(final IBlockState state) {
		return 0;
	}

	@Override
	public ItemStack getItem(final World worldIn, final BlockPos pos, final IBlockState state) {
		return new ItemStack(Block.getBlockFromName(Mill.MODID+":"+singleSlabBlockName), 1, 0);
	}

	/**
	 * Unlike regular slabs we drop the version corresponding to the actual block
	 */
	@Override
	public Item getItemDropped(final IBlockState state, final Random rand, final int fortune) {
		if (isDouble())
			return Item.getItemFromBlock(Block.getBlockFromName(Mill.MODID+":"+doubleSlabName));
		else
			return Item.getItemFromBlock(Block.getBlockFromName(Mill.MODID+":"+singleSlabBlockName));
	}

	/**
	 * Convert the BlockState into the correct metadata value
	 */
	@Override
	public int getMetaFromState(final IBlockState state) {
		int i = 0;

		if (state.getValue(STABLE)) {
			i |= 1;
		}

		if (!this.isDouble() && (state.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP)) {
			i |= 8;
		}

		return i;
	}

	/**
	 * Convert the given metadata into a BlockState for this Block
	 */
	@Override
	public IBlockState getStateFromMeta(final int meta) {
		IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT, Variant.DEFAULT);
		
		if ((meta & 1) == 1) {
			iblockstate = iblockstate.withProperty(STABLE, true);
		}

		if (!this.isDouble()) {
			iblockstate = iblockstate.withProperty(HALF,
					(meta & 8) == 0 ? BlockSlab.EnumBlockHalf.BOTTOM : BlockSlab.EnumBlockHalf.TOP);
		}

		return iblockstate;
	}

	@Override
	public String getUnlocalizedName(int meta) {
		//we don't actually have variants for this block
		return getUnlocalizedName();
	}
	
	@SideOnly(Side.CLIENT)
	public void initModel() {
		if (isDouble()) {
			ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0,
					new ModelResourceLocation(getRegistryName(), "stable=false,variant=default"));
		} else {
			ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0,
					new ModelResourceLocation(getRegistryName(), "half=bottom,stable=false,variant=default"));
		}
			
	}
	
	@Override
	public Comparable<?> getTypeForItem(final ItemStack stack) {
		return Variant.DEFAULT;
	}

	@Override
	public IProperty<?> getVariantProperty() {
		return VARIANT;
	}

	@Override
	public String getSpecialName(final ItemStack stack) {
		//we don't actually have variants for this block
		return getUnlocalizedName();
	}
	
	/*
	 * Gets the single slab of this block, whether or not it is the single block itself
	 */
	public BlockPath getSingleSlab() {
		return (BlockPath)Block.getBlockFromName(Mill.MODID+":"+singleSlabBlockName);
	}
	
	/*
	 * Gets the double slab of this block, whether or not it is the double block itself
	 */
	public BlockPath getDoubleSlab() {
		return (BlockPath)Block.getBlockFromName(Mill.MODID+":"+doubleSlabName);
	}
	
	/*
	 * Unlike normal slabs we always drop 1 since double blocks drop a full block
	 */
	public int quantityDropped(Random random)
    {
        return 1;
    }
	
	/*
	 * Overriding the one from BlockSlab that can't deal without double slabs being set directly
	 * 	 */
	@Override
	public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
    {
        
        if (this.isDouble())
        {
            return getStateFromMeta(meta).withProperty(STABLE, true);
        }
        else
        {
        	IBlockState iblockstate = super.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM).withProperty(STABLE, true);

            return facing != EnumFacing.DOWN && (facing == EnumFacing.UP || (double)hitY <= 0.5D) ? iblockstate : iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.TOP);
        }
    }
}

 

One of my blockstate:

{
	"forge_marker": 1,
	"variants": {
		"half=bottom,stable=false,variant=default": {
			"model": "millenaire:pathsandstone_bottom"
		},
		"half=top,stable=false,variant=default": {
			"model": "millenaire:pathsandstone_top"
		},
		"half=bottom,stable=true,variant=default": {
			"model": "millenaire:pathsandstone_bottom"
		},
		"half=top,stable=true,variant=default": {
			"model": "millenaire:pathsandstone_top"
		}
	}
}

 

And one of my block model:

 

{
    "parent": "block/half_slab",
    "textures": {
        "bottom": "millenaire:blocks/pathbottom",
        "top": "millenaire:blocks/pathsandstone",
        "side": "millenaire:blocks/pathsandstone_halfside",
        "particle" : "millenaire:blocks/pathsandstone"
    }
}

 

Those two JSONs are pretty much identical to those used by Minecraft's slabs, with just particles added to the model.

 

Must be something stupid, but what? Any ideas?

 

Thanks!

 

2018-02-24_18.20.29.png

Posted

As I discovered in this topic, you need to set Block#useNeighborBrightness to true. For some reason, Vanilla does this in Block.registerBlocks instead of in the constructors of the appropriate Block classes.

  • Like 2

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • 4 weeks later...

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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