From 883833351cdcce7946563e69c215f90176cec545 Mon Sep 17 00:00:00 2001 From: mewhenthe Date: Mon, 27 Apr 2026 11:20:22 +0200 Subject: [PATCH] cable stuff --- .../client/NeoComputersFabricClient.java | 22 +++++++++++ .../fabric/client/model/ModelLoader.java | 6 +-- .../neoflock/neocomputers/block/CableBlock.kt | 39 +++++++++++++++++-- .../neocomputers/entity/CableEntity.kt | 20 ++-------- .../models/block/cable/cable_center.json | 14 +++---- .../models/block/cable/cable_connection.json | 10 ++--- .../models/block/cable/cable_item.json | 24 ++++++------ 7 files changed, 89 insertions(+), 46 deletions(-) diff --git a/src/main/java/org/neoflock/neocomputers/platforms/fabric/client/NeoComputersFabricClient.java b/src/main/java/org/neoflock/neocomputers/platforms/fabric/client/NeoComputersFabricClient.java index dedbbd1..2c77dd7 100644 --- a/src/main/java/org/neoflock/neocomputers/platforms/fabric/client/NeoComputersFabricClient.java +++ b/src/main/java/org/neoflock/neocomputers/platforms/fabric/client/NeoComputersFabricClient.java @@ -2,10 +2,20 @@ package org.neoflock.neocomputers.platforms.fabric.client; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin; +import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; +import net.minecraft.client.color.item.ItemColor; +import net.minecraft.client.color.item.ItemColors; import net.minecraft.client.renderer.blockentity.BlockEntityRenderers; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.DyeColor; +import net.minecraft.world.level.ItemLike; +import org.neoflock.neocomputers.NeoComputers; +import org.neoflock.neocomputers.block.Blocks; +import org.neoflock.neocomputers.block.CableBlock; import org.neoflock.neocomputers.entity.BlockEntities; import org.neoflock.neocomputers.entity.render.CaseEntityRenderer; import org.neoflock.neocomputers.entity.render.ScreenEntityRenderer; +import org.neoflock.neocomputers.item.Items; import org.neoflock.neocomputers.platforms.fabric.client.model.ModelLoader; public class NeoComputersFabricClient implements ClientModInitializer { @@ -14,5 +24,17 @@ public class NeoComputersFabricClient implements ClientModInitializer { ModelLoadingPlugin.register(new ModelLoader()); BlockEntityRenderers.register(BlockEntities.INSTANCE.getSCREEN_ENTITY().get(), ScreenEntityRenderer::new); BlockEntityRenderers.register(BlockEntities.INSTANCE.getCASE_ENTITY().get(), CaseEntityRenderer::new); + + ColorProviderRegistry.BLOCK.register((state, world, pos, index) -> { + if (index == 0) { + return state.getValue(CableBlock.Companion.getCOLOR()).getTextureDiffuseColor(); + } else { + return 0xFFFFFF; + } + }, Blocks.INSTANCE.getCABLE_BLOCK().get()); + + ColorProviderRegistry.ITEM.register((stack, index)-> { + return DyeColor.LIGHT_GRAY.getTextureDiffuseColor(); + }, Items.INSTANCE.getITEMS().getRegistrar().get(ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "cable"))); } } diff --git a/src/main/java/org/neoflock/neocomputers/platforms/fabric/client/model/ModelLoader.java b/src/main/java/org/neoflock/neocomputers/platforms/fabric/client/model/ModelLoader.java index 20bb4cb..7cf46c9 100644 --- a/src/main/java/org/neoflock/neocomputers/platforms/fabric/client/model/ModelLoader.java +++ b/src/main/java/org/neoflock/neocomputers/platforms/fabric/client/model/ModelLoader.java @@ -12,10 +12,10 @@ public class ModelLoader implements ModelLoadingPlugin { public void onInitializeModelLoader(Context pluginContext) { pluginContext.modifyModelOnLoad().register((original, context) -> { // final ModelResourceLocation id = context.topLevelId(); -//// if (id != null && id.id().getNamespace().equals(NeoComputers.MODID)) NeoComputers.INSTANCE.getLOGGER().info("{} {} {}", id.id().getNamespace(), id.id().getPath(), id.id().getPath().equals(CABLE.id().getPath())); +////// if (id != null && id.id().getNamespace().equals(NeoComputers.MODID)) NeoComputers.INSTANCE.getLOGGER().info("{} {} {}", id.id().getNamespace(), id.id().getPath(), id.id().getPath().equals(CABLE.id().getPath())); // if (id != null && id.id().equals(CABLE)) { -//// NeoComputers.INSTANCE.getLOGGER().error("DOING CABLEEEEEEE"); -// return new CableModel(); +////// NeoComputers.INSTANCE.getLOGGER().error("DOING CABLEEEEEEE"); +// original. // } else { // return original; // } diff --git a/src/main/kotlin/org/neoflock/neocomputers/block/CableBlock.kt b/src/main/kotlin/org/neoflock/neocomputers/block/CableBlock.kt index f959082..ae83853 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/block/CableBlock.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/block/CableBlock.kt @@ -3,6 +3,13 @@ package org.neoflock.neocomputers.block import net.minecraft.client.renderer.blockentity.PistonHeadRenderer import net.minecraft.core.BlockPos import net.minecraft.core.Direction +import net.minecraft.world.InteractionHand +import net.minecraft.world.ItemInteractionResult +import net.minecraft.world.entity.player.Player +import net.minecraft.world.item.DyeColor +import net.minecraft.world.item.DyeItem +import net.minecraft.world.item.ItemStack +import net.minecraft.world.item.Items import net.minecraft.world.level.BlockGetter import net.minecraft.world.level.Level import net.minecraft.world.level.block.Block @@ -11,6 +18,8 @@ import net.minecraft.world.level.block.entity.BlockEntity import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.StateDefinition import net.minecraft.world.level.block.state.properties.BooleanProperty +import net.minecraft.world.level.block.state.properties.EnumProperty +import net.minecraft.world.phys.BlockHitResult import net.minecraft.world.phys.shapes.BooleanOp import net.minecraft.world.phys.shapes.CollisionContext import net.minecraft.world.phys.shapes.Shapes @@ -26,6 +35,8 @@ class CableBlock() : BaseBlock(Properties.of()), EntityBlock { val UP = BooleanProperty.create("up") val DOWN = BooleanProperty.create("down") + val COLOR = EnumProperty.create("color", DyeColor::class.java) + val MIN = 0.375 val MAX = 1-MIN @@ -68,6 +79,16 @@ class CableBlock() : BaseBlock(Properties.of()), EntityBlock { Direction.DOWN -> DOWN } } + fun shouldConnect(pos: BlockPos, npos: BlockPos, level: Level): Boolean { + val ent = level.getBlockEntity(npos) + val blockState = level.getBlockState(pos) + + return (ent is CableEntity && + (level.getBlockState(npos).getValue(COLOR).equals(blockState.getValue(COLOR)) || + blockState.getValue(COLOR).equals(DyeColor.LIGHT_GRAY) || + level.getBlockState(npos).getValue(COLOR).equals(DyeColor.LIGHT_GRAY))) +// val state: BlockState? = (ent is CableEntity && (level.getBlockState(neighborPos).getValue(COLOR).equals(state.getValue(COLOR)) || state.getValue(COLOR).equals(DyeColor.LIGHT_GRAY)) + } } init { @@ -78,6 +99,7 @@ class CableBlock() : BaseBlock(Properties.of()), EntityBlock { .setValue(SOUTH, false) .setValue(UP, false) .setValue(DOWN, false) + .setValue(COLOR, DyeColor.LIGHT_GRAY) ) } @@ -89,7 +111,8 @@ class CableBlock() : BaseBlock(Properties.of()), EntityBlock { .add(SOUTH) .add(WEST) .add(UP) - .add(DOWN)) + .add(DOWN) + .add(COLOR)) } override fun newBlockEntity(pos: BlockPos, state: BlockState): BlockEntity? { @@ -109,7 +132,17 @@ class CableBlock() : BaseBlock(Properties.of()), EntityBlock { val diff = pos.subtract(neighborPos) val dir = Direction.fromDelta(diff.x, diff.y, diff.z)!!.opposite val ent = level.getBlockEntity(neighborPos) - val value = ent is NodeBlockEntity || ent is CableEntity - level.setBlockAndUpdate(pos, state.setValue(getPropByDirection(dir), value)) +// val value = ent is NodeBlockEntity || (ent is CableEntity && (level.getBlockState(neighborPos).getValue(COLOR).equals(state.getValue(COLOR)) || state.getValue(COLOR).equals(DyeColor.LIGHT_GRAY))) + level.setBlockAndUpdate(pos, state.setValue(getPropByDirection(dir), shouldConnect(pos, neighborPos, level))) + } + + override fun useItemOn(stack: ItemStack, state: BlockState, level: Level, pos: BlockPos, player: Player, hand: InteractionHand, hitResult: BlockHitResult): ItemInteractionResult? { +// return super.useItemOn(stack, state, level, pos, player, hand, hitResult) + if (stack.item is DyeItem) { + val dyeitem = stack.item as DyeItem + level.setBlockAndUpdate(pos, state.setValue(COLOR, dyeitem.dyeColor)) + return ItemInteractionResult.SUCCESS + } + return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION } } \ No newline at end of file diff --git a/src/main/kotlin/org/neoflock/neocomputers/entity/CableEntity.kt b/src/main/kotlin/org/neoflock/neocomputers/entity/CableEntity.kt index 8247435..0ace58b 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/entity/CableEntity.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/entity/CableEntity.kt @@ -2,33 +2,21 @@ package org.neoflock.neocomputers.entity import net.minecraft.core.BlockPos import net.minecraft.core.Direction +import net.minecraft.world.item.DyeColor import net.minecraft.world.level.block.entity.BlockEntity import net.minecraft.world.level.block.state.BlockState import org.neoflock.neocomputers.block.CableBlock +import org.neoflock.neocomputers.block.CableBlock.Companion.COLOR +import org.neoflock.neocomputers.block.CableBlock.Companion.getPropByDirection import org.neoflock.neocomputers.block.NodeBlockEntity class CableEntity(pos: BlockPos, state: BlockState) : BlockEntity(BlockEntities.CABLE_ENTITY.get(), pos, state) { override fun setChanged() { super.setChanged() -// val neighbors = getNeighbourEntities() - for (dir in Direction.entries) { val ent = level!!.getBlockEntity(blockPos.relative(dir)) - level!!.setBlockAndUpdate(blockPos, blockState.setValue(CableBlock.getPropByDirection(dir), (ent is NodeBlockEntity || ent is CableEntity))) + level!!.setBlockAndUpdate(blockPos, blockState.setValue(getPropByDirection(dir), CableBlock.shouldConnect(blockPos, blockPos.relative(dir), level!!))) } - } -// fun getNeighbourEntities(): List { -// val subpos = listOf( -// blockPos.offset(0, 0, 1), -// blockPos.offset(0, 0, -1), -// blockPos.offset(0, 1, 0), -// blockPos.offset(0, -1, 0), -// blockPos.offset(1, 0, 0), -// blockPos.offset(-1, 0, 0), -// ) -// -// return subpos.mapNotNull { pos -> level?.getBlockEntity(pos) } -// } } \ No newline at end of file diff --git a/src/main/resources/assets/neocomputers/models/block/cable/cable_center.json b/src/main/resources/assets/neocomputers/models/block/cable/cable_center.json index abc67d0..4cf8501 100644 --- a/src/main/resources/assets/neocomputers/models/block/cable/cable_center.json +++ b/src/main/resources/assets/neocomputers/models/block/cable/cable_center.json @@ -2,19 +2,19 @@ "parent": "minecraft:block/block", "render_type": "minecraft:solid", "textures": { - "cap": "neocomputers:block/cable_body" + "body": "neocomputers:block/cable_body" }, "elements": [ { "from": [6, 6, 6], "to": [10, 10, 10], "faces": { - "north": { "uv": [6,6,10,10], "texture": "#cap" }, - "east": { "uv": [6,6,10,10], "texture": "#cap" }, - "west": { "uv": [6,6,10,10], "texture": "#cap" }, - "south": { "uv": [6,6,10,10], "texture": "#cap" }, - "up": { "uv": [0,0, 5, 5], "texture": "#cap" }, - "down": { "uv": [0,0, 5, 5], "texture": "#cap" } + "north": { "uv": [6,6,10,10], "texture": "#body", "tintindex": 0 }, + "east": { "uv": [6,6,10,10], "texture": "#body", "tintindex": 0 }, + "west": { "uv": [6,6,10,10], "texture": "#body", "tintindex": 0 }, + "south": { "uv": [6,6,10,10], "texture": "#body", "tintindex": 0 }, + "up": { "uv": [0,0, 5, 5], "texture": "#body", "tintindex": 0 }, + "down": { "uv": [0,0, 5, 5], "texture": "#body", "tintindex": 0 } } } ] diff --git a/src/main/resources/assets/neocomputers/models/block/cable/cable_connection.json b/src/main/resources/assets/neocomputers/models/block/cable/cable_connection.json index 7d736ad..c1d7445 100644 --- a/src/main/resources/assets/neocomputers/models/block/cable/cable_connection.json +++ b/src/main/resources/assets/neocomputers/models/block/cable/cable_connection.json @@ -10,11 +10,11 @@ "from": [6, 6, 10], "to": [10, 10, 16], "faces": { - "east": { "uv": [4,4,11,11], "texture": "#body" }, - "west": { "uv": [4,4,11,11], "texture": "#body" }, - "up": { "uv": [4,4,11,11], "texture": "#body" }, - "down": { "uv": [4,4,11,11], "texture": "#body" }, - "south": { "uv": [6, 6, 10, 10], "texture": "#cap"} + "east": { "uv": [4,4,11,11], "texture": "#body", "tintindex": 0 }, + "west": { "uv": [4,4,11,11], "texture": "#body", "tintindex": 0 }, + "up": { "uv": [4,4,11,11], "texture": "#body", "tintindex": 0 }, + "down": { "uv": [4,4,11,11], "texture": "#body", "tintindex": 0 }, + "south": { "uv": [6, 6, 10, 10], "texture": "#cap", "tintindex": 0} } } ] diff --git a/src/main/resources/assets/neocomputers/models/block/cable/cable_item.json b/src/main/resources/assets/neocomputers/models/block/cable/cable_item.json index c06c056..7e5a3e6 100644 --- a/src/main/resources/assets/neocomputers/models/block/cable/cable_item.json +++ b/src/main/resources/assets/neocomputers/models/block/cable/cable_item.json @@ -7,20 +7,20 @@ }, "elements": [ { - "from": [6, -2, 6], - "to": [10, 18, 10], + "from": [6, 1, 6], + "to": [10, 15, 10], "faces": { - "east": { "uv": [0,0,5,16], "texture": "#body" }, - "west": { "uv": [0,0,5,16], "texture": "#body" }, - "north": { "uv": [0,0,5,16], "texture": "#body" }, - "south": { "uv": [0,0,5,16], "texture": "#body" }, - "up": { "uv": [0,0,5,16], "texture": "#body" }, - "down": { "uv": [0,0,5,16], "texture": "#body" } + "east": { "uv": [0,0,5,16], "texture": "#body", "tintindex": 0 }, + "west": { "uv": [0,0,5,16], "texture": "#body", "tintindex": 0 }, + "north": { "uv": [0,0,5,16], "texture": "#body", "tintindex": 0 }, + "south": { "uv": [0,0,5,16], "texture": "#body", "tintindex": 0 }, + "up": { "uv": [0,0,5,16], "texture": "#body", "tintindex": 0 }, + "down": { "uv": [0,0,5,16], "texture": "#body", "tintindex": 0 } } }, { - "from": [4, -3, 4], - "to": [12, -2, 12], + "from": [4, 0, 4], + "to": [12, 1, 12], "faces": { "east": { "uv": [0,0,4,4], "texture": "#cap" }, "west": { "uv": [0,0,4,4], "texture": "#cap" }, @@ -30,8 +30,8 @@ } }, { - "from": [4, 18, 4], - "to": [12, 19, 12], + "from": [4, 15, 4], + "to": [12, 16, 12], "faces": { "east": { "uv": [0,0,4,4], "texture": "#cap" }, "west": { "uv": [0,0,4,4], "texture": "#cap" },