Merge branch 'main' of https://gitea.codersquack.nl/NeoFlock/NeoComputers
This commit is contained in:
@@ -11,15 +11,20 @@ import net.minecraft.sounds.SoundSource
|
||||
import net.minecraft.util.RandomSource
|
||||
import net.minecraft.world.Containers
|
||||
import net.minecraft.world.InteractionResult
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.context.BlockPlaceContext
|
||||
import net.minecraft.world.level.BlockGetter
|
||||
import net.minecraft.world.level.Level
|
||||
import net.minecraft.world.level.block.Block
|
||||
import net.minecraft.world.level.block.EntityBlock
|
||||
import net.minecraft.world.level.block.FurnaceBlock
|
||||
import net.minecraft.world.level.block.SoundType
|
||||
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 org.neoflock.neocomputers.NeoComputers
|
||||
import org.neoflock.neocomputers.block.CombustionGeneratorBlock.Companion.COMBUSTGEN_ACTIVE
|
||||
@@ -30,6 +35,7 @@ import org.neoflock.neocomputers.sounds.Sounds
|
||||
|
||||
class CaseBlock() : NodeBlock(Properties.of().sound(SoundType.METAL).lightLevel(CaseBlock::getLuminance)) { // placeholder stuff
|
||||
companion object {
|
||||
val FACING: EnumProperty<Direction> = EnumProperty.create<Direction>("facing", Direction::class.java)
|
||||
val COMPUTER_RUNNING = BooleanProperty.create("running")!!
|
||||
|
||||
fun getLuminance(blockState: BlockState): Int {
|
||||
@@ -37,10 +43,15 @@ class CaseBlock() : NodeBlock(Properties.of().sound(SoundType.METAL).lightLevel(
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
registerDefaultState(stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(COMPUTER_RUNNING, false))
|
||||
}
|
||||
|
||||
override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState) = CaseBlockEntity(blockPos, blockState).initNetworking()
|
||||
|
||||
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block?, BlockState?>) {
|
||||
builder.add(COMPUTER_RUNNING)
|
||||
builder.add(FACING)
|
||||
}
|
||||
|
||||
fun getMachine(level: BlockGetter, blockPos: BlockPos): CaseBlockEntity {
|
||||
@@ -70,6 +81,10 @@ class CaseBlock() : NodeBlock(Properties.of().sound(SoundType.METAL).lightLevel(
|
||||
super.onPlace(blockState, level, blockPos, blockState2, bl)
|
||||
}
|
||||
|
||||
override fun getStateForPlacement(context: BlockPlaceContext): BlockState? {
|
||||
return defaultBlockState().setValue(FACING, context.horizontalDirection.opposite)
|
||||
}
|
||||
|
||||
override fun neighborChanged(
|
||||
blockState: BlockState,
|
||||
level: Level,
|
||||
@@ -94,8 +109,14 @@ class CaseBlock() : NodeBlock(Properties.of().sound(SoundType.METAL).lightLevel(
|
||||
): InteractionResult {
|
||||
if(!level.isClientSide) {
|
||||
val ent = level.getBlockEntity(blockPos, BlockEntities.CASE_ENTITY.get()).get()
|
||||
MenuRegistry.openMenu(player as ServerPlayer, ent)
|
||||
NodeSynchronizer.registerPlayerScreen(player, ent)
|
||||
if(player.isCrouching) {
|
||||
// Quickstat
|
||||
ent.start()
|
||||
} else {
|
||||
// Open menu
|
||||
MenuRegistry.openMenu(player as ServerPlayer, ent)
|
||||
NodeSynchronizer.registerPlayerScreen(player, ent)
|
||||
}
|
||||
}
|
||||
return InteractionResult.SUCCESS
|
||||
}
|
||||
|
||||
@@ -49,11 +49,13 @@ class CaseBlockEntity(blockPos: BlockPos, blockState: BlockState): NodeBlockEnti
|
||||
override fun encodeDownstreamData(packet: FriendlyByteBuf) {
|
||||
super.encodeDownstreamData(packet)
|
||||
packet.writeBoolean(isOn)
|
||||
packet.writeUtf(err ?: "")
|
||||
}
|
||||
|
||||
override fun syncWithUpstream(packet: FriendlyByteBuf) {
|
||||
super.syncWithUpstream(packet)
|
||||
setRunning(packet.readBoolean())
|
||||
err = packet.readUtf().ifEmpty { null }
|
||||
}
|
||||
|
||||
override fun processScreenInteraction(player: ServerPlayer, packet: FriendlyByteBuf) {
|
||||
|
||||
19
src/main/resources/assets/neocomputers/blockstates/case.json
Normal file
19
src/main/resources/assets/neocomputers/blockstates/case.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"variants": {
|
||||
"facing=north": {
|
||||
"model": "neocomputers:block/case"
|
||||
},
|
||||
"facing=east": {
|
||||
"model": "neocomputers:block/case",
|
||||
"y": 90
|
||||
},
|
||||
"facing=west": {
|
||||
"model": "neocomputers:block/case",
|
||||
"y": -90
|
||||
},
|
||||
"facing=south": {
|
||||
"model": "neocomputers:block/case",
|
||||
"y": 180
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"parent": "minecraft:block/cube",
|
||||
"textures": {
|
||||
"up": "neocomputers:block/case_top",
|
||||
"down": "neocomputers:block/case_bottom",
|
||||
"north": "neocomputers:block/case_front",
|
||||
"south": "neocomputers:block/case_back",
|
||||
"east": "neocomputers:block/case_side",
|
||||
"west": "neocomputers:block/case_side",
|
||||
"particle": "neocomputers:block/case_top"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 634 B |
Binary file not shown.
|
After Width: | Height: | Size: 494 B |
Binary file not shown.
|
After Width: | Height: | Size: 634 B |
Binary file not shown.
|
After Width: | Height: | Size: 570 B |
Binary file not shown.
|
After Width: | Height: | Size: 339 B |
Reference in New Issue
Block a user