Jump to content

[SOLVED][1.9] Glass slab glitch


JimiIT92

Recommended Posts

I'm using this class to make some slabs. However one of this is a glass slab, and so it needs to be transparent. The texture it is, but when placed down it glitches the block below, but only the double or the bottom slab, doing this

Qs5B1kM.png

I've already tried adding the BlockGlass methods (isOpaque/isFullCube) but the glitch reamin :/

This is the class i use

package com.mwvanilla.blocks;

import java.util.List;
import java.util.Random;

import com.mineworld.blocks.ores.BlockOreSlab;
import com.mwvanilla.core.MWVanillaSlabs;
import com.mwvanilla.core.MWVanillaTabs;

import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.BlockSlab.EnumBlockHalf;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public abstract class BlockVanillaSlab extends BlockSlab
{
    public static final PropertyEnum<BlockVanillaSlab.Variant> VARIANT = PropertyEnum.<BlockVanillaSlab.Variant>create("variant", BlockVanillaSlab.Variant.class);
    private Block block;
    public BlockVanillaSlab(Block block)
    {
        super(block.getDefaultState().getMaterial());
        this.block = block;
        IBlockState iblockstate = this.blockState.getBaseState();

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

        this.setDefaultState(iblockstate.withProperty(VARIANT, BlockVanillaSlab.Variant.DEFAULT));
        this.setHardness(block.getBlockHardness(block.getDefaultState(), null, null));
        this.setResistance(block.getExplosionResistance(null));
        this.setStepSound(this.block.getStepSound());
        if(this.block.equals(Blocks.glowstone))
        	this.setLightLevel(0.75F);
        if(this.block.equals(Blocks.sea_lantern))
        	this.setLightLevel(1.0F);
	this.useNeighborBrightness = !this.isDouble();
    }
    
    @SideOnly(Side.CLIENT)
    public BlockRenderLayer getBlockLayer()
    {
        return this.block.getDefaultState().getMaterial().equals(Material.glass) ? BlockRenderLayer.CUTOUT : BlockRenderLayer.SOLID;
    }
            
    protected boolean canSilkHarvest()
    {
        return this.block.getDefaultState().getMaterial().equals(Material.glass);
    }
    
    @Override
public boolean canProvidePower(IBlockState state) {
	return this.block.equals(Blocks.redstone_block);
}

@Override
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
	return  this.block.equals(Blocks.redstone_block) ? 15 : 0;
}

    /**
     * Get the Item that this Block should drop when harvested.
     */
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        return this.block.getDefaultState().getMaterial().equals(Material.glass) ? null : Item.getItemFromBlock(this);
    }

    public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
    {
        return new ItemStack(Item.getItemFromBlock(this));
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public IBlockState getStateFromMeta(int meta)
    {
        IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT, BlockVanillaSlab.Variant.DEFAULT);

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

        return iblockstate;
    }

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

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

        return i;
    }

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

    /**
     * Returns the slab block name with the type associated with it
     */
    public String getUnlocalizedName(int meta)
    {
        return super.getUnlocalizedName();
    }

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

    public Comparable<?> getTypeForItem(ItemStack stack)
    {
        return BlockVanillaSlab.Variant.DEFAULT;
    }

    public static enum Variant implements IStringSerializable
    {
        DEFAULT;

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

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

I've already looked at that classes. Already added in the slab class the getBlockLayer function and the canSilkHarvest function. The only functions not added are the isFullCube, the isOpaque and the shouldSideBeRendered. Adding the isFullCube didn't change, overriding the shouldSideBeRendered to call the supermethod if the material isn't glass or running the same code of the BlockBreakable class if it is also didn't change. So i've added the last function, isOpaque, returning always false, but then the game crashes as i place a double slab (also the glitch persist). The class is now looking like this

package com.mwvanilla.blocks;

import java.util.List;
import java.util.Random;

import com.mineworld.blocks.ores.BlockOreSlab;
import com.mwvanilla.core.MWVanillaSlabs;
import com.mwvanilla.core.MWVanillaTabs;

import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.BlockSlab.EnumBlockHalf;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public abstract class BlockVanillaSlab extends BlockSlab
{
    public static final PropertyEnum<BlockVanillaSlab.Variant> VARIANT = PropertyEnum.<BlockVanillaSlab.Variant>create("variant", BlockVanillaSlab.Variant.class);
    private Block block;
    public BlockVanillaSlab(Block block)
    {
        super(block.getDefaultState().getMaterial());
        this.block = block;
        IBlockState iblockstate = this.blockState.getBaseState();

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

        this.setDefaultState(iblockstate.withProperty(VARIANT, BlockVanillaSlab.Variant.DEFAULT));
        this.setHardness(block.getBlockHardness(block.getDefaultState(), null, null));
        this.setResistance(block.getExplosionResistance(null));
        this.setStepSound(this.block.getStepSound());
        if(this.block.equals(Blocks.glowstone))
        	this.setLightLevel(0.75F);
        if(this.block.equals(Blocks.sea_lantern))
        	this.setLightLevel(1.0F);
	this.useNeighborBrightness = !this.isDouble();
    }
    
    public boolean isFullCube(IBlockState state)
    {
        return false;
    }
    
    public boolean isOpaqueCube(IBlockState state)
    {
        return false;
    }
    
    @Override
    public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos,
    		EnumFacing side) {
    	if(this.block.getDefaultState().getMaterial().equals(Material.glass)) {
    		IBlockState iblockstate = blockAccess.getBlockState(pos.offset(side));
            Block block = iblockstate.getBlock();
            if (blockState != iblockstate)
            {
                return true;
            }

            if (block == this)
            {
                return false;
            }
            
            return block == this ? false : super.shouldSideBeRendered(blockState, blockAccess, pos, side);
    	}
    	return this.isDouble() ? true : super.shouldSideBeRendered(blockState, blockAccess, pos, side);
    }
    
    @SideOnly(Side.CLIENT)
    public BlockRenderLayer getBlockLayer()
    {
        return this.block.getDefaultState().getMaterial().equals(Material.glass) ? BlockRenderLayer.CUTOUT : BlockRenderLayer.SOLID;
    }
            
    protected boolean canSilkHarvest()
    {
        return !this.isDouble();
    }
    
    @Override
public boolean canProvidePower(IBlockState state) {
	return this.block.equals(Blocks.redstone_block);
}

@Override
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
	return  this.block.equals(Blocks.redstone_block) ? 15 : 0;
}

    /**
     * Get the Item that this Block should drop when harvested.
     */
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        return this.block.getDefaultState().getMaterial().equals(Material.glass) ? null : Item.getItemFromBlock(this);
    }

    public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
    {
        return new ItemStack(Item.getItemFromBlock(this));
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public IBlockState getStateFromMeta(int meta)
    {
        IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT, BlockVanillaSlab.Variant.DEFAULT);

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

        return iblockstate;
    }

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

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

        return i;
    }

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

    /**
     * Returns the slab block name with the type associated with it
     */
    public String getUnlocalizedName(int meta)
    {
        return super.getUnlocalizedName();
    }

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

    public Comparable<?> getTypeForItem(ItemStack stack)
    {
        return BlockVanillaSlab.Variant.DEFAULT;
    }

    public static enum Variant implements IStringSerializable
    {
        DEFAULT;

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

 

And this is the crash i have

java.lang.IllegalArgumentException: Cannot get property PropertyEnum{name=half, clazz=class net.minecraft.block.BlockSlab$EnumBlockHalf, values=[top, bottom]} as it does not exist in BlockStateContainer{block=mw:glass_double_slab, properties=[variant]}
at net.minecraft.block.state.BlockStateContainer$StateImplementation.getValue(BlockStateContainer.java:192)
at net.minecraft.block.BlockSlab.doesSideBlockRendering(BlockSlab.java:67)
at net.minecraft.block.state.BlockStateContainer$StateImplementation.doesSideBlockRendering(BlockStateContainer.java:468)
at net.minecraft.block.Block.shouldSideBeRendered(Block.java:516)
at net.minecraft.block.state.BlockStateContainer$StateImplementation.shouldSideBeRendered(BlockStateContainer.java:408)
at net.minecraftforge.client.model.pipeline.ForgeBlockModelRenderer.render(ForgeBlockModelRenderer.java:113)
at net.minecraftforge.client.model.pipeline.ForgeBlockModelRenderer.renderModelSmooth(ForgeBlockModelRenderer.java:84)
at net.minecraft.client.renderer.BlockModelRenderer.renderModel(BlockModelRenderer.java:45)
at net.minecraft.client.renderer.BlockModelRenderer.renderModel(BlockModelRenderer.java:36)
at net.minecraft.client.renderer.BlockRendererDispatcher.renderBlock(BlockRendererDispatcher.java:81)
at net.minecraft.client.renderer.chunk.RenderChunk.rebuildChunk(RenderChunk.java:196)
at net.minecraft.client.renderer.chunk.ChunkRenderWorker.processTask(ChunkRenderWorker.java:124)
at net.minecraft.client.renderer.chunk.ChunkRenderDispatcher.updateChunkNow(ChunkRenderDispatcher.java:171)
at net.minecraft.client.renderer.RenderGlobal.setupTerrain(RenderGlobal.java:975)
at net.minecraft.client.renderer.EntityRenderer.renderWorldPass(EntityRenderer.java:1339)
at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1282)
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1091)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1135)
at net.minecraft.client.Minecraft.run(Minecraft.java:401)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)

 

It says that it cannot set the half property to a double slab as it doesn't exixts, wich is correct but looking at the supermethod the doubleslab case is handled well

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

EDIT: the crash was cause by the doesSideBlockRendering, wich overriding properly as solved the problem. In case everyone want to look how this has been fixed, this is the complete class

package com.mwvanilla.blocks;

import java.util.List;
import java.util.Random;

import com.mineworld.blocks.ores.BlockOreSlab;
import com.mwvanilla.core.MWVanillaSlabs;
import com.mwvanilla.core.MWVanillaTabs;

import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.BlockSlab.EnumBlockHalf;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public abstract class BlockVanillaSlab extends BlockSlab
{
    public static final PropertyEnum<BlockVanillaSlab.Variant> VARIANT = PropertyEnum.<BlockVanillaSlab.Variant>create("variant", BlockVanillaSlab.Variant.class);
    private Block block;
    public BlockVanillaSlab(Block block)
    {
        super(block.getDefaultState().getMaterial());
        this.block = block;
        IBlockState iblockstate = this.blockState.getBaseState();

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

        this.setDefaultState(iblockstate.withProperty(VARIANT, BlockVanillaSlab.Variant.DEFAULT));
        this.setHardness(block.getBlockHardness(block.getDefaultState(), null, null));
        this.setResistance(block.getExplosionResistance(null));
        this.setStepSound(this.block.getStepSound());
        if(this.block.equals(Blocks.glowstone))
        	this.setLightLevel(0.75F);
        if(this.block.equals(Blocks.sea_lantern))
        	this.setLightLevel(1.0F);
	this.useNeighborBrightness = !this.isDouble();
    }
    
    @Override
    public boolean isOpaqueCube(IBlockState state) {
    	return false;
    }
    
    @Override
    public boolean doesSideBlockRendering(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing face)
    {
        if(this.block.getDefaultState().getMaterial().equals(Material.glass))
        	return Blocks.glass.doesSideBlockRendering(state, world, pos, face);
        else
        	return super.doesSideBlockRendering(state, world, pos, face);
    }
    
    @Override
    public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos,
    		EnumFacing side) {
    	if(this.block.getDefaultState().getMaterial().equals(Material.glass)) {
    		IBlockState iblockstate = blockAccess.getBlockState(pos.offset(side));
            Block block = iblockstate.getBlock();
            if (blockState != iblockstate)
            {
                return true;
            }

            if (block == this)
            {
                return false;
            }
            
            return block == this ? false : super.shouldSideBeRendered(blockState, blockAccess, pos, side);
    	}
    	return super.shouldSideBeRendered(blockState, blockAccess, pos, side);
    }
    
    @SideOnly(Side.CLIENT)
    public BlockRenderLayer getBlockLayer()
    {
        return this.block.getDefaultState().getMaterial().equals(Material.glass) ? BlockRenderLayer.CUTOUT : BlockRenderLayer.SOLID;
    }
            
    protected boolean canSilkHarvest()
    {
        return !this.isDouble();
    }
    
    @Override
public boolean canProvidePower(IBlockState state) {
	return this.block.equals(Blocks.redstone_block);
}

@Override
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
	return  this.block.equals(Blocks.redstone_block) ? 15 : 0;
}

    /**
     * Get the Item that this Block should drop when harvested.
     */
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        return this.block.getDefaultState().getMaterial().equals(Material.glass) ? null : Item.getItemFromBlock(this);
    }

    public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
    {
        return new ItemStack(Item.getItemFromBlock(this));
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public IBlockState getStateFromMeta(int meta)
    {
        IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT, BlockVanillaSlab.Variant.DEFAULT);

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

        return iblockstate;
    }

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

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

        return i;
    }

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

    /**
     * Returns the slab block name with the type associated with it
     */
    public String getUnlocalizedName(int meta)
    {
        return super.getUnlocalizedName();
    }

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

    public Comparable<?> getTypeForItem(ItemStack stack)
    {
        return BlockVanillaSlab.Variant.DEFAULT;
    }

    public static enum Variant implements IStringSerializable
    {
        DEFAULT;

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

 

Thank you diesieben for the help :)

Don't blame me if i always ask for your help. I just want to learn to be better :)

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I would like to setup a test that makes sure an animation completes, however this animation can be a couple of seconds long. Are there any examples of using a GameTestSequence created from GameTestHelper#startSequence to wait until a certain function in the code is reached or finished?
    • Minecraft java and forge seem to have it out for me, any ideas? I have had issues with exit code 1 while loading forge -fabric was having the same issues, but I seemed to fix it in these repairs? (tried different versions upwards from 1.19 to 1.20.2 for forge, nothing worked and I'm confident older versions wouldn't either) -The launcher itself loads fine, it will load the game within the launcher, and then crash the moment it tries to load outside of the launcher. I have tried the default launcher, legacy launcher, and the curse forge launcher, none have worked! (all have had the same problem) I think this started when I took a break and upgraded to windows 11 and wonder if that changed anything? I have tried the following: uninstalled & reinstalled java, (I have having issues where I download jdk 17 but only 8 would show up (would not show up anywhere but the control panel, not even the official uninstaller, I *think* I got that fixed) tried jarfix uninstalled & reinstalled minecraft tried alternate launchers -forge & legacy, & repaired them too. tried without mods updated game drivers uninstalled and reinstalled forge -including completely wiping it from my system changed java excutable path followed everything in the error code 1 post completely reset my pc I tried to change the launch path but couldn't seem to get it to work -the default launcher wont let me even see properties as an option, i have yet to try with the other two (i did try on legacy but it was being weird) I want to include my debug log; but its over the max size? sorry my brains gone numb from trying to fix this for the past 2 days
    • I personally create registries using DataPackRegistryEvent.NewRegistry. It's pretty powerful as long as you know how to make codecs. In some class, make a registry key like so: public static final ResourceKey<Registry<MyDataType>> MY_REGISTRY = ResourceKey.createRegistryKey(new ResourceLocation(MyMod.MOD_ID, "registry_name")); This will make a registry that holds objects of type "MyDataType". JSON files stored in data/<datapack_namespace>/modid/registryname/ will be parsed and put into this registry. Note that the directory structure has a folder named after your mod inside your datapack directory, so the actual path would look like: data/my_mod/my_mod/registry_name (or if another mod uses your registry: data/their_mod/my_mod/registry_name. To register this registry, subscribe to the DataPackRegistryEvent.NewRegistry event on the MOD event bus and call event.dataPackRegistry() for every registry you have. An example of what I'm doing for my mod (this is in the constructor for the main mod file): IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); bus.addListener((DataPackRegistryEvent.NewRegistry event) -> { event.dataPackRegistry(ModRegistries.INSULATOR_DATA, InsulatorData.CODEC); }); CODEC is a public static field inside the class for the custom data type I am registering. It holds a Codec<InsulatorData> that tells Minecraft how to serialize/deserialize the data. Most of my data so far can be represented by records, so I use RecordCodecBuilder.create() to do this: public static final Codec<InsulatorData> CODEC = RecordCodecBuilder.create(instance -> instance.group( // Yadda yadda ).apply(instance, InsulatorData::new)); What exactly to put here depends on what you're trying to do, so that's up to you. But basically you're just defining a list of codecs that correspond to the parameters of the record (data type). Most primitive data types have records in the Codec class (ex. Codec.INT) that you can use, and other classes like ResourceLocation have their own codecs as a static field (ex. ResourceLocation.CODEC). Hopefully this is what you're looking for, and that this helps.
    • Good days  I finnaly manage to fix and get a working gui from BlockItem and from BlockEntity the next issues i have to fix is this the block Entity model for some reason is moved to the south west  this briefcase model must be centered but is moved to a side, i have nothing weird in the code but this is happening // ########## ########## ########## ########## @Override public RenderShape getRenderShape(BlockState blkstate) {     return RenderShape.MODEL; } the block model is out of place However The hitBox of the block is right in place   ########################################################################################################### This next issue  Mi gui also adds the 5 slots from the player equipment the thing is theres no filter to determine whats can be put in an armor slot and what not      i have this method that draws the slots for the armor, the part i dont get i slike wheres the code that responds when you set an item in a item slot to do checks and allow the item to be set or not  //########## ########## ########## //Draw Player Armor private void addPlayerArmorSlots(Inventory playerInventory) { // 36 this.addSlot(new Slot(playerInventory, 39, 8, 8)); this.addSlot(new Slot(playerInventory, 38, 8, 26)); this.addSlot(new Slot(playerInventory, 37, 8, 44)); this.addSlot(new Slot(playerInventory, 36, 8, 62)); this.addSlot(new Slot(playerInventory, 40, 26, 53)); }   theres must be a method that triggers when you set a itemstack inside an slot and allows to do a check if its a valid item for that slot                                             
    • No like how do I use my new PreperableReloadListener, I know how to set it up now and register it, I just need to know how to use it in other classes.
  • Topics

×
×
  • Create New...

Important Information

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