merged
This commit is contained in:
@@ -3,11 +3,13 @@ package org.neoflock.neocomputers.platforms.fabric.client;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
|
||||
import org.neoflock.neocomputers.entity.BlockEntities;
|
||||
import org.neoflock.neocomputers.gui.render.CaseEntityRenderer;
|
||||
import org.neoflock.neocomputers.gui.render.ScreenEntityRenderer;
|
||||
|
||||
public class NeoComputersFabricClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
BlockEntityRenderers.register(BlockEntities.INSTANCE.getSCREEN_ENTITY().get(), ScreenEntityRenderer::new);
|
||||
BlockEntityRenderers.register(BlockEntities.INSTANCE.getCASE_ENTITY().get(), CaseEntityRenderer::new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ 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.level.block.state.properties.EnumProperty.*
|
||||
import net.minecraft.world.level.block.state.properties.IntegerProperty
|
||||
import net.minecraft.world.phys.BlockHitResult
|
||||
import org.neoflock.neocomputers.NeoComputers
|
||||
import org.neoflock.neocomputers.entity.BlockEntities
|
||||
@@ -37,12 +38,13 @@ import kotlin.math.max
|
||||
|
||||
class ScreenBlock() : NodeBlock() {
|
||||
companion object {
|
||||
val FACING: EnumProperty<Direction> = EnumProperty.create<Direction>("facing", Direction::class.java)
|
||||
val FACING_HORIZ: EnumProperty<Direction> = EnumProperty.create<Direction>("facing_horiz", Direction::class.java)
|
||||
val FACING_VERTI: IntegerProperty = IntegerProperty.create("facing_verti", 0, 2) // "Integer" property doesnt accept values below 0, also death to enums, long live magic numbers
|
||||
val ENERGY: Long = 5
|
||||
}
|
||||
|
||||
init {
|
||||
registerDefaultState(stateDefinition.any().setValue(FACING, Direction.NORTH))
|
||||
registerDefaultState(stateDefinition.any().setValue(FACING_HORIZ, Direction.NORTH).setValue(FACING_VERTI, 1))
|
||||
}
|
||||
|
||||
override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity? {
|
||||
@@ -83,10 +85,26 @@ class ScreenBlock() : NodeBlock() {
|
||||
}
|
||||
|
||||
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block?, BlockState?>) {
|
||||
builder.add(FACING)
|
||||
builder.add(FACING_HORIZ)
|
||||
builder.add(FACING_VERTI)
|
||||
}
|
||||
|
||||
override fun getStateForPlacement(context: BlockPlaceContext): BlockState? {
|
||||
return super.getStateForPlacement(context)!!.setValue(FACING, context.nearestLookingDirection.opposite)
|
||||
val horiz = context.horizontalDirection
|
||||
val looking = context.player!!.lookAngle
|
||||
|
||||
val biggest = max(max(abs(looking.y), abs(looking.z)), abs(looking.x))
|
||||
|
||||
return super.getStateForPlacement(context)!!
|
||||
.setValue(FACING_HORIZ, horiz.opposite)
|
||||
.setValue(FACING_VERTI, if (biggest != abs(looking.y)) 1 else if (looking.y < 0) 2 else 0 )
|
||||
|
||||
// val dirs = context.nearestLookingDirections
|
||||
// context.
|
||||
// return when (face) {
|
||||
// Direction.UP -> super.getStateForPlacement(context)!!.setValue(FACING_HORIZ, looking.opposite).setValue(FACING_VERTI, 2)
|
||||
// Direction.DOWN -> super.getStateForPlacement(context)!!.setValue(FACING_HORIZ, looking.opposite).setValue(FACING_VERTI, 0)
|
||||
// else -> super.getStateForPlacement(context)!!.setValue(FACING_HORIZ, looking.opposite).setValue(FACING_VERTI, 1)
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,7 @@ class CaseBlockEntity(blockPos: BlockPos, blockState: BlockState): NodeBlockEnti
|
||||
val stacks: NonNullList<ItemStack> = NonNullList<ItemStack>.withSize(7, ItemStack.EMPTY)
|
||||
|
||||
var isOn = false
|
||||
var isDisking = false // TOOD: writing writers and reading readers
|
||||
var err: String? = null
|
||||
var arch = "Lua 5.3"
|
||||
var soundInstance: SoundInstance? = null
|
||||
@@ -49,12 +50,14 @@ class CaseBlockEntity(blockPos: BlockPos, blockState: BlockState): NodeBlockEnti
|
||||
override fun encodeDownstreamData(packet: FriendlyByteBuf) {
|
||||
super.encodeDownstreamData(packet)
|
||||
packet.writeBoolean(isOn)
|
||||
packet.writeBoolean(isDisking)
|
||||
packet.writeUtf(err ?: "")
|
||||
}
|
||||
|
||||
override fun syncWithUpstream(packet: FriendlyByteBuf) {
|
||||
super.syncWithUpstream(packet)
|
||||
setRunning(packet.readBoolean())
|
||||
isDisking = packet.readBoolean()
|
||||
err = packet.readUtf().ifEmpty { null }
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,9 @@ class ScreenEntity(blockPos: BlockPos, blockState: BlockState) :
|
||||
|
||||
override val node = Networking.Node()
|
||||
var bound = "screen/unbound"
|
||||
var render_on_block = false
|
||||
|
||||
val scrwidth: Short = 160
|
||||
val scrheight: Short = 50
|
||||
val scrwidth: Short = 50
|
||||
val scrheight: Short = 16
|
||||
|
||||
private var cleanrenderer: () -> Unit = { }; // TODO: THIS SUCKS, FIND A BETTER WAY
|
||||
|
||||
@@ -32,7 +31,7 @@ class ScreenEntity(blockPos: BlockPos, blockState: BlockState) :
|
||||
|
||||
override fun tickNode(level: Level) {
|
||||
super.tickNode(level)
|
||||
if (bound == "screen/unbound" && level.isClientSide) { // am i epstein or am i just retarded?
|
||||
if (bound == "screen/unbound") { // am i epstein or am i just retarded?
|
||||
createscreenstuffs()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package org.neoflock.neocomputers.gui.render
|
||||
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer
|
||||
import com.mojang.blaze3d.vertex.VertexFormat
|
||||
import com.mojang.math.Axis
|
||||
import net.minecraft.client.renderer.MultiBufferSource
|
||||
import net.minecraft.client.renderer.RenderStateShard
|
||||
import net.minecraft.client.renderer.RenderType
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider
|
||||
import net.minecraft.core.Direction
|
||||
import org.neoflock.neocomputers.NeoComputers
|
||||
import org.neoflock.neocomputers.block.CaseBlock
|
||||
import org.neoflock.neocomputers.entity.CaseBlockEntity
|
||||
|
||||
class CaseEntityRenderer(private val context: BlockEntityRendererProvider.Context?) : BlockEntityRenderer<CaseBlockEntity>{
|
||||
|
||||
val OFF = 0xFF5F855E.toInt()
|
||||
val GREEN = 0xFF4EDC5E.toInt()
|
||||
val RED = 0xFFff102B.toInt()
|
||||
|
||||
val BLINKTIME: Long = 10 // in ticks
|
||||
|
||||
val RENDER_TYPE = RenderType.create("nc_case", DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.QUADS,
|
||||
RenderType.TRANSIENT_BUFFER_SIZE, RenderType.CompositeState.builder()
|
||||
.setShaderState(RenderStateShard.POSITION_COLOR_SHADER)
|
||||
.createCompositeState(false))
|
||||
|
||||
override fun render(ent: CaseBlockEntity, partialTick: Float, mat: PoseStack, bufferSource: MultiBufferSource, packedLight: Int, packedOverlay: Int) {
|
||||
val buffer = bufferSource.getBuffer(RENDER_TYPE);
|
||||
|
||||
mat.pushPose()
|
||||
handleDirection(ent.blockState.getValue(CaseBlock.FACING), mat)
|
||||
|
||||
mat.translate(5/16F, 14/16F, 0.0001F)
|
||||
if (ent.isOn) drawLED(buffer, mat.last(), 3F)
|
||||
else if (ent.getLastError() != null) { // if else hell
|
||||
if ((ent.level!!.dayTime/BLINKTIME) % 2 == 1.toLong()) drawLED(buffer, mat.last(), 3F, RED)
|
||||
else drawLED(buffer, mat.last(), 3F, OFF)
|
||||
} else drawLED(buffer, mat.last(), 3F, OFF)
|
||||
|
||||
mat.translate(6/16F, 0F, 0F)
|
||||
drawLED(buffer, mat.last(), 2F, if (ent.isDisking) GREEN else OFF)
|
||||
|
||||
mat.popPose()
|
||||
|
||||
}
|
||||
private fun drawLED(buffer: VertexConsumer, mat: PoseStack.Pose, width: Float, color: Int = GREEN) {
|
||||
buffer.addVertex(mat, width/16F, 0F, 0F).setColor(color)
|
||||
buffer.addVertex(mat, width/16F, 1/16F, 0F).setColor(color)
|
||||
buffer.addVertex(mat, 0F, 1/16F, 0F).setColor(color)
|
||||
buffer.addVertex(mat, 0F, 0F, 0F).setColor(color)
|
||||
}
|
||||
|
||||
private fun handleDirection(facing: Direction, mat: PoseStack) {
|
||||
when (facing) {
|
||||
Direction.SOUTH -> { mat.translate(0F, 0F, 1F) }
|
||||
Direction.EAST -> { mat.mulPose(Axis.YP.rotationDegrees(90F)); mat.translate(-1F, 0F, 1F) }
|
||||
Direction.WEST -> { mat.mulPose(Axis.YN.rotationDegrees(90F)); }
|
||||
Direction.NORTH -> {mat.mulPose(Axis.YP.rotationDegrees(180F)); mat.translate(-1F, 0F, 0F) }
|
||||
else -> return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,6 @@ import org.neoflock.neocomputers.entity.ScreenEntity
|
||||
|
||||
|
||||
class ScreenEntityRenderer(val context: BlockEntityRendererProvider.Context?) : BlockEntityRenderer<ScreenEntity> { // TODO: FORGE
|
||||
|
||||
companion object {
|
||||
val RENDER_TYPE: (ResourceLocation) -> RenderType = { t: ResourceLocation ->
|
||||
RenderType.create(
|
||||
"nc_screen",
|
||||
@@ -34,46 +32,45 @@ class ScreenEntityRenderer(val context: BlockEntityRendererProvider.Context?) :
|
||||
setTextureState(RenderStateShard.TextureStateShard(t, false, false))
|
||||
.createCompositeState(false))
|
||||
}
|
||||
}
|
||||
|
||||
// var renderer: ChestRenderer
|
||||
override fun render(entity: ScreenEntity, partialTick: Float, mat: PoseStack, bufferSource: MultiBufferSource, packedLight: Int, packedOverlay: Int) {
|
||||
var facing = entity.blockState.getValue(ScreenBlock.FACING)
|
||||
|
||||
var nx = if(facing==Direction.EAST) 1F else if (facing==Direction.WEST) -1F else 0F
|
||||
var ny = if(facing==Direction.UP) 1F else if (facing==Direction.DOWN) -1F else 0F
|
||||
var nz = if(facing==Direction.SOUTH) 1F else if (facing==Direction.EAST) -1F else 0F
|
||||
|
||||
val facing = entity.blockState.getValue(ScreenBlock.FACING_HORIZ)
|
||||
val vert = entity.blockState.getValue(ScreenBlock.FACING_VERTI)-1
|
||||
|
||||
mat.pushPose()
|
||||
handleDirection(facing, mat)
|
||||
handleDirection(facing, vert, mat)
|
||||
mat.translate(2 / 16f, 2 / 16f, 0.0001f) // am i epstein or am i just retarded
|
||||
|
||||
// val rendertype = RENDER_TYPE(entity.node.address.toString(), ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, entity.bound))
|
||||
val width = 3/4F
|
||||
val height = 3/4F
|
||||
val bx = 0F
|
||||
val by = 0F
|
||||
|
||||
val rendertype = RENDER_TYPE(ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, entity.bound))
|
||||
val buffer = bufferSource.getBuffer(rendertype)
|
||||
buffer.addVertex(mat.last(), 3 / 4f, 0f, 0f).setUv(1f, 1f)
|
||||
buffer.addVertex(mat.last(), 3 / 4f, 3 / 4f, 0f).setUv(1f, 0f)
|
||||
buffer.addVertex(mat.last(), 0f, 3 / 4f, 0f).setUv(0f, 0f)
|
||||
buffer.addVertex(mat.last(), 0f, 0f, 0f).setUv(0f, 1f)
|
||||
buffer.addVertex(mat.last(), bx+width, by, 0f).setUv(1f, 1f)
|
||||
buffer.addVertex(mat.last(), bx+width, by+height, 0f).setUv(1f, 0f)
|
||||
buffer.addVertex(mat.last(), bx, by+height, 0f).setUv(0f, 0f)
|
||||
buffer.addVertex(mat.last(), bx, by, 0f).setUv(0f, 1f)
|
||||
|
||||
mat.popPose()
|
||||
}
|
||||
|
||||
private fun addCommonSlop(vert: VertexConsumer, entity: ScreenEntity) {
|
||||
// vert.setUv2(15, 15).setColor(255, 255, 255, 255).setNormal()
|
||||
}
|
||||
|
||||
private fun handleDirection(facing: Direction, mat: PoseStack) { // TODO: separate up and down from cardinal directions
|
||||
private fun handleDirection(facing: Direction, vert: Int, mat: PoseStack) { // TODO: separate up and down from cardinal directions
|
||||
// mat.mulPose(Axis.XN.rotationDegrees(vert.toFloat()*90F))
|
||||
// if (vert==0) {
|
||||
// mat.mulPose(Axis.YP.rotationDegrees(90F))
|
||||
// return
|
||||
// }
|
||||
when (facing) {
|
||||
Direction.SOUTH -> { mat.translate(0F, 0F, 1F) }
|
||||
Direction.EAST -> { mat.mulPose(Axis.YP.rotationDegrees(90F)); mat.translate(-1F, 0F, 1F) }
|
||||
Direction.WEST -> { mat.mulPose(Axis.YN.rotationDegrees(90F)); }
|
||||
Direction.NORTH -> {mat.mulPose(Axis.YP.rotationDegrees(180F)); mat.translate(-1F, 0F, 0F) }
|
||||
Direction.UP -> { mat.mulPose(Axis.XN.rotationDegrees(90F)); mat.mulPose(Axis.ZP.rotationDegrees(180F)); mat.translate(-1F, 0F, 1F) } // idek
|
||||
Direction.DOWN -> { mat.mulPose(Axis.XP.rotationDegrees(90F)); mat.mulPose(Axis.ZN.rotationDegrees(180F)); mat.translate(-1F, -1F, 0F) }
|
||||
else -> {}
|
||||
// Direction.UP -> { mat.mulPose(Axis.XN.rotationDegrees(90F)); mat.mulPose(Axis.ZP.rotationDegrees(180F)); mat.translate(-1F, 0F, 1F) } // idek
|
||||
// Direction.DOWN -> { mat.mulPose(Axis.XP.rotationDegrees(90F)); mat.mulPose(Axis.ZN.rotationDegrees(180F)); mat.translate(-1F, -1F, 0F) }
|
||||
}
|
||||
mat.mulPose(Axis.XN.rotationDegrees(vert*90F))
|
||||
mat.translate(0F, if (vert==-1) -1F else 0F, if (vert==1) 1F else 0F)
|
||||
}
|
||||
}
|
||||
// private fun handleDirection(ent: ScreenEntity, mat: PoseStack?) {
|
||||
// `when`(ent.getBlockState().get)
|
||||
// }
|
||||
}
|
||||
@@ -23,10 +23,6 @@ import java.util.Optional
|
||||
class CaseScreen : GenericContainerScreen<CaseMenu> {
|
||||
private val PCB: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/computer.png")
|
||||
private val BTN: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/button_power.png")
|
||||
// private val BTN_ENABLED: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/button/power/enabled.png") // gonna do this later
|
||||
// private val BTN_DISABLED: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/button/power/disabled.png")
|
||||
// private val BTN_ENABLED_HOVER: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/button/power/enabled_hover.png")
|
||||
// private val BTN_DISABLED_HOVER: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/power/disabled_hover.png")
|
||||
|
||||
private var btn: ImagerButton? = null
|
||||
override fun shouldCenterTitle(): Boolean = false
|
||||
|
||||
@@ -1,27 +1,57 @@
|
||||
{
|
||||
"variants": {
|
||||
"facing=north": {
|
||||
"facing_horiz=north,facing_verti=1": {
|
||||
"model": "neocomputers:block/screen"
|
||||
},
|
||||
"facing=east": {
|
||||
"facing_horiz=east,facing_verti=1": {
|
||||
"model": "neocomputers:block/screen",
|
||||
"y": 90
|
||||
},
|
||||
"facing=west": {
|
||||
"facing_horiz=west,facing_verti=1": {
|
||||
"model": "neocomputers:block/screen",
|
||||
"y": -90
|
||||
},
|
||||
"facing=south": {
|
||||
"facing_horiz=south,facing_verti=1": {
|
||||
"model": "neocomputers:block/screen",
|
||||
"y": 180
|
||||
},
|
||||
"facing=up": {
|
||||
"facing_horiz=north,facing_verti=0": {
|
||||
"model": "neocomputers:block/screen",
|
||||
"x": 90
|
||||
},
|
||||
"facing_horiz=east,facing_verti=0": {
|
||||
"model": "neocomputers:block/screen",
|
||||
"x": 90,
|
||||
"y": 90
|
||||
},
|
||||
"facing_horiz=west,facing_verti=0": {
|
||||
"model": "neocomputers:block/screen",
|
||||
"x": 90,
|
||||
"y": -90
|
||||
},
|
||||
"facing_horiz=south,facing_verti=0": {
|
||||
"model": "neocomputers:block/screen",
|
||||
"x": 90,
|
||||
"y": 180
|
||||
},
|
||||
"facing_horiz=north,facing_verti=2": {
|
||||
"model": "neocomputers:block/screen",
|
||||
"x": -90
|
||||
},
|
||||
"facing=down": {
|
||||
"facing_horiz=east,facing_verti=2": {
|
||||
"model": "neocomputers:block/screen",
|
||||
"x": 90
|
||||
"x": -90,
|
||||
"y": 90
|
||||
},
|
||||
"facing_horiz=west,facing_verti=2": {
|
||||
"model": "neocomputers:block/screen",
|
||||
"x": -90,
|
||||
"y": -90
|
||||
},
|
||||
"facing_horiz=south,facing_verti=2": {
|
||||
"model": "neocomputers:block/screen",
|
||||
"x": -90,
|
||||
"y": 180
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 634 B After Width: | Height: | Size: 4.6 KiB |
Reference in New Issue
Block a user