Jump to content

Error with Facing Blockstate


jun2040

Recommended Posts

I ran the game and I tried placing a block then my game crashed. Here's my code and crash report.

Block:

package com.jun2040.sourcemod.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.properties.BlockStateProperties;

import javax.annotation.Nullable;

public class ExampleBlock extends Block {

    public ExampleBlock() {
        super(Properties.create(Material.IRON)
                .sound(SoundType.METAL)
                .hardnessAndResistance(2.0f)
                .lightValue(14)
        );
        setRegistryName("example_block");
    }

    @Nullable
    @Override
    public BlockState getStateForPlacement(BlockItemUseContext context) {
        BlockState blockstate = super.getStateForPlacement(context);
        if (blockstate != null) {
            blockstate = blockstate.with(BlockStateProperties.FACING, context.getNearestLookingDirection());
        }
        return blockstate;
    }
}

 

crash report:

---- Minecraft Crash Report ----
// There are four lights!

Time: 10/6/19 11:11 AM
Description: Unexpected error

java.lang.IllegalArgumentException: Cannot set property DirectionProperty{name=facing, clazz=class net.minecraft.util.Direction, values=[north, east, south, west, up, down]} as it does not exist in Block{sourcemod:example_block}
    at net.minecraft.state.StateHolder.with(StateHolder.java:105) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
    at com.jun2040.sourcemod.blocks.ExampleBlock.getStateForPlacement(ExampleBlock.java:28) ~[main/:?] {}
    at net.minecraft.item.BlockItem.getStateForPlacement(BlockItem.java:99) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
    at net.minecraft.item.BlockItem.tryPlace(BlockItem.java:54) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
    at net.minecraft.item.BlockItem.onItemUse(BlockItem.java:42) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
    at net.minecraft.item.ItemStack.lambda$onItemUse$0(ItemStack.java:169) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
    at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:184) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
    at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:169) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
    at net.minecraft.client.multiplayer.PlayerController.func_217292_a(PlayerController.java:307) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1283) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:1541) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1374) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:901) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.run(Minecraft.java:384) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.main.Main.main(Main.java:128) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:runtimedistcleaner:A}
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_202] {}
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_202] {}
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_202] {}
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_202] {}
    at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-3.2.0.jar:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:50) [modlauncher-3.2.0.jar:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:68) [modlauncher-3.2.0.jar:?] {}
    at cpw.mods.modlauncher.Launcher.run(Launcher.java:80) [modlauncher-3.2.0.jar:?] {}
    at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-3.2.0.jar:?] {}
    at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:101) [forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}


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

-- Head --
Thread: Client thread
Stacktrace:
    at net.minecraft.state.StateHolder.with(StateHolder.java:105)
    at com.jun2040.sourcemod.blocks.ExampleBlock.getStateForPlacement(ExampleBlock.java:28)
    at net.minecraft.item.BlockItem.getStateForPlacement(BlockItem.java:99)
    at net.minecraft.item.BlockItem.tryPlace(BlockItem.java:54)
    at net.minecraft.item.BlockItem.onItemUse(BlockItem.java:42)
    at net.minecraft.item.ItemStack.lambda$onItemUse$0(ItemStack.java:169)
    at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:184)
    at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:169)
    at net.minecraft.client.multiplayer.PlayerController.func_217292_a(PlayerController.java:307)
    at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1283)
    at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:1541)

-- Affected level --
Details:
    All players: 1 total; [ClientPlayerEntity['Dev'/110, l='MpServer', x=103.82, y=23.17, z=9.94]]
    Chunk stats: Client Chunk Cache: 729, 441
    Level dimension: DimensionType{minecraft:overworld}
    Level name: MpServer
    Level seed: 0
    Level generator: ID 01 - flat, ver 0. Features enabled: false
    Level generator options: {}
    Level spawn location: World: (96,22,0), Chunk: (at 0,1,0 in 6,0; contains blocks 96,0,0 to 111,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Level time: 950 game time, 950 day time
    Level storage version: 0x00000 - Unknown?
    Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
    Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
    Server brand: forge
    Server type: Integrated singleplayer server
Stacktrace:
    at net.minecraft.client.world.ClientWorld.fillCrashReport(ClientWorld.java:425)
    at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:1821)
    at net.minecraft.client.Minecraft.run(Minecraft.java:405)
    at net.minecraft.client.main.Main.main(Main.java:128)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55)
    at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37)
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:50)
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:68)
    at cpw.mods.modlauncher.Launcher.run(Launcher.java:80)
    at cpw.mods.modlauncher.Launcher.main(Launcher.java:65)
    at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:101)

-- System Details --
Details:
    Minecraft Version: 1.14.4
    Minecraft Version ID: 1.14.4
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_202, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 938414592 bytes (894 MB) / 2120220672 bytes (2022 MB) up to 3771203584 bytes (3596 MB)
    CPUs: 12
    JVM Flags: 1 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump
    ModLauncher: 3.2.0+60+b86c1d4
    ModLauncher launch target: fmluserdevclient
    ModLauncher naming: mcp
    ModLauncher services: 
        /eventbus-1.0.0-service.jar eventbus PLUGINSERVICE 
        /forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar object_holder_definalize PLUGINSERVICE 
        /forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar runtime_enum_extender PLUGINSERVICE 
        /accesstransformers-1.0.0-shadowed.jar accesstransformer PLUGINSERVICE 
        /forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar capability_inject_definalize PLUGINSERVICE 
        /forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar runtimedistcleaner PLUGINSERVICE 
        /forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar fml TRANSFORMATIONSERVICE 
    FML: 28.1
    Forge: net.minecraftforge:28.1.0
    FML Language Providers: 
        javafml@28.1
        minecraft@1
    Mod List: 
        forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar Forge {forge@28.1.0 DONE}
        main Source Mod {sourcemod@0.1 DONE}
        client-extra.jar Minecraft {minecraft@1.14.4 DONE}
    Launched Version: MOD_DEV
    LWJGL: 3.2.2 build 10
    OpenGL: GeForce GTX 1060 with Max-Q Design/PCIe/SSE2 GL version 4.6.0 NVIDIA 436.48, NVIDIA Corporation
    GL Caps: Using GL 1.3 multitexturing.
Using GL 1.3 texture combiners.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Shaders are available because OpenGL 2.1 is supported.
VBOs are available because OpenGL 1.5 is supported.

    Using VBOs: Yes
    Is Modded: Definitely; Client brand changed to 'forge'
    Type: Client (map_client.txt)
    Resource Packs: 
    Current Language: English (US)
    CPU: 12x Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz

Link to comment
Share on other sites

7 minutes ago, jun2040 said:

Here's my code and crash report.

You need to override Block#fillBlockState and add the FACING property to the builder.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

53 minutes ago, Animefan8888 said:

You need to override Block#fillBlockState and add the FACING property to the builder.

like this?

package com.jun2040.sourcemod.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;

import javax.annotation.Nullable;

public class ExampleBlock extends Block {

    public ExampleBlock() {
        super(Properties.create(Material.IRON)
                .sound(SoundType.METAL)
                .hardnessAndResistance(2.0f)
                .lightValue(14)
        );
        setRegistryName("example_block");
    }

    @Nullable
    @Override
    public BlockState getStateForPlacement(BlockItemUseContext context) {
        BlockState blockstate = super.getStateForPlacement(context);
        if (blockstate != null) {
            blockstate = blockstate.with(BlockStateProperties.FACING, context.getNearestLookingDirection());
        }
        return blockstate;
    }

    public static Direction getFacingFromEntity(BlockPos clickedBlock, LivingEntity entity) {
        return Direction.getFacingFromVector((float) (entity.posX - clickedBlock.getX()), (float) (entity.posY - clickedBlock.getY()), (float) (entity.posZ - clickedBlock.getZ()));
    }

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

I did this and the textures aren't working.

Link to comment
Share on other sites

Just now, jun2040 said:

I did this and the textures aren't working. 

Does your blockstate json reflect the facing property?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 minute ago, Animefan8888 said:

Does your blockstate json reflect the facing property?

yes

{
    "variants": {
        "facing=north": { "model": "sourcemod:block/example_block" },
        "facing=south": { "model": "sourcemod:block/example_block", "y": 180 },
        "facing=west": { "model": "sourcemod:block/example_block", "y": 270 },
        "facing=east": { "model": "sourcemod:block/example_block", "y": 90 },
        "facing=up": { "model": "sourcemod:block/example_block", "x": -90 },
        "facing=down": { "model": "sourcemod:block/example_block", "x": 90 },
    }
}
Link to comment
Share on other sites

6 minutes ago, jun2040 said:

"facing=down": { "model": "sourcemod:block/example_block", "x": 90 },

You've got an extra comma at the end of this line. You should download a json editing plugin for your IDE.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

  • 2 weeks later...
29 minutes ago, jun2040 said:

So I made it work but whenever I place the block, the front side's always facing away from me. Does anyone know how to fix this?

I just use

@Nullable
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
       return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite());
}

But that's only for Horizontal, without UP and DOWN.

 

If i am not mistaken your code set's the FACING to the Direction you are looking at,

so you could just add the .getOpposite() to it.

 

I think context.getFace() get's the Face your are placing against, but I am not sure.

So context.getFace().getOpposite() should face it in your Direction.

Edited by Keitaro
Link to comment
Share on other sites

44 minutes ago, Keitaro said:

I think context.getFace() get's the Face your are placing against, but I am not sure.

So context.getFace().getOpposite() should face it in your Direction.

No, that would be wrong. context.getFace() is the face you're placing against (so the North face). Getting the opposite of that would give you South, facing the block into the block you clicked on, not facing the player. To use the player's facing you use (gasp) context.getPlacementHorizontalFacing()

 

(Its almost like you looked at your own code and went "this is what I use to do the thing you want, so don't do that, do this other thing")

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

3 hours ago, Draco18s said:

(Its almost like you looked at your own code and went "this is what I use to do the thing you want, so don't do that, do this other thing") 

That's exactly what i did.?

 

But i only use HORIZONTAL_FACING and was not sure what you would use, if you want to include the posibiity you let your block face up and down.

It's somewhere in my commit history, but was to lazy to look it up.

I had that before but changed it horizontal only, since it looked somewhat strange  to have da machine lay on it's back instead of standing upright.

Link to comment
Share on other sites

getOpposite doesn't care about horizontal or not.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.



×
×
  • Create New...

Important Information

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