Jump to content

Changing block texture depending of the direction it was placed


TokiiWalkie

Recommended Posts

Hello, I’m pretty new in the Minecraft modding community, and I’m having a lot of difficulties, since i’m a beginner. Actually, I’m working on a big railway project on Minecraft, and I wanted to create a mod that fills what is missing. I started by doing a platform indicator block to indicate the player the train he needs to take (a texture example is attached). But my stations won’t be all in the same directions, so I need to make a block that has different faces depending on the player position, but I don’t know how to do.

 

I tried some researches on the Internet, I tried to find answers in the source code of other mods, but I can’t figure how to do this kind of block :(

 

Maybe using BlockState? I really don’t know...

 

Here is my project structure :

 

image.thumb.png.b846d57c19d08d3c25441cc447b5d6a5.png

 

Here is some codes :

 

# Block class
  public class PlatformIndicatorBlock extends Block {
    public PlatformIndicatorBlock() {
        super(AbstractBlock.Properties.create(Material.CLAY, MaterialColor.LIGHT_BLUE)
                .hardnessAndResistance(2f, 6f)
                .harvestTool(ToolType.PICKAXE)
                .harvestLevel(1)
                .sound(SoundType.STONE));
    }
}
// Blockstate file
{
  "variants": {
    "": { "model": "twlksrailwayproject:block/platform_indicator_block" }
  }
}
// Model file
{
  "parent": "block/cube",
  "textures": {
    "front": "twlksrailwayproject:blocks/platform_indicator_block_front",
    "side": "twlksrailwayproject:blocks/platform_indicator_block_side"
  },
  "elements": [
    {
      "from": [0, 0, 0],
      "to": [16, 16, 16],
      "faces": {
        "down":  { "texture": "#side", "cullface": "down" },
        "up":    { "texture": "#side", "cullface": "up" },
        "north": { "texture": "#front", "cullface": "north" },
        "south": { "texture": "#side", "cullface": "south" },
        "west":  { "texture": "#side", "cullface": "west" },
        "east":  { "texture": "#side", "cullface": "east" }
      }
    }
  ]
}

 

(Sorry for bad english, I’m french and not fluent yet ^^’)

7.png

Link to comment
Share on other sites

So, I’ve been looking for the source code of the furnace block, but it was a bit too complicated for me ^^'. So, I searched on the source code of the mod "IronFurnaces", and I found something interesting :

public class PlatformIndicatorBlock extends Block {
    public PlatformIndicatorBlock() {
        super(AbstractBlock.Properties.create(Material.CLAY, MaterialColor.LIGHT_BLUE)
                .hardnessAndResistance(2f, 6f)
                .harvestTool(ToolType.PICKAXE)
                .harvestLevel(1)
                .sound(SoundType.STONE));
    }

  	// What I’ve added
  
    @Override
    public BlockState getStateForPlacement(BlockItemUseContext ctx) {
        return (BlockState) this.getDefaultState().with(BlockStateProperties.HORIZONTAL_FACING,         ctx.getPlacementHorizontalFacing().getOpposite());
    }
}

 

But now, it creshes when I try to place the block :

 

// You're mean.

Time: 07/02/21 12:25
Description: Unexpected error

java.lang.IllegalArgumentException: Cannot set property DirectionProperty{name=facing, clazz=class net.minecraft.util.Direction, values=[north, south, west, east]} as it does not exist in Block{twlksrailwayproject:platform_indicator
_block}
        at net.minecraft.state.StateHolder.with(StateHolder.java:109) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
        at fr.twlk.therailwaysproject.content.blocks.PlatformIndicatorBlock.getStateForPlacement(PlatformIndicatorBlock.java:31) ~[main/:?] {re:classloading}
        at net.minecraft.item.BlockItem.getStateForPlacement(BlockItem.java:108) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
        at net.minecraft.item.BlockItem.tryPlace(BlockItem.java:54) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
        at net.minecraft.item.BlockItem.onItemUse(BlockItem.java:42) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
        at net.minecraft.item.ItemStack.lambda$onItemUse$5(ItemStack.java:192) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
        at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:207) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
        at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:192) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
        at net.minecraft.client.multiplayer.PlayerController.func_217292_a(PlayerController.java:319) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
        at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1407) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
        at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:1692) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
        at net.minecraft.client.Minecraft.runTick(Minecraft.java:1507) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
        at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:979) ~[forge-1.16.4-35.1.4_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.4_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.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_275] {}
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_275] {}
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_275] {}
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_275] {}
        at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.4-35.1.4_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.4_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.minecraft.state.StateHolder.with(StateHolder.java:109) ~[forge:?] {re:classloading}
        at fr.twlk.therailwaysproject.content.blocks.PlatformIndicatorBlock.getStateForPlacement(PlatformIndicatorBlock.java:31) ~[?:?] {re:classloading}
        at net.minecraft.item.BlockItem.getStateForPlacement(BlockItem.java:108) ~[forge:?] {re:classloading}
        at net.minecraft.item.BlockItem.tryPlace(BlockItem.java:54) ~[forge:?] {re:classloading}
        at net.minecraft.item.BlockItem.onItemUse(BlockItem.java:42) ~[forge:?] {re:classloading}
        at net.minecraft.item.ItemStack.lambda$onItemUse$5(ItemStack.java:192) ~[forge:?] {re:classloading}
        at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:207) ~[forge:?] {re:classloading}
        at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:192) ~[forge:?] {re:classloading}
        at net.minecraft.client.multiplayer.PlayerController.func_217292_a(PlayerController.java:319) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A}
        at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1407) ~[forge:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
        at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:1692) ~[forge:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
-- Affected level --
Details:
        All players: 1 total; [ClientPlayerEntity['Dev'/146, l='ClientLevel', x=228.57, y=72.00, z=132.31]]
        Chunk stats: Client Chunk Cache: 121, 35
        Level dimension: minecraft:overworld
        Level spawn location: World: (176,68,-16), Chunk: (at 0,4,0 in 11,-1; contains blocks 176,0,-16 to 191,255,-1), Region: (0,-1; contains chunks 0,-32 to 31,-1, blocks 0,0,-512 to 511,255,-1)
        Level time: 91379 game time, 1 day time
        Server brand: forge
        Server type: Integrated singleplayer server
Stacktrace:
        at net.minecraft.client.world.ClientWorld.fillCrashReport(ClientWorld.java:465) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
        at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2086) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
        at net.minecraft.client.Minecraft.run(Minecraft.java:633) ~[forge-1.16.4-35.1.4_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.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_275] {}
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_275] {}
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_275] {}
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_275] {}
        at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.4-35.1.4_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.4_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_275, Oracle Corporation
        Java VM Version: OpenJDK 64-Bit Server VM (mixed mode), Oracle Corporation
        Memory: 509008104 bytes (485 MB) / 1163919360 bytes (1110 MB) up to 1881145344 bytes (1794 MB)
        CPUs: 4
        JVM Flags: 1 total; -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.4_mapped_snapshot_20201028-1.16.3-launcher.jar object_holder_definalize PLUGINSERVICE
                /forge-1.16.4-35.1.4_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.4_mapped_snapshot_20201028-1.16.3-launcher.jar capability_inject_definalize PLUGINSERVICE
                /forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-launcher.jar runtimedistcleaner PLUGINSERVICE
                /mixin-0.8.2.jar mixin TRANSFORMATIONSERVICE
                /forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-launcher.jar fml TRANSFORMATIONSERVICE
        FML: 35.1
        Forge: net.minecraftforge:35.1.4
        FML Language Providers:
                [email protected]
                minecraft@1
        Mod List:
                client-extra.jar                                  |Minecraft                     |minecraft                     |1.16.4              |DONE      |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                                              |Example Mod                   |twlksrailwayproject           |1.0                 |DONE      |NOSIGNATURE
                forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.|Forge                         |forge                         |35.1.4              |DONE      |NOSIGNATURE
        Crash Report UUID: a705293e-ad82-4e78-b8af-bfc6be8b698b
        Launched Version: MOD_DEV
        Backend library: LWJGL version 3.2.2 build 10
        Backend API: Intel(R) Iris(TM) Graphics 5100 GL version 4.3.0 - Build 20.19.15.4624, Intel
        GL Caps: Using framebuffer using OpenGL 3.0
        Using VBOs: Yes
        Is Modded: Definitely; Client brand changed to 'forge'
        Type: Client (map_client.txt)
        Graphics mode: fast
        Resource Packs:
        Current Language: English (US)
        CPU: 4x Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz

 

I have also modified some files :

 

// Blockstate file

{
  "variants": {
    "facing=east": {
      "model": "minecraft:block/platform_indicator_block",
      "y": 90
    },
    "facing=north": {
      "model": "minecraft:block/platform_indicator_block"
    },
    "facing=south": {
      "model": "minecraft:block/platform_indicator_block",
      "y": 180
    },
    "facing=west": {
      "model": "minecraft:block/platform_indicator_block",
      "y": 270
    }
  }
}

 

// Model file

{
  "parent": "minecraft:block/orientable",
  "textures": {
    "top": "minecraft:block/platform_indicator_block_side",
    "front": "minecraft:block/platform_indicator_block_front",
    "side": "minecraft:block/platform_indicator_block_side"
  }
}

 

Maybe you know this error and why it crashes?

Edited by TokiiWalkie
Wrong model file
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.