Jump to content

[1.16.4] Adding blockstates to minecraft/forge


<Gl33p_0r4nge>

Recommended Posts

 

So I'm trying to override/recreate vanilla cauldron's mechanic. I end up with this...

My Cauldron Code:

package me.gleep.oreexpansion.blocks;

import me.gleep.oreexpansion.util.RegistryHandler;
import me.gleep.oreexpansion.util.CustomBlockStatePropeties;
import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.*;
import net.minecraft.potion.PotionUtils;
import net.minecraft.potion.Potions;
import net.minecraft.state.IntegerProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.stats.Stats;
import net.minecraft.tileentity.BannerTileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

public class Cauldron extends CauldronBlock {

    public static final IntegerProperty CONTENT = CustomBlockStatePropeties.CONTENTS_0_2;

    public Cauldron() {
        super(AbstractBlock.Properties.create(Material.IRON, MaterialColor.STONE).setRequiresTool().hardnessAndResistance(2.0F).notSolid());
    }

    @Override
    public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
        ItemStack itemstack = player.getHeldItem(handIn);
        if (itemstack.isEmpty()) {
            return ActionResultType.PASS;
        } else {
            int i = state.get(LEVEL);
            int j = state.get(CONTENT);
            Item item = itemstack.getItem();
            if (item == RegistryHandler.LEAD_BLOCK_ITEM.get()) {
                if (!worldIn.isRemote && j == 0) {
                    /*if (!player.abilities.isCreativeMode) {
                        player.setHeldItem(handIn, new ItemStack(Items.BUCKET));
                    }*/

                    player.addStat(Stats.FILL_CAULDRON);
                    this.setInside(worldIn, pos, state, 2);
                    this.setLeadLevel(worldIn, pos, state, 1);
                    worldIn.playSound((PlayerEntity) null, pos, SoundEvents.BLOCK_STONE_BREAK, SoundCategory.BLOCKS, 1.0F, 1.0F);
                }

                return ActionResultType.func_233537_a_(worldIn.isRemote);
            } /*else if (item == RegistryHandler.LEAD_BUCKET.get()) {
                if (j == 0 && i < 3 && !worldIn.isRemote) {
                    if (!player.abilities.isCreativeMode) {
                        player.setHeldItem(handIn, new ItemStack(Items.BUCKET));
                    }

                    player.addStat(Stats.FILL_CAULDRON);
                    this.setInside(worldIn, pos, state, 0);
                    this.setLeadLevel(worldIn, pos, state, 0);
                    worldIn.playSound((PlayerEntity)null, pos, SoundEvents.ITEM_BUCKET_EMPTY_LAVA, SoundCategory.BLOCKS, 1.0F, 1.0F);
                }

                return ActionResultType.func_233537_a_(worldIn.isRemote);
            }*/
            else if (item == Items.WATER_BUCKET) {
                if (j < 2 && i < 3 && !worldIn.isRemote) {
                    if (!player.abilities.isCreativeMode) {
                        player.setHeldItem(handIn, new ItemStack(Items.BUCKET));
                    }

                    player.addStat(Stats.FILL_CAULDRON);
                    this.setInside(worldIn, pos, state, 1);
                    this.setWaterLevel(worldIn, pos, state, 3);
                    worldIn.playSound((PlayerEntity) null, pos, SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
                }

                return ActionResultType.func_233537_a_(worldIn.isRemote);

            } else if (item == Items.BUCKET) {
                if (j > 0 && i == 3 && !worldIn.isRemote) {
                    if (j == 1) {
                        if (!player.abilities.isCreativeMode) {
                            itemstack.shrink(1);
                            if (itemstack.isEmpty()) {
                                player.setHeldItem(handIn, new ItemStack(Items.WATER_BUCKET));
                            } else if (!player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET))) {
                                player.dropItem(new ItemStack(Items.WATER_BUCKET), false);
                            }
                        }

                        player.addStat(Stats.USE_CAULDRON);
                        this.setInside(worldIn, pos, state, 0);
                        this.setWaterLevel(worldIn, pos, state, 0);
                        worldIn.playSound((PlayerEntity) null, pos, SoundEvents.ITEM_BUCKET_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);

                    } else {
                        return ActionResultType.PASS;
                        /*if (!player.abilities.isCreativeMode) {
                            itemstack.shrink(1);
                            if (itemstack.isEmpty()) {
                                player.setHeldItem(handIn, new ItemStack(Items.WATER_BUCKET));
                            } else if (!player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET))) {
                                player.dropItem(new ItemStack(Items.WATER_BUCKET), false);
                            }
                        }
                        player.addStat(Stats.USE_CAULDRON);
                        this.setInside(worldIn, pos, state, 0);
                        this.setWaterLevel(worldIn, pos, state, 0);
                        worldIn.playSound((PlayerEntity) null, pos, SoundEvents.ITEM_BUCKET_FILL_LAVA, SoundCategory.BLOCKS, 1.0F, 1.0F);*/
                    }
                }
                return ActionResultType.func_233537_a_(worldIn.isRemote);

            } else if (item == Items.GLASS_BOTTLE) {
                if (j == 1 && i > 0 && !worldIn.isRemote) {
                    if (!player.abilities.isCreativeMode) {
                        ItemStack itemstack4 = PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.WATER);
                        player.addStat(Stats.USE_CAULDRON);
                        itemstack.shrink(1);
                        if (itemstack.isEmpty()) {
                            player.setHeldItem(handIn, itemstack4);
                        } else if (!player.inventory.addItemStackToInventory(itemstack4)) {
                            player.dropItem(itemstack4, false);
                        } else if (player instanceof ServerPlayerEntity) {
                            ((ServerPlayerEntity) player).sendContainerToPlayer(player.container);
                        }
                    }

                    worldIn.playSound((PlayerEntity) null, pos, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
                    if (i - 1 == 0) this.setInside(worldIn, pos, state, 0);
                    this.setWaterLevel(worldIn, pos, state, i - 1);
                }

                return ActionResultType.func_233537_a_(worldIn.isRemote);
            } else if (item == Items.POTION && PotionUtils.getPotionFromItem(itemstack) == Potions.WATER) {
                if (j < 2 && i < 3 && !worldIn.isRemote) {
                    if (!player.abilities.isCreativeMode) {
                        ItemStack itemstack3 = new ItemStack(Items.GLASS_BOTTLE);
                        player.addStat(Stats.USE_CAULDRON);
                        player.setHeldItem(handIn, itemstack3);
                        if (player instanceof ServerPlayerEntity) {
                            ((ServerPlayerEntity) player).sendContainerToPlayer(player.container);
                        }
                    }

                    worldIn.playSound((PlayerEntity) null, pos, SoundEvents.ITEM_BOTTLE_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
                    this.setWaterLevel(worldIn, pos, state, i + 1);
                }

                return ActionResultType.func_233537_a_(worldIn.isRemote);
            } else {
                if (j == 1) {
                    if (i > 0 && item instanceof IDyeableArmorItem) {
                        IDyeableArmorItem idyeablearmoritem = (IDyeableArmorItem) item;
                        if (idyeablearmoritem.hasColor(itemstack) && !worldIn.isRemote) {
                            idyeablearmoritem.removeColor(itemstack);
                            if (i - 1 == 0) this.setInside(worldIn, pos, state, 0);
                            this.setWaterLevel(worldIn, pos, state, i - 1);
                            player.addStat(Stats.CLEAN_ARMOR);
                            return ActionResultType.SUCCESS;
                        }
                    } else if (i > 0 && item instanceof BannerItem) {
                        if (BannerTileEntity.getPatterns(itemstack) > 0 && !worldIn.isRemote) {
                            ItemStack itemstack2 = itemstack.copy();
                            itemstack2.setCount(1);
                            BannerTileEntity.removeBannerData(itemstack2);
                            player.addStat(Stats.CLEAN_BANNER);
                            if (!player.abilities.isCreativeMode) {
                                itemstack.shrink(1);
                                this.setWaterLevel(worldIn, pos, state, i - 1);
                            }

                            if (itemstack.isEmpty()) {
                                player.setHeldItem(handIn, itemstack2);
                            } else if (!player.inventory.addItemStackToInventory(itemstack2)) {
                                player.dropItem(itemstack2, false);
                            } else if (player instanceof ServerPlayerEntity) {
                                ((ServerPlayerEntity) player).sendContainerToPlayer(player.container);
                            }
                        }

                        return ActionResultType.func_233537_a_(worldIn.isRemote);
                    } else if (i > 0 && item instanceof BlockItem) {
                        Block block = ((BlockItem) item).getBlock();
                        if (block instanceof ShulkerBoxBlock && !worldIn.isRemote()) {
                            ItemStack itemstack1 = new ItemStack(Blocks.SHULKER_BOX, 1);
                            if (itemstack.hasTag()) {
                                itemstack1.setTag(itemstack.getTag().copy());
                            }

                            player.setHeldItem(handIn, itemstack1);
                            this.setWaterLevel(worldIn, pos, state, i - 1);
                            player.addStat(Stats.CLEAN_SHULKER_BOX);
                            return ActionResultType.SUCCESS;
                        } else {
                            return ActionResultType.CONSUME;
                        }
                    } else return ActionResultType.PASS;
                }
            }
        }
        return ActionResultType.PASS;
    }

    public void setInside(World worldIn, BlockPos pos, BlockState state, int content) {
        worldIn.setBlockState(pos, state.with(CONTENT, Integer.valueOf(MathHelper.clamp(content, 0, 2))), 2);
    }

    public void setLeadLevel(World worldIn, BlockPos pos, BlockState state, int level) {
        worldIn.setBlockState(pos, state.with(LEVEL, Integer.valueOf(MathHelper.clamp(level, 0, 3))), 2);
    }

    @Override
    public void fillWithRain(World worldIn, BlockPos pos) {
        if (worldIn.getBlockState(pos).get(CONTENT) < 2) {
            super.fillWithRain(worldIn, pos);
        }
    }
}

and something I hoped that will work:

package me.gleep.oreexpansion.util;

import net.minecraft.state.IntegerProperty;
import net.minecraft.state.properties.BlockStateProperties;

public class CustomBlockStatePropeties extends BlockStateProperties {
    public static final IntegerProperty CONTENTS_0_2 = IntegerProperty.create("content", 0, 2);
}

 

It worked but I wanted to add textures and I ran into a problem. I need apparently add custom block state so I added thisto the Cauldron code:

@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
	super.fillStateContainer(builder);
  	builder.add(CONTENT);
}

@Nullable
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
	return this.getDefaultState().with(CONTENT, 0).getBlockState();
}

 

And end up with error:

---- Minecraft Crash Report ----
// Daisy, daisy...

Time: 3.12.20 14:17
Description: Mod loading error has occurred

java.lang.Exception: Mod Loading has failed
	at net.minecraftforge.fml.CrashReportExtender.dumpModLoadingCrashReport(CrashReportExtender.java:85) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.client.ClientModLoader.completeModLoading(ClientModLoader.java:188) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.lambda$null$1(Minecraft.java:513) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.util.Util.acceptOrElse(Util.java:323) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraft.client.Minecraft.lambda$new$2(Minecraft.java:509) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.ResourceLoadProgressGui.render(ResourceLoadProgressGui.java:113) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.GameRenderer.updateCameraAndRender(GameRenderer.java:492) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1002) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:612) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_162] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_162] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_162] {}
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_162] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.0.6.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.0.6.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.0.6.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.0.6.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.0.6.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:105) [forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {}


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Render thread
Stacktrace:
	at net.minecraftforge.registries.GameData$BlockCallbacks.onAdd(GameData.java:455) ~[?:?] {re:classloading}
-- MOD oreexpansion --
Details:
	Mod File: main
	Failure message: Ore Expansion (oreexpansion) encountered an error during the load_registries event phase
		java.lang.RuntimeException: Invalid vanilla replacement. See log for details.
	Mod Version: 1.16.4-0.0.1-alpha
	Mod Issue URL: http://my.issue.tracker/
	Exception message: java.lang.RuntimeException: Invalid vanilla replacement. See log for details.
Stacktrace:
	at net.minecraftforge.registries.GameData$BlockCallbacks.onAdd(GameData.java:455) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraftforge.registries.GameData$BlockCallbacks.onAdd(GameData.java:425) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:404) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:335) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraftforge.registries.ForgeRegistry.register(ForgeRegistry.java:142) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraftforge.registries.DeferredRegister.addEntries(DeferredRegister.java:200) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraftforge.registries.DeferredRegister.access$000(DeferredRegister.java:61) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraftforge.registries.DeferredRegister$EventDispatcher.handleEvent(DeferredRegister.java:172) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraftforge.eventbus.ASMEventHandler_0_EventDispatcher_handleEvent_Register.invoke(.dynamic) ~[?:?] {}
	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-3.0.5-service.jar:?] {}
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:297) ~[eventbus-3.0.5-service.jar:?] {}
	at net.minecraftforge.fml.javafmlmod.FMLModContainer.acceptEvent(FMLModContainer.java:120) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:35.1] {re:classloading}
	at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$4(ModContainer.java:121) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1626) ~[?:1.8.0_162] {}
	at net.minecraftforge.fml.ModWorkManager$SyncExecutor.driveOne(ModWorkManager.java:56) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.ModWorkManager$DrivenExecutor.drive(ModWorkManager.java:40) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:243) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:230) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:196) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.client.ClientModLoader.lambda$begin$1(ClientModLoader.java:103) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraftforge.fml.client.ClientModLoader.lambda$createRunnableWithCatch$4(ClientModLoader.java:123) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraftforge.fml.client.ClientModLoader.begin(ClientModLoader.java:103) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.<init>(Minecraft.java:442) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:149) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_162] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_162] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_162] {}
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_162] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.0.6.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.0.6.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.0.6.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.0.6.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.0.6.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:105) [forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {}


-- System Details --
Details:
	Minecraft Version: 1.16.4
	Minecraft Version ID: 1.16.4
	Operating System: Windows 10 (amd64) version 10.0
	Java Version: 1.8.0_162, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 1359560424 bytes (1296 MB) / 1725956096 bytes (1646 MB) up to 3817865216 bytes (3641 MB)
	CPUs: 4
	JVM Flags: 2 total; -Xmx4G -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump
	ModLauncher: 8.0.6+85+master.325de55
	ModLauncher launch target: fmluserdevclient
	ModLauncher naming: mcp
	ModLauncher services: 
		/mixin-0.8.2.jar mixin PLUGINSERVICE 
		/eventbus-3.0.5-service.jar eventbus PLUGINSERVICE 
		/forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-launcher.jar object_holder_definalize PLUGINSERVICE 
		/forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-launcher.jar runtime_enum_extender PLUGINSERVICE 
		/accesstransformers-2.2.0-shadowed.jar accesstransformer PLUGINSERVICE 
		/forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-launcher.jar capability_inject_definalize PLUGINSERVICE 
		/forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-launcher.jar runtimedistcleaner PLUGINSERVICE 
		/mixin-0.8.2.jar mixin TRANSFORMATIONSERVICE 
		/forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.3-launcher.jar fml TRANSFORMATIONSERVICE 
	FML: 35.1
	Forge: net.minecraftforge:35.1.2
	FML Language Providers: 
		javafml@35.1
		minecraft@1
	Mod List: 
		client-extra.jar                                  |Minecraft                     |minecraft                     |1.16.4              |COMMON_SET|a1:d4:5e:04:4f:d3:d6:e0:7b:37:97:cf:77:b0:de:ad:4a:47:ce:8c:96:49:5f:0a:cf:8c:ae:b2:6d:4b:8a:3f
		main                                              |Ore Expansion                 |oreexpansion                  |1.16.4-0.0.1-alpha  |VALIDATE  |NOSIGNATURE
		forge-1.16.4-35.1.2_mapped_snapshot_20201028-1.16.|Forge                         |forge                         |35.1.0              |COMMON_SET|NOSIGNATURE
	Crash Report UUID: edc69e6a-8785-4dfb-9c50-38b392e2f432

 

 

My question is if I could and how to make my custom block states or if I theres some other way or I made something wrong?

 

Link to comment
Share on other sites

You need to set the default state in the constructor, the Block class has the setDefaultState method that you should use

 

@Nullable
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
	return this.getDefaultState().with(CONTENT, 0).getBlockState();
}

Also, calling getBlockState is irrelevant, getDefaultState().with() already return a blockState

Also Also, if the State for Placement for the Property CONTENT is always 0, you don't need to set it in the getStateForPlacement method, you can just set it in the constructor like I said before

Edited by kiou.23
I'm bad at spelling words
Link to comment
Share on other sites

12 hours ago, kiou.23 said:

You need to set the default state in the constructor, the Block class has the setDefaultState method that you should use

 

Okay so, I tried this in the constructor (the second line is what I tried first):

this.setDefaultState(this.getDefaultState().with(LEVEL, Integer.valueOf(0)).with(CONTENT, Integer.valueOf(0)));

this.setDefaultState(this.stateContainer.getBaseState().with(CONTENT, Integer.valueOf(0)).with(LEVEL, Integer.valueOf(0)));

And I still got the same error:

image.png.49097ec1884a02af6fa86223442363cd.png

I tried it without that 2 methods with one of them and still don't working. I don't know if I mention that but I'm registring it as vanilla block.

It was working before I start to deal with block states. And also Im creating new cauldron.json in texturepacks but thats not the main problem I think because it runs without textures.

 

12 hours ago, kiou.23 said:

Also, calling getBlockState is irrelevant, getDefaultState().with() already return a blockState

I know I just forgot to remove it before posting.

 

12 hours ago, kiou.23 said:

Also Also, if the State for Placement for the Property CONTENT is always 0, you don't need to set it in the getStateForPlacement method, you can just set it in the constructor like I said before

It is not always 0 it stores the material in the cauldron

Edited by <Gl33p_0r4nge>
Link to comment
Share on other sites

Can you share your Registry code and your Mod main class?

 

27 minutes ago, <Gl33p_0r4nge> said:

It is not always 0 it stores the material in the cauldron

I'm talking about this snippet:

@Nullable
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
	return this.getDefaultState().with(CONTENT, 0).getBlockState();
}

this function return the state for placement based on the context of the placement, it's useful so you can orient a directional block for example, but in this case it always return the same block state independent of the state, so it's redundant

this clearly isn't the problem that's causing the crash tho

 

The crash log doesn't say anything about the State Container crashing, it says the error ocurred when registering, did you alter something in the registration before it started crashing?

 

Link to comment
Share on other sites

1 minute ago, kiou.23 said:

this function return the state for placement based on the context of the placement, it's useful so you can orient a directional block for example, but in this case it always return the same block state independent of the state, so it's redundant

this clearly isn't the problem that's causing the crash tho

ohhh, allright now I understatnd

 

4 minutes ago, kiou.23 said:

Can you share your Registry code and your Mod main class?

thats Registry:

package me.gleep.oreexpansion.util;

import me.gleep.oreexpansion.OreExpansion;
import me.gleep.oreexpansion.armors.STAMaterial;
import me.gleep.oreexpansion.armors.ArmorBase;
import me.gleep.oreexpansion.blocks.*;
import me.gleep.oreexpansion.blocks.tileentities.SilverBlockTileEntity;
import me.gleep.oreexpansion.items.ItemBase;
import me.gleep.oreexpansion.tools.STSMaterial;
import me.gleep.oreexpansion.tools.STSBase;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.*;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.world.gen.blockstateprovider.BlockStateProviderType;
import net.minecraftforge.client.model.generators.BlockStateProvider;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class RegistryHandler {
    //Vanilla
    private static final DeferredRegister<Block> VANILLA_BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, "minecraft");

    //Mod
    private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, OreExpansion.MOD_ID);
    private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, OreExpansion.MOD_ID);
    //private static final DeferredRegister<Fluid> FLUDIS = DeferredRegister.create(ForgeRegistries.FLUIDS, OreExpansion.MOD_ID);
    private static final DeferredRegister<TileEntityType<?>> TILE_ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, OreExpansion.MOD_ID);
    //private static final DeferredRegister<IRecipeSerializer<?>> RECIPES = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, OreExpansion.MOD_ID);

    public static void init() {
        ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
        BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
        //FLUDIS.register(FMLJavaModLoadingContext.get().getModEventBus());
        TILE_ENTITY_TYPES.register(FMLJavaModLoadingContext.get().getModEventBus());

        VANILLA_BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
    }


    //Items
    public static final RegistryObject<Item> SILVER_INGOT = ITEMS.register("silver_ingot", ItemBase::new);
    public static final RegistryObject<Item> LEAD_INGOT = ITEMS.register("lead_ingot", ItemBase::new);
    public static final RegistryObject<Item> SILVER_NUGGET = ITEMS.register("silver_nugget", ItemBase::new);
    public static final RegistryObject<Item> LEAD_NUGGET = ITEMS.register("lead_nugget", ItemBase::new);
    public static final RegistryObject<Item> NETHERITE_NUGGET = ITEMS.register("netherite_nugget", () -> new ItemBase(true));
    //public static final RegistryObject<Item> LEAD_BUCKET = ITEMS.register("lead_bucket", LeadBucket::new);


    //Blocks
    public static final RegistryObject<Block> SILVER_BLOCK = BLOCKS.register("silver_block", SilverBlock::new);
    public static final RegistryObject<Block> LEAD_BLOCK = BLOCKS.register("lead_block", LeadBlock::new);
    public static final RegistryObject<Block> SILVER_ORE = BLOCKS.register("silver_ore", SilverOre::new);
    public static final RegistryObject<Block> LEAD_ORE = BLOCKS.register("lead_ore", LeadOre::new);
    public static final RegistryObject<Block> CAULDRON = VANILLA_BLOCKS.register("cauldron", Cauldron::new);

    //Block Item
    public static final RegistryObject<Item> SILVER_BLOCK_ITEM = ITEMS.register("silver_block", () -> new BlockItemBase(SILVER_BLOCK.get()));
    public static final RegistryObject<Item> LEAD_BLOCK_ITEM = ITEMS.register("lead_block", () -> new BlockItemBase(LEAD_BLOCK.get()));
    public static final RegistryObject<Item> SILVER_ORE_ITEM = ITEMS.register("silver_ore", () -> new BlockItemBase(SILVER_ORE.get()));
    public static final RegistryObject<Item> LEAD_ORE_ITEM = ITEMS.register("lead_ore", () -> new BlockItemBase(LEAD_ORE.get()));


    //Fluids
    //public static final RegistryObject<FlowingFluidBlock> LEAD_FLUID = FLUDIS.register("lead_fluid", ();


    //Tile Entities
    public static final RegistryObject<TileEntityType<SilverBlockTileEntity>> SILVER_BLOCK_TE = TILE_ENTITY_TYPES.register("silver_block", () -> TileEntityType.Builder.create(
            SilverBlockTileEntity::new, SILVER_BLOCK.get()).build(null));


    //Tools
    public static final RegistryObject<SwordItem> SILVER_TINTED_GOLDEN_SWORD = ITEMS.register("silver_tinted_golden_sword", () ->
            new STSBase(STSMaterial.STGS, 3, -2.4F));
    public static final RegistryObject<SwordItem> SILVER_TINTED_DIAMOND_SWORD = ITEMS.register("silver_tinted_diamond_sword", () ->
            new STSBase(STSMaterial.STDS, 3, -2.4F));
    public static final RegistryObject<SwordItem> SILVER_TINTED_NETHERITE_SWORD = ITEMS.register("silver_tinted_netherite_sword", () ->
            new STSBase(STSMaterial.STNS, 3, -2.4F, true));


    //Armors
    public static final RegistryObject<ArmorItem> SILVER_TITNTED_GOLDEN_HELMET = ITEMS.register("silver_tinted_golden_helmet", () ->
            new ArmorBase(STAMaterial.STGA, EquipmentSlotType.HEAD));
    public static final RegistryObject<ArmorItem> SILVER_TITNTED_GOLDEN_CHESTPLATE = ITEMS.register("silver_tinted_golden_chestplate", () ->
            new ArmorBase(STAMaterial.STGA, EquipmentSlotType.CHEST));
    public static final RegistryObject<ArmorItem> SILVER_TITNTED_GOLDEN_LEGGINGS = ITEMS.register("silver_tinted_golden_leggings", () ->
            new ArmorBase(STAMaterial.STGA, EquipmentSlotType.LEGS));
    public static final RegistryObject<ArmorItem> SILVER_TITNTED_GOLDEN_BOOTS = ITEMS.register("silver_tinted_golden_boots", () ->
            new ArmorBase(STAMaterial.STGA, EquipmentSlotType.FEET));

    public static final RegistryObject<ArmorItem> SILVER_TITNTED_DIAMOND_HELMET = ITEMS.register("silver_tinted_diamond_helmet", () ->
            new ArmorBase(STAMaterial.STDA, EquipmentSlotType.HEAD));
    public static final RegistryObject<ArmorItem> SILVER_TITNTED_DIAMOND_CHESTPLATE = ITEMS.register("silver_tinted_diamond_chestplate", () ->
            new ArmorBase(STAMaterial.STDA, EquipmentSlotType.CHEST));
    public static final RegistryObject<ArmorItem> SILVER_TITNTED_DIAMOND_LEGGINGS = ITEMS.register("silver_tinted_diamond_leggings", () ->
            new ArmorBase(STAMaterial.STDA, EquipmentSlotType.LEGS));
    public static final RegistryObject<ArmorItem> SILVER_TITNTED_DIAMOND_BOOTS = ITEMS.register("silver_tinted_diamond_boots", () ->
            new ArmorBase(STAMaterial.STDA, EquipmentSlotType.FEET));

    public static final RegistryObject<ArmorItem> SILVER_TITNTED_NETHERITE_HELMET = ITEMS.register("silver_tinted_netherite_helmet", () ->
            new ArmorBase(STAMaterial.STNA, EquipmentSlotType.HEAD, true));
    public static final RegistryObject<ArmorItem> SILVER_TITNTED_NETHERITE_CHESTPLATE = ITEMS.register("silver_tinted_netherite_chestplate", () ->
            new ArmorBase(STAMaterial.STNA, EquipmentSlotType.CHEST, true));
    public static final RegistryObject<ArmorItem> SILVER_TITNTED_NETHERITE_LEGGINGS = ITEMS.register("silver_tinted_netherite_leggings", () ->
            new ArmorBase(STAMaterial.STNA, EquipmentSlotType.LEGS, true));
    public static final RegistryObject<ArmorItem> SILVER_TITNTED_NETHERITE_BOOTS = ITEMS.register("silver_tinted_netherite_boots", () ->
            new ArmorBase(STAMaterial.STNA, EquipmentSlotType.FEET, true));

}

like I haven't made change since I'm editing the cauldron

and the main:
 

package me.gleep.oreexpansion;

import me.gleep.oreexpansion.util.RegistryHandler;
import me.gleep.oreexpansion.world.gen.CustomOreGen;
import net.minecraft.block.Blocks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Mod("oreexpansion")
public class OreExpansion {
    private static final Logger LOGGER = LogManager.getLogger();
    public static final String MOD_ID = "oreexpansion";

    public OreExpansion() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        RegistryHandler.init();
    }

    private void setup(final FMLCommonSetupEvent event) {
        CustomOreGen.registerOres();
        MinecraftForge.EVENT_BUS.register(this);
        LOGGER.info("HELLO FROM PREINIT");
        LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
    }

    private void doClientStuff(final FMLClientSetupEvent event) {
        LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
    }
}
Link to comment
Share on other sites

Hmm, seems that the problem is with replacing vanilla blocks and adding more states to them, I think forge doesn't like that... and I haven't tried to replace anything in vanilla
I found this thread on the forum: https://forums.minecraftforge.net/topic/71283-1132-vanilla-block-replacement/

may be a bit old but seems like the OP was having the same problem, maybe it helps

 

Maybe make a new Cauldron Block and just replace the recipe to return your block?

 

Link to comment
Share on other sites

I looked in the forum and yeah it looks like forge really dont like overriding vanilla items/blocks with custom block states so I need to create my cauldron anyway:

[10:22:41] [Render thread/ERROR] [ne.mi.re.GameData/REGISTRIES]: Registry replacements for vanilla block 'minecraft:cauldron' must not change the number or order of blockstates.
    Old: level={0,1,2,3}
    New: content={0,1,2};level={0,1,2,3}

but still happy that I made it like this so it could actually work. Maybe in 1.17 there will be more support to adding custom fluids to cauldron as they add lava and other to cauldron

 

Anyways thanks for help!

 

for those who want to do the same thing as I want just simply do this (its just replacing the cauldron with your own cauldron when placed) :

public class VanillaCauldron extends CauldronBlock {
    public VanillaCauldron() {
        super(AbstractBlock.Properties.create(Material.IRON, MaterialColor.STONE).setRequiresTool().hardnessAndResistance(2.0F).notSolid());
    }

    @Override
    public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) {
        if (!worldIn.isRemote) {
            worldIn.removeBlock(pos, false);
            worldIn.setBlockState(pos, RegistryHandler.CAULDRON.get().getDefaultState());
        }
    }
}

 

You want there put your registry class and the new name of the block (mine is CAULDRON):

worldIn.setBlockState(pos, RegistryHandler.CAULDRON.get().getDefaultState());

 

then register it in registry like normal block except your modid replace with "minecraft" and then create your block also extending the vanilla one and here you can override add custom blockstatest as you wish and want. Then simply register it as block under your modid and there you go. Also dont forget to create json files

 

EDIT: oh no Im dumb do this with the Cauldron Item then check when right click

EDIT 2: wait just still testing it

 

 

Yeah I was wrong just simply dont override it and with the BlockEvent.EntityPlaceEvent check for cauldron block

Edited by <Gl33p_0r4nge>
Link to comment
Share on other sites

Like if I put in lead block (which is from my mod) then put campfire/some source of fire under it, it melts. Like water it will have 3 "levels" that means that it will change texture from basic block to melted stage and to completly melted then the player could get it from the cauldron with bucket recieving lead bucket which I haven't created yet and tbh maybe you right about it not overriding the cauldron because with this I override the water colors which is controlled somwhere else as I guess. 

Link to comment
Share on other sites

Nice now it is working that when I right click it changes to my cauldron and when I get the item out again by right clicking with bare hand it pops out and changing back to the vanilla cauldron. And my question is how can I check for source of fire under the cauldron (I maybe have idea just when event is fired on block (campfire) is placed) and how to change the content of the cauldron after some ticks (I have never worked with ticks and other related stuff)?

Edited by <Gl33p_0r4nge>
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



×
×
  • Create New...

Important Information

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