separate cardinal directions from up and down
This commit is contained in:
@@ -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)
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,30 +33,44 @@ class ScreenEntityRenderer(val context: BlockEntityRendererProvider.Context?) :
|
||||
.createCompositeState(false))
|
||||
}
|
||||
override fun render(entity: ScreenEntity, partialTick: Float, mat: PoseStack, bufferSource: MultiBufferSource, packedLight: Int, packedOverlay: Int) {
|
||||
val facing = entity.blockState.getValue(ScreenBlock.FACING)
|
||||
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 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 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)
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user