cable stuff
This commit is contained in:
@@ -2,10 +2,20 @@ package org.neoflock.neocomputers.platforms.fabric.client;
|
|||||||
|
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin;
|
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.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.BlockEntities;
|
||||||
import org.neoflock.neocomputers.entity.render.CaseEntityRenderer;
|
import org.neoflock.neocomputers.entity.render.CaseEntityRenderer;
|
||||||
import org.neoflock.neocomputers.entity.render.ScreenEntityRenderer;
|
import org.neoflock.neocomputers.entity.render.ScreenEntityRenderer;
|
||||||
|
import org.neoflock.neocomputers.item.Items;
|
||||||
import org.neoflock.neocomputers.platforms.fabric.client.model.ModelLoader;
|
import org.neoflock.neocomputers.platforms.fabric.client.model.ModelLoader;
|
||||||
|
|
||||||
public class NeoComputersFabricClient implements ClientModInitializer {
|
public class NeoComputersFabricClient implements ClientModInitializer {
|
||||||
@@ -14,5 +24,17 @@ public class NeoComputersFabricClient implements ClientModInitializer {
|
|||||||
ModelLoadingPlugin.register(new ModelLoader());
|
ModelLoadingPlugin.register(new ModelLoader());
|
||||||
BlockEntityRenderers.register(BlockEntities.INSTANCE.getSCREEN_ENTITY().get(), ScreenEntityRenderer::new);
|
BlockEntityRenderers.register(BlockEntities.INSTANCE.getSCREEN_ENTITY().get(), ScreenEntityRenderer::new);
|
||||||
BlockEntityRenderers.register(BlockEntities.INSTANCE.getCASE_ENTITY().get(), CaseEntityRenderer::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")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ public class ModelLoader implements ModelLoadingPlugin {
|
|||||||
public void onInitializeModelLoader(Context pluginContext) {
|
public void onInitializeModelLoader(Context pluginContext) {
|
||||||
pluginContext.modifyModelOnLoad().register((original, context) -> {
|
pluginContext.modifyModelOnLoad().register((original, context) -> {
|
||||||
// final ModelResourceLocation id = context.topLevelId();
|
// 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)) {
|
// if (id != null && id.id().equals(CABLE)) {
|
||||||
//// NeoComputers.INSTANCE.getLOGGER().error("DOING CABLEEEEEEE");
|
////// NeoComputers.INSTANCE.getLOGGER().error("DOING CABLEEEEEEE");
|
||||||
// return new CableModel();
|
// original.
|
||||||
// } else {
|
// } else {
|
||||||
// return original;
|
// return original;
|
||||||
// }
|
// }
|
||||||
|
|||||||
@@ -3,6 +3,13 @@ package org.neoflock.neocomputers.block
|
|||||||
import net.minecraft.client.renderer.blockentity.PistonHeadRenderer
|
import net.minecraft.client.renderer.blockentity.PistonHeadRenderer
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.core.Direction
|
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.BlockGetter
|
||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
import net.minecraft.world.level.block.Block
|
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.BlockState
|
||||||
import net.minecraft.world.level.block.state.StateDefinition
|
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.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.BooleanOp
|
||||||
import net.minecraft.world.phys.shapes.CollisionContext
|
import net.minecraft.world.phys.shapes.CollisionContext
|
||||||
import net.minecraft.world.phys.shapes.Shapes
|
import net.minecraft.world.phys.shapes.Shapes
|
||||||
@@ -26,6 +35,8 @@ class CableBlock() : BaseBlock(Properties.of()), EntityBlock {
|
|||||||
val UP = BooleanProperty.create("up")
|
val UP = BooleanProperty.create("up")
|
||||||
val DOWN = BooleanProperty.create("down")
|
val DOWN = BooleanProperty.create("down")
|
||||||
|
|
||||||
|
val COLOR = EnumProperty<DyeColor>.create("color", DyeColor::class.java)
|
||||||
|
|
||||||
val MIN = 0.375
|
val MIN = 0.375
|
||||||
val MAX = 1-MIN
|
val MAX = 1-MIN
|
||||||
|
|
||||||
@@ -68,6 +79,16 @@ class CableBlock() : BaseBlock(Properties.of()), EntityBlock {
|
|||||||
Direction.DOWN -> DOWN
|
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 {
|
init {
|
||||||
@@ -78,6 +99,7 @@ class CableBlock() : BaseBlock(Properties.of()), EntityBlock {
|
|||||||
.setValue(SOUTH, false)
|
.setValue(SOUTH, false)
|
||||||
.setValue(UP, false)
|
.setValue(UP, false)
|
||||||
.setValue(DOWN, false)
|
.setValue(DOWN, false)
|
||||||
|
.setValue(COLOR, DyeColor.LIGHT_GRAY)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +111,8 @@ class CableBlock() : BaseBlock(Properties.of()), EntityBlock {
|
|||||||
.add(SOUTH)
|
.add(SOUTH)
|
||||||
.add(WEST)
|
.add(WEST)
|
||||||
.add(UP)
|
.add(UP)
|
||||||
.add(DOWN))
|
.add(DOWN)
|
||||||
|
.add(COLOR))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun newBlockEntity(pos: BlockPos, state: BlockState): BlockEntity? {
|
override fun newBlockEntity(pos: BlockPos, state: BlockState): BlockEntity? {
|
||||||
@@ -109,7 +132,17 @@ class CableBlock() : BaseBlock(Properties.of()), EntityBlock {
|
|||||||
val diff = pos.subtract(neighborPos)
|
val diff = pos.subtract(neighborPos)
|
||||||
val dir = Direction.fromDelta(diff.x, diff.y, diff.z)!!.opposite
|
val dir = Direction.fromDelta(diff.x, diff.y, diff.z)!!.opposite
|
||||||
val ent = level.getBlockEntity(neighborPos)
|
val ent = level.getBlockEntity(neighborPos)
|
||||||
val value = ent is NodeBlockEntity || ent is CableEntity
|
// 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), value))
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,33 +2,21 @@ package org.neoflock.neocomputers.entity
|
|||||||
|
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.core.Direction
|
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.entity.BlockEntity
|
||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
import org.neoflock.neocomputers.block.CableBlock
|
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
|
import org.neoflock.neocomputers.block.NodeBlockEntity
|
||||||
|
|
||||||
class CableEntity(pos: BlockPos, state: BlockState) : BlockEntity(BlockEntities.CABLE_ENTITY.get(), pos, state) {
|
class CableEntity(pos: BlockPos, state: BlockState) : BlockEntity(BlockEntities.CABLE_ENTITY.get(), pos, state) {
|
||||||
|
|
||||||
override fun setChanged() {
|
override fun setChanged() {
|
||||||
super.setChanged()
|
super.setChanged()
|
||||||
// val neighbors = getNeighbourEntities()
|
|
||||||
|
|
||||||
for (dir in Direction.entries) {
|
for (dir in Direction.entries) {
|
||||||
val ent = level!!.getBlockEntity(blockPos.relative(dir))
|
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<BlockEntity> {
|
|
||||||
// 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) }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
@@ -2,19 +2,19 @@
|
|||||||
"parent": "minecraft:block/block",
|
"parent": "minecraft:block/block",
|
||||||
"render_type": "minecraft:solid",
|
"render_type": "minecraft:solid",
|
||||||
"textures": {
|
"textures": {
|
||||||
"cap": "neocomputers:block/cable_body"
|
"body": "neocomputers:block/cable_body"
|
||||||
},
|
},
|
||||||
"elements": [
|
"elements": [
|
||||||
{
|
{
|
||||||
"from": [6, 6, 6],
|
"from": [6, 6, 6],
|
||||||
"to": [10, 10, 10],
|
"to": [10, 10, 10],
|
||||||
"faces": {
|
"faces": {
|
||||||
"north": { "uv": [6,6,10,10], "texture": "#cap" },
|
"north": { "uv": [6,6,10,10], "texture": "#body", "tintindex": 0 },
|
||||||
"east": { "uv": [6,6,10,10], "texture": "#cap" },
|
"east": { "uv": [6,6,10,10], "texture": "#body", "tintindex": 0 },
|
||||||
"west": { "uv": [6,6,10,10], "texture": "#cap" },
|
"west": { "uv": [6,6,10,10], "texture": "#body", "tintindex": 0 },
|
||||||
"south": { "uv": [6,6,10,10], "texture": "#cap" },
|
"south": { "uv": [6,6,10,10], "texture": "#body", "tintindex": 0 },
|
||||||
"up": { "uv": [0,0, 5, 5], "texture": "#cap" },
|
"up": { "uv": [0,0, 5, 5], "texture": "#body", "tintindex": 0 },
|
||||||
"down": { "uv": [0,0, 5, 5], "texture": "#cap" }
|
"down": { "uv": [0,0, 5, 5], "texture": "#body", "tintindex": 0 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -10,11 +10,11 @@
|
|||||||
"from": [6, 6, 10],
|
"from": [6, 6, 10],
|
||||||
"to": [10, 10, 16],
|
"to": [10, 10, 16],
|
||||||
"faces": {
|
"faces": {
|
||||||
"east": { "uv": [4,4,11,11], "texture": "#body" },
|
"east": { "uv": [4,4,11,11], "texture": "#body", "tintindex": 0 },
|
||||||
"west": { "uv": [4,4,11,11], "texture": "#body" },
|
"west": { "uv": [4,4,11,11], "texture": "#body", "tintindex": 0 },
|
||||||
"up": { "uv": [4,4,11,11], "texture": "#body" },
|
"up": { "uv": [4,4,11,11], "texture": "#body", "tintindex": 0 },
|
||||||
"down": { "uv": [4,4,11,11], "texture": "#body" },
|
"down": { "uv": [4,4,11,11], "texture": "#body", "tintindex": 0 },
|
||||||
"south": { "uv": [6, 6, 10, 10], "texture": "#cap"}
|
"south": { "uv": [6, 6, 10, 10], "texture": "#cap", "tintindex": 0}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -7,20 +7,20 @@
|
|||||||
},
|
},
|
||||||
"elements": [
|
"elements": [
|
||||||
{
|
{
|
||||||
"from": [6, -2, 6],
|
"from": [6, 1, 6],
|
||||||
"to": [10, 18, 10],
|
"to": [10, 15, 10],
|
||||||
"faces": {
|
"faces": {
|
||||||
"east": { "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" },
|
"west": { "uv": [0,0,5,16], "texture": "#body", "tintindex": 0 },
|
||||||
"north": { "uv": [0,0,5,16], "texture": "#body" },
|
"north": { "uv": [0,0,5,16], "texture": "#body", "tintindex": 0 },
|
||||||
"south": { "uv": [0,0,5,16], "texture": "#body" },
|
"south": { "uv": [0,0,5,16], "texture": "#body", "tintindex": 0 },
|
||||||
"up": { "uv": [0,0,5,16], "texture": "#body" },
|
"up": { "uv": [0,0,5,16], "texture": "#body", "tintindex": 0 },
|
||||||
"down": { "uv": [0,0,5,16], "texture": "#body" }
|
"down": { "uv": [0,0,5,16], "texture": "#body", "tintindex": 0 }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"from": [4, -3, 4],
|
"from": [4, 0, 4],
|
||||||
"to": [12, -2, 12],
|
"to": [12, 1, 12],
|
||||||
"faces": {
|
"faces": {
|
||||||
"east": { "uv": [0,0,4,4], "texture": "#cap" },
|
"east": { "uv": [0,0,4,4], "texture": "#cap" },
|
||||||
"west": { "uv": [0,0,4,4], "texture": "#cap" },
|
"west": { "uv": [0,0,4,4], "texture": "#cap" },
|
||||||
@@ -30,8 +30,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"from": [4, 18, 4],
|
"from": [4, 15, 4],
|
||||||
"to": [12, 19, 12],
|
"to": [12, 16, 12],
|
||||||
"faces": {
|
"faces": {
|
||||||
"east": { "uv": [0,0,4,4], "texture": "#cap" },
|
"east": { "uv": [0,0,4,4], "texture": "#cap" },
|
||||||
"west": { "uv": [0,0,4,4], "texture": "#cap" },
|
"west": { "uv": [0,0,4,4], "texture": "#cap" },
|
||||||
|
|||||||
Reference in New Issue
Block a user