Jump to content

[1.12] [SOLVED] Moving Half-Slabs


NoEffort

Recommended Posts

Half-Slabs that I've created move their positions from being half_slab_bottom to half_slab_top and I don't know why.

*Note: There are no error messages in console when booting the game, placing the slabs, or opening the world.

 

GitHub: https://github.com/NoEffort/Basic

Video: https://www.youtube.com/watch?v=wh3eUJmlx-w

 

Spoiler

C:\ForgeModded\Basic\src\main\java\com\noeffort\basic\init\slab\CustomBlockSlab.java


package com.noeffort.basic.init.blocks.slab;

import com.noeffort.basic.init.BlockInit;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

import java.util.Random;

public abstract class CustomBlockSlab extends BlockSlab {

    public CustomBlockSlab(String name, float hardness, float resistance) {
        super(Material.WOOD);
        setUnlocalizedName(name);
        setRegistryName(name);

        IBlockState state = this.blockState.getBaseState();

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

        setDefaultState(state);
        this.useNeighborBrightness = true;
    }

    @Override
    public String getUnlocalizedName(int meta) {
        return this.getUnlocalizedName();
    }

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

    @Override
    public Comparable<?> getTypeForItem(ItemStack stack) {
        return EnumBlockHalf.BOTTOM;
    }

    @Override
    public int damageDropped(IBlockState state) {
        return 0;
    }

    @Override
    public IBlockState getStateFromMeta(int meta) {
        if(!this.isDouble()) {
            return this.getDefaultState().withProperty(HALF, EnumBlockHalf.values()[meta % EnumBlockHalf.values().length]);
        }
        return this.getDefaultState();
    }

    @Override
    public int getMetaFromState(IBlockState state) {
        if(!this.isDouble()) {
            return 0;
        }
        return ((EnumBlockHalf)state.getValue(HALF)).ordinal() + 1;
    }

    @Override
    public Item getItemDropped(IBlockState state, Random rand, int fortune) {
        return Item.getItemFromBlock(BlockInit.strange_plank_slab_half);
    }

    @Override
    protected BlockStateContainer createBlockState() {
        return new BlockStateContainer(this, new IProperty[] {HALF});
    }
}

 

Spoiler

C:\ForgeModded\Basic\src\main\java\com\noeffort\basic\init\slab\CustomBlockHalfSlab.java


package com.noeffort.basic.init.blocks.slab;

import net.minecraft.block.SoundType;

public class CustomBlockHalfSlab extends CustomBlockSlab {

    public CustomBlockHalfSlab(String name,float hardness, float resistance, SoundType sound) {
        super(name, hardness, resistance);
        setSoundType(sound);
    }

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

 

Spoiler

C:\ForgeModded\Basic\src\main\java\com\noeffort\basic\init\slab\CustomBlockDoubleSlab.java


package com.noeffort.basic.init.blocks.slab;

import net.minecraft.block.SoundType;

public class CustomBlockDoubleSlab extends CustomBlockSlab {

    public CustomBlockDoubleSlab(String name, float hardness, float resistance, SoundType sound) {
        super(name, hardness, resistance);
        setSoundType(sound);
    }

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

 

Spoiler

C:\ForgeModded\Basic\src\main\java\com\noeffort\basic\init\BlockInit.java


package com.noeffort.basic.init;

import com.noeffort.basic.Basic;
import com.noeffort.basic.init.blocks.CustomBlockStairs;
import com.noeffort.basic.init.blocks.CustomGem;
import com.noeffort.basic.init.blocks.CustomLog;
import com.noeffort.basic.init.blocks.CustomOre;
import com.noeffort.basic.init.blocks.CustomPlank;
import com.noeffort.basic.init.blocks.slab.CustomBlockDoubleSlab;
import com.noeffort.basic.init.blocks.slab.CustomBlockHalfSlab;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemSlab;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.ForgeRegistries;

public class BlockInit {

    public static Block strange_log;
    public static Block strange_plank;
    public static Block strange_ore;
    public static Block nether_strange_ore, end_strange_ore;
    public static Block strange_block;
    public static Block strange_plank_stairs;
    public static CustomBlockHalfSlab strange_plank_slab_half;
    public static CustomBlockDoubleSlab strange_plank_slab_double;

    public static void init() {
        strange_log = new CustomLog("strange_log", 1.0f, 2.0f, 1, SoundType.WOOD);
        strange_plank = new CustomPlank("strange_plank", 1.0f, 2.0f, 1, SoundType.WOOD);
        strange_ore = new CustomOre("strange_ore", 2.0f, 4.0f, 2, SoundType.STONE);
        strange_block = new CustomGem("strange_block", 3.2f, 5.0f, 2, SoundType.METAL);
        nether_strange_ore = new CustomOre("nether_strange_ore", 2.0f, 4.0f, 2, SoundType.STONE);
        end_strange_ore = new CustomOre("end_strange_ore", 2.5f, 4.5f, 2, SoundType.STONE);
        strange_plank_stairs = new CustomBlockStairs("strange_plank_stairs", strange_plank.getDefaultState(), SoundType.WOOD);
        strange_plank_slab_half = new CustomBlockHalfSlab("strange_plank_slab_half", 1.0f, 2.0f, SoundType.WOOD);
        strange_plank_slab_double = new CustomBlockDoubleSlab("strange_plank_slab_double", 1.0f, 2.0f, SoundType.WOOD);
    }

    public static void register() {
        registerBlock(strange_log);
        registerBlock(strange_plank);
        registerBlock(strange_ore);
        registerBlock(strange_block);
        registerBlock(nether_strange_ore);
        registerBlock(end_strange_ore);
        registerBlock(strange_plank_stairs);
        registerBlock(strange_plank_slab_half, new ItemSlab(strange_plank_slab_half, strange_plank_slab_half, strange_plank_slab_double));
        ForgeRegistries.BLOCKS.register(strange_plank_slab_double);
    }

    public static void registerBlock(Block block) {
        ForgeRegistries.BLOCKS.register(block);

        block.setCreativeTab(Basic.basictab);
        ItemBlock item = new ItemBlock(block);
        item.setRegistryName(block.getRegistryName());
        ForgeRegistries.ITEMS.register(item);

        ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0,
                new ModelResourceLocation(block.getRegistryName(), "inventory"));
    }

    public static void registerBlock(Block block, ItemBlock itemBlock) {
        ForgeRegistries.BLOCKS.register(block);

        block.setCreativeTab(Basic.basictab);
        itemBlock.setRegistryName(block.getRegistryName());
        ForgeRegistries.ITEMS.register(itemBlock);

        ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0,
                new ModelResourceLocation(block.getRegistryName(), "inventory"));
    }

}

 

 

All help is appreciated!

Edited by NoEffort
+Added [SOLVED] tag
Link to comment
Share on other sites

Set some break points and run in the debugger. You'll probably run into a place where you're setting a state to its default properties (forgot to append a withProperty?

 

This method is suspicious:

    @Override
    public IBlockState getStateFromMeta(int meta) {
        if(!this.isDouble()) {
            return this.getDefaultState().withProperty(HALF, EnumBlockHalf.values()[meta % EnumBlockHalf.values().length]);
        }
        return this.getDefaultState();
    }

 

Why ignore meta and return default?

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

5 hours ago, NoEffort said:

    @Override
    public int getMetaFromState(IBlockState state) {
        if(!this.isDouble()) {
            return 0;
        }
        return ((EnumBlockHalf)state.getValue(HALF)).ordinal() + 1;
    }

 

In this method, you check whether your slab is not double - then if it is not double you don't store the half in metadata. Then in the corresponding read method you ignore the metadata if the slab is not double. 

Edited by Jay Avery
Link to comment
Share on other sites

2 hours ago, jeffryfisher said:

Set some break points and run in the debugger. You'll probably run into a place where you're setting a state to its default properties (forgot to append a withProperty?

 

This method is suspicious:


    @Override
    public IBlockState getStateFromMeta(int meta) {
        if(!this.isDouble()) {
            return this.getDefaultState().withProperty(HALF, EnumBlockHalf.values()[meta % EnumBlockHalf.values().length]);
        }
        return this.getDefaultState();
    }

 

Why ignore meta and return default?

Because it worked in theory.

Also, the game did crash when setting a breakpoint on this method.

[ALSO] This method did not need to be changed in the end.

 

2 minutes ago, Jay Avery said:

In this method, you check whether your slab is not double - then if it is not double you don't store the half in metadata.

Keen eye, much obliged!

I did not mean to call isDouble() with !

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • sure, here's the link, I hope I did what you wrote about, I just didn't quite understand you ( ._.) https://paste.ee/p/ZXHKZ
    • Keep this post up just in case but I'm using the curseforge launcher and it's working  IM SOO HAPPY
    • Post logs as per https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/ They may have information that will answer these questions.
    • I was left reeling when a glitch on a cryptocurrency exchange caused me to lose $166,000 worth of my hard-earned savings. It felt like my entire world had crumbled in the blink of an eye, leaving me with a sense of hopelessness. Determined not to give up, I delved into research on recovery options, unsure of what to expect. That's when I stumbled upon I was left reeling when a glitch on a cryptocurrency exchange caused me to lose $166,000 worth of my hard-earned savings. It felt like my entire world had crumbled in the blink of an eye, leaving me with a sense of hopelessness. Determined not to give up, I delved into research on recovery options, unsure of what to expect. That's when I stumbled upon DIGITAL HACK RECOVERY, a beacon of hope in my darkest hour. Despite my initial doubts, I decided to take a leap of faith and give them a shot as a final lifeline. The experts at DIGITAL HACK RECOVERY proved to be masters of their craft, guiding me through their exclusive process with precision and expertise. Utilizing cutting-edge blockchain analysis methods, they were able to track down the elusive trail of my missing funds and identify the exact point of failure. Their forensic talents were unparalleled as they tirelessly combed through the intricate web of blockchain data to locate my cryptocurrency. With each step they took, they kept me informed of their progress, never wavering in their belief that my funds could be rescued. After several painstaking weeks, DIGITAL HACK RECOVERY finally located and restored my $166,000 worth of cryptocurrency. I was awestruck that they were able to salvage what I had thought was lost forever. The whole experience restored my faith in the crypto space and proved that even in the worst situations, recovery is possible with the right experts on your side. I will be forever grateful to DIGITAL HACK RECOVERY for giving me back my life savings when I needed it most. Their tireless efforts and technical mastery turned what could have been a devastating loss into an uplifting success story. Book a time with DIGITAL HACK RECOVERY through: digital hack recovery @ techie . com &  +12018871705
  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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