Skip to content

Commit 2187197

Browse files
Merge pull request #239 from ValkyrienSkies/1.20.1/main
update renderslop
2 parents b329f24 + 854ae67 commit 2187197

File tree

13 files changed

+190
-77
lines changed

13 files changed

+190
-77
lines changed

common/src/main/kotlin/org/valkyrienskies/clockwork/ClockworkMod.kt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
11
package org.valkyrienskies.clockwork
22

3-
import com.mojang.blaze3d.platform.InputConstants
43
import com.mojang.brigadier.builder.LiteralArgumentBuilder
54
import com.mojang.logging.LogUtils
6-
import com.simibubi.create.AllBlocks
7-
import com.simibubi.create.content.decoration.encasing.EncasingRegistry
85
import com.simibubi.create.foundation.data.CreateRegistrate
96
import com.simibubi.create.foundation.item.ItemDescription
107
import com.simibubi.create.foundation.item.TooltipModifier
118
import dev.architectury.event.events.common.CommandRegistrationEvent
129
import dev.architectury.event.events.common.InteractionEvent
1310
import dev.architectury.event.events.common.LifecycleEvent
1411
import dev.architectury.event.events.common.TickEvent
12+
import dev.architectury.platform.Platform
1513
import dev.architectury.registry.CreativeTabRegistry
1614
import dev.architectury.registry.registries.DeferredRegister
1715
import dev.architectury.registry.registries.RegistrySupplier
1816
import net.createmod.catnip.lang.FontHelper
19-
import net.minecraft.client.KeyMapping
2017
import net.minecraft.commands.CommandSourceStack
2118
import net.minecraft.core.registries.Registries
2219
import net.minecraft.network.chat.Component
23-
import net.minecraft.network.chat.OutgoingChatMessage
2420
import net.minecraft.resources.ResourceKey
2521
import net.minecraft.resources.ResourceLocation
2622
import net.minecraft.world.item.CreativeModeTab
2723
import net.minecraft.world.item.ItemStack
28-
import net.minecraft.world.item.crafting.RecipeSerializer
29-
import net.minecraft.world.item.crafting.RecipeType
3024
import org.slf4j.LoggerFactory
3125
import org.valkyrienskies.clockwork.client.render.airpocket.AirpocketRenderer
3226
import org.valkyrienskies.clockwork.content.contraptions.flap.dual_link.DualLinkHandler
33-
import org.valkyrienskies.clockwork.content.contraptions.propeller.blades.item.CraftingTableBladeRecipe
3427
import org.valkyrienskies.clockwork.content.events.CollisionSoundEffectHandler
3528
import org.valkyrienskies.clockwork.content.forces.*
3629
import org.valkyrienskies.clockwork.content.forces.contraption.BearingController
3730
import org.valkyrienskies.clockwork.content.physicalities.gyro.GyroShipControl
31+
import org.valkyrienskies.clockwork.integration.cc.GenericPeripheralsCommon
3832
import org.valkyrienskies.clockwork.util.ClockworkUtils
3933
import org.valkyrienskies.clockwork.util.builder.ClockworkExpandedCreateRegistrate
4034
import org.valkyrienskies.clockwork.util.gui.DuctStats
@@ -46,11 +40,8 @@ import org.valkyrienskies.kelvin.impl.DuctNetworkServer
4640
import org.valkyrienskies.kelvin.impl.registry.GasTypeRegistry
4741
import org.valkyrienskies.mod.api.dimensionId
4842
import org.valkyrienskies.mod.api.vsApi
49-
import org.valkyrienskies.mod.common.ValkyrienSkiesMod
50-
import org.valkyrienskies.mod.common.hooks.VSGameEvents
5143
import org.valkyrienskies.mod.common.shipObjectWorld
5244
import org.valkyrienskies.mod.common.vsCore
53-
import org.valkyrienskies.mod.event.RegistryEvents
5445
import java.util.concurrent.ConcurrentLinkedQueue
5546
import kotlin.math.roundToInt
5647

@@ -154,7 +145,6 @@ object ClockworkMod {
154145
ClockworkAugmentations.registerSumAugmentation("sealed", it.shipObjectWorld)
155146
}
156147

157-
158148
TickEvent.SERVER_LEVEL_POST.register {
159149
for (ship in it.shipObjectWorld.loadedShips) {
160150
//TODO: UNCOMMENT WHEN POCKET FORCES IS FIXED
@@ -201,6 +191,10 @@ object ClockworkMod {
201191
}
202192
physTickOnce.addAll(temp)
203193
}
194+
195+
if (Platform.isModLoaded("computercraft")) {
196+
GenericPeripheralsCommon.register()
197+
}
204198
}
205199

206200
@JvmStatic

common/src/main/kotlin/org/valkyrienskies/clockwork/content/contraptions/phys/bearing/PhysBearingAssembler.kt

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,81 @@ package org.valkyrienskies.clockwork.content.contraptions.phys.bearing
33
import net.minecraft.core.BlockPos
44
import net.minecraft.nbt.CompoundTag
55
import net.minecraft.server.level.ServerLevel
6-
import net.minecraft.world.level.Level
76
import net.minecraft.world.level.block.Block
87
import net.minecraft.world.level.block.Blocks
98
import net.minecraft.world.ticks.ScheduledTick
9+
import org.joml.Vector3d
10+
import org.joml.Vector3dc
11+
import org.valkyrienskies.core.api.ships.ServerShip
1012
import org.valkyrienskies.core.util.datastructures.DenseBlockPosSet
13+
import org.valkyrienskies.mod.common.assembly.ICopyableBlock
14+
import org.valkyrienskies.mod.common.assembly.ShipAssembler
15+
import org.valkyrienskies.mod.common.assembly.VSAssemblyEvents
1116
import org.valkyrienskies.mod.common.inAssemblyBlacklist
1217
import org.valkyrienskies.mod.common.util.toBlockPos
18+
import org.valkyrienskies.mod.common.util.toJOMLD
1319

14-
//TODO this is dumb but i'm not going to use ShipAssembler cuz it sucks
15-
//Why does it suck? Mainly this because of this (https://github.com/ValkyrienSkies/Valkyrien-Skies-2/blob/93cc755c6325585ddf3fd90cfd414e8293474ecc/common/src/main/kotlin/org/valkyrienskies/mod/common/assembly/ShipAssembler.kt#L84)
16-
// it gets worldspace position of the new ship, then transforms it back to shipspace, why???????????????????????
17-
// doing some math to calculate center is simple and can be easily calculated outside of the function when you need it (and you do need it)
18-
// you can't get the center pos without knowing what value positionInShip has
20+
//TODO should be in ShipAssembler itself
1921
object PhysBearingAssembler {
20-
2122
@JvmStatic
22-
fun copyBlock(level: Level, from: BlockPos, to: BlockPos) {
23+
fun copyBlock(level: ServerLevel, from: BlockPos, to: BlockPos, originShip: ServerShip?, toShip: ServerShip?, centerPositions: Pair<Vector3dc, Vector3dc>) {
2324
val state = level.getBlockState(from)
24-
val blockentity = level.getBlockEntity(from)
25+
val block = state.block
26+
val be = level.getBlockEntity(from)
27+
28+
var tag = (if (block is ICopyableBlock) block.onCopy(level, from, state, be,
29+
mutableListOf<ServerShip>().also { if (originShip != null) it.add(originShip) }.also { if (toShip != null) it.add(toShip) },
30+
ShipAssembler.SingleItemMap(originShip?.id ?: -1L, centerPositions.first.get(Vector3d()), Vector3d()) //return actual center position only for origin ship
31+
) else null) ?: be?.saveWithId()
2532
level.getChunk(to).setBlockState(to, state, false)
33+
tag = (if (block is ICopyableBlock) block.onPaste(level, to, state,
34+
ShipAssembler.SingleItemMap(originShip?.id ?: -1L, toShip?.id ?: -1L, -1L) {it}, // return actual change (originShip -> toShip), otherwise identity
35+
ShipAssembler.SingleItemMap(originShip?.id ?: -1L, Vector3d(centerPositions.first) to Vector3d(centerPositions.second), Vector3d() to Vector3d()),
36+
tag
37+
) else tag) ?: tag
2638

2739
// Transfer pending schedule-ticks
2840
if (level.blockTicks.hasScheduledTick(from, state.block)) {
2941
level.blockTicks.schedule(ScheduledTick<Block?>(state.block, to, 0, 0))
3042
}
3143

3244
// Transfer block-entity data
33-
if (state.hasBlockEntity() && blockentity != null) {
34-
val data: CompoundTag = blockentity.saveWithId()
35-
level.setBlockEntity(blockentity)
45+
if (state.hasBlockEntity() && be != null && tag != null) {
3646
val newBlockentity = level.getBlockEntity(to)
37-
newBlockentity?.load(data)
47+
newBlockentity?.load(tag)
3848
}
3949
}
4050

4151
@JvmStatic
42-
fun moveBlocksFromTo(level: ServerLevel, blocks: DenseBlockPosSet, removeOriginal: Boolean, originCenter: BlockPos, toCenter: BlockPos): Boolean {
43-
val blocks = blocks.filter { !(level.getBlockState(it.toBlockPos()).inAssemblyBlacklist()) }.map {it.toBlockPos()}
52+
fun moveBlocksFromTo(level: ServerLevel, blocks: DenseBlockPosSet, removeOriginal: Boolean, originCenter: BlockPos, toCenter: BlockPos, originShip: ServerShip?, toShip: ServerShip?): Boolean {
53+
val blocks = blocks.filter { level.getBlockState(it.toBlockPos()).let{!it.isAir && !it.inAssemblyBlacklist()} }.map {it.toBlockPos()}
54+
if (blocks.isEmpty()) return false
4455
for (itPos in blocks) {
4556
val relative: BlockPos = itPos.subtract(BlockPos(originCenter.x, originCenter.y, originCenter.z))
4657
val shipPos: BlockPos = toCenter.offset(relative)
4758
if (!level.getBlockState(shipPos).isAir) {return false}
4859
}
4960

61+
val eventData = mutableMapOf<String, CompoundTag>()
62+
63+
val (minB, maxB) = ShipAssembler.findMinAndMax(blocks)
64+
val oldMin = minB.toJOMLD()
65+
val oldMax = maxB.toJOMLD()
66+
val oldCenter = originCenter.toJOMLD()
67+
val newCenter = toCenter.toJOMLD()
68+
69+
VSAssemblyEvents.beforeCopy.emit(VSAssemblyEvents.BeforeCopy(level, oldMin, oldMax, originCenter.toJOMLD(), originShip, blocks.toSet(), eventData))
70+
//TODO
71+
// VSAssemblyEvents.onPasteBeforeBlocksAreLoaded.emit(VSAssemblyEvents.OnPasteBeforeBlocksAreLoaded(level, originShip, toShip, oldCenter to newCenter, eventData))
72+
5073
for (itPos in blocks) {
5174
val relative: BlockPos = itPos.subtract(BlockPos(originCenter.x, originCenter.y, originCenter.z))
5275
val shipPos: BlockPos = toCenter.offset(relative)
53-
copyBlock(level, itPos, shipPos)
76+
copyBlock(level, itPos, shipPos, originShip, toShip, originCenter.toJOMLD() to toCenter.toJOMLD())
5477
}
5578

5679
if (removeOriginal) {
5780
for (itPos in blocks) {
58-
//AssemblyUtil.removeBlock has isMoving set to false which updates blocks on removal
5981
level.removeBlockEntity(itPos)
6082
level.getChunk(itPos).setBlockState(itPos, Blocks.AIR.defaultBlockState(), true)
6183
}
@@ -67,6 +89,8 @@ object PhysBearingAssembler {
6789
level.chunkSource.blockChanged(shipPos)
6890
}
6991

92+
// VSAssemblyEvents.onPasteAfterBlocksAreLoaded.emit(VSAssemblyEvents.OnPasteAfterBlocksAreLoaded(level, originShip, toShip, oldCenter to newCenter, eventData))
93+
7094
return true
7195
}
7296
}

common/src/main/kotlin/org/valkyrienskies/clockwork/content/contraptions/phys/bearing/PhysBearingBlock.kt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import com.simibubi.create.content.contraptions.bearing.BearingBlock
55
import com.simibubi.create.foundation.block.IBE
66
import net.minecraft.core.BlockPos
77
import net.minecraft.core.Direction
8+
import net.minecraft.nbt.CompoundTag
9+
import net.minecraft.server.level.ServerLevel
810
import net.minecraft.world.InteractionHand
911
import net.minecraft.world.InteractionResult
1012
import net.minecraft.world.entity.player.Player
@@ -13,16 +15,44 @@ import net.minecraft.world.level.BlockGetter
1315
import net.minecraft.world.level.Level
1416
import net.minecraft.world.level.LevelReader
1517
import net.minecraft.world.level.block.Block
18+
import net.minecraft.world.level.block.entity.BlockEntity
1619
import net.minecraft.world.level.block.entity.BlockEntityType
1720
import net.minecraft.world.level.block.state.BlockState
1821
import net.minecraft.world.phys.BlockHitResult
1922
import net.minecraft.world.phys.shapes.CollisionContext
2023
import net.minecraft.world.phys.shapes.VoxelShape
24+
import org.joml.Vector3d
25+
import org.joml.Vector3dc
2126
import org.valkyrienskies.clockwork.ClockworkBlockEntities
2227
import org.valkyrienskies.clockwork.ClockworkConfig
28+
import org.valkyrienskies.clockwork.util.ClockworkConstants
29+
import org.valkyrienskies.clockwork.util.ClockworkUtils.getVector3d
30+
import org.valkyrienskies.core.api.ships.ServerShip
31+
import org.valkyrienskies.mod.common.assembly.ICopyableBlock
32+
import org.valkyrienskies.mod.util.putVector3d
2333
import java.util.function.Consumer
2434

25-
class PhysBearingBlock(properties: Properties) : BearingBlock(properties), IBE<PhysBearingBlockEntity> {
35+
class PhysBearingBlock(properties: Properties) : BearingBlock(properties), IBE<PhysBearingBlockEntity>, ICopyableBlock {
36+
override fun onCopy(level: ServerLevel, pos: BlockPos, state: BlockState, be: BlockEntity?, shipsBeingCopied: List<ServerShip>, centerPositions: Map<Long, Vector3dc>): CompoundTag? = null
37+
override fun onPaste(
38+
level: ServerLevel,
39+
pos: BlockPos,
40+
state: BlockState,
41+
oldShipIdToNewId: Map<Long, Long>,
42+
centerPositions: Map<Long, Pair<Vector3dc, Vector3dc>>,
43+
tag: CompoundTag?
44+
): CompoundTag? {
45+
val tag = tag ?: return null
46+
47+
if (!tag.contains(ClockworkConstants.Nbt.SHIPTRAPTION_ID)) return tag
48+
val oldShiptraptionCenter = tag.getVector3d(ClockworkConstants.Nbt.NEW_SHIPTRAPTION_CENTER) ?: return tag
49+
val oldId = tag.getLong(ClockworkConstants.Nbt.SHIPTRAPTION_ID)
50+
tag.putLong(ClockworkConstants.Nbt.SHIPTRAPTION_ID, oldShipIdToNewId[oldId] ?: -1)
51+
val (oldCenter, newCenter) = centerPositions[oldId] ?: (Vector3d() to Vector3d())
52+
tag.putVector3d(ClockworkConstants.Nbt.NEW_SHIPTRAPTION_CENTER, oldShiptraptionCenter.sub(oldCenter).add(newCenter))
53+
return tag
54+
}
55+
2656
override fun use(state: BlockState, worldIn: Level, pos: BlockPos, player: Player, handIn: InteractionHand, hit: BlockHitResult): InteractionResult {
2757
if (!player.mayBuild()) return InteractionResult.FAIL
2858
if (player.isShiftKeyDown) return InteractionResult.FAIL

common/src/main/kotlin/org/valkyrienskies/clockwork/content/contraptions/phys/bearing/PhysBearingBlockEntity.kt

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import net.minecraft.network.chat.Component
2121
import net.minecraft.server.level.ServerLevel
2222
import net.minecraft.util.Mth
2323
import net.minecraft.world.level.ClipContext
24+
import net.minecraft.world.level.block.entity.BlockEntity
2425
import net.minecraft.world.level.block.entity.BlockEntityType
2526
import net.minecraft.world.level.block.state.BlockState
2627
import org.joml.*
@@ -53,13 +54,14 @@ import org.valkyrienskies.core.impl.bodies.properties.BodyTransformFactory
5354
import org.valkyrienskies.core.impl.util.serialization.VSJacksonUtil
5455
import org.valkyrienskies.core.internal.world.VsiPhysLevel
5556
import org.valkyrienskies.core.util.datastructures.DenseBlockPosSet
56-
import org.valkyrienskies.kelvin.util.KelvinExtensions.toDuctNodePos
5757
import org.valkyrienskies.kelvin.util.KelvinExtensions.toMinecraft
5858
import org.valkyrienskies.kelvin.util.KelvinExtensions.toVector3d
5959
import org.valkyrienskies.mod.api.BlockEntityPhysicsListener
6060
import org.valkyrienskies.mod.api.dimensionId
6161
import org.valkyrienskies.mod.common.*
62+
import org.valkyrienskies.mod.common.assembly.ICopyableBlock
6263
import org.valkyrienskies.mod.common.assembly.ShipAssembler.assembleToShip
64+
import org.valkyrienskies.mod.common.assembly.VSAssemblyEvents
6365
import org.valkyrienskies.mod.common.util.SplittingDisablerAttachment
6466
import org.valkyrienskies.mod.common.util.toJOML
6567
import org.valkyrienskies.mod.common.util.toJOMLD
@@ -304,10 +306,6 @@ class PhysBearingBlockEntity(type: BlockEntityType<*>?, pos: BlockPos?, state: B
304306
}
305307

306308
override fun read(tag: CompoundTag, clientPacket: Boolean) {
307-
if (wasMoved) {
308-
super.read(tag, clientPacket)
309-
return
310-
}
311309
val angleBefore = targetAngle
312310
open = tag.getBoolean(ClockworkConstants.Nbt.OPEN)
313311
isRunning = tag.getBoolean(ClockworkConstants.Nbt.RUNNING)
@@ -519,17 +517,23 @@ class PhysBearingBlockEntity(type: BlockEntityType<*>?, pos: BlockPos?, state: B
519517
}
520518
if (selection == null) return
521519

522-
//todo: move to using new assembly from VLib
523-
//val (shiptraption, previousCenterBP, newCenter, _) = PhysBearingAssembler.assembleToShip(level, selection, true, 1.0, true)
524-
//val previousCenter = Vector3d(previousCenterBP)
520+
var centerPositions: Pair<Vector3d, Vector3d> = Pair(Vector3d(), Vector3d())
521+
522+
//TODO this is dumb, but i forgot to make assembly return center positions, oh well
523+
val event = VSAssemblyEvents.onPasteBeforeBlocksAreLoaded.on {
524+
centerPositions = it.centerPosition.first.get(Vector3d()) to it.centerPosition.second.get(Vector3d())
525+
}
525526
val shiptraption = assembleToShip(
526527
level,
527528
selection.toSet().map { it.toMinecraft() }.toSet(), //accursed, unholy, abominable
528529
1.0
529530
)
531+
event.unregister()
532+
533+
val newPos = Vector3d(worldPos).sub(centerPositions.first).add(centerPositions.second)
530534

531535
shiptraptionID = shiptraption.id
532-
Triple(Vector3d(worldPos), shiptraption, direction)
536+
Triple(newPos, shiptraption, direction)
533537
} else {
534538
shiptraptionID = otherShip.id
535539
Triple(otherPos.blockPos.toVector3d() + 0.5 - direction.normal.toJOMLD(), otherShip, otherPos.direction)
@@ -622,7 +626,7 @@ class PhysBearingBlockEntity(type: BlockEntityType<*>?, pos: BlockPos?, state: B
622626
if (!canDisassemble(bearingAxis, subShip, mainShip)) { return }
623627
val direction = originalDirection ?: blockState.getValue(BearingBlock.FACING)
624628
val inMain = worldPosition.relative(direction, 1)
625-
val inSubship = bearingPos.add(bearingAxis, Vector3d())
629+
val inSubship = bearingPos.add(bearingAxis, Vector3d()).let { BlockPos.containing(it.x, it.y, it.z) }
626630

627631
//todo this is stupid
628632
val aabb = subShip.shipAABB!!
@@ -636,7 +640,7 @@ class PhysBearingBlockEntity(type: BlockEntityType<*>?, pos: BlockPos?, state: B
636640
val subCouldSplit = subShip.getAttachment<SplittingDisablerAttachment>()?.let { if (it.canSplit()) { it.disableSplitting(); true } else {false} } ?: false
637641
val mainCouldSplit = mainShip?.getAttachment<SplittingDisablerAttachment>()?.let { if (it.canSplit()) { it.disableSplitting(); true } else {false} } ?: false
638642

639-
val hasMoved = PhysBearingAssembler.moveBlocksFromTo(level, blocks, true, inSubship.toDuctNodePos().toMinecraft(), inMain)
643+
val hasMoved = PhysBearingAssembler.moveBlocksFromTo(level, blocks, true, inSubship, inMain, subShip, mainShip)
640644

641645
if (subCouldSplit) { subShip.getAttachment<SplittingDisablerAttachment>()?.enableSplitting() }
642646
if (mainCouldSplit) { mainShip?.getAttachment<SplittingDisablerAttachment>()?.enableSplitting() }

common/src/main/kotlin/org/valkyrienskies/clockwork/content/logistics/gas/generation/coal_burner/CoalBurnerBlock.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import net.minecraft.world.phys.BlockHitResult
2727
import org.valkyrienskies.clockwork.ClockworkBlockEntities
2828
import org.valkyrienskies.clockwork.util.gui.IHaveDuctStats
2929
import org.valkyrienskies.kelvin.util.INodeBlock
30-
import java.util.*
3130

3231

3332
class CoalBurnerBlock(properties: Properties) : HorizontalDirectionalBlock(properties), INodeBlock, IBE<CoalBurnerBlockEntity>, IHaveDuctStats {
@@ -52,10 +51,14 @@ class CoalBurnerBlock(properties: Properties) : HorizontalDirectionalBlock(prope
5251

5352
if (player.isShiftKeyDown) return InteractionResult.PASS
5453

55-
56-
if (item == ItemStack.EMPTY && !be.storedFuelStack.isEmpty) {
57-
player.setItemInHand(hand, be.storedFuelStack)
58-
be.storedFuelStack = ItemStack.EMPTY
54+
if (item == ItemStack.EMPTY) {
55+
if (!be.remainingItemStack.isEmpty) {
56+
player.setItemInHand(hand, be.remainingItemStack)
57+
be.remainingItemStack = ItemStack.EMPTY
58+
} else if (!be.storedFuelStack.isEmpty) {
59+
player.setItemInHand(hand, be.storedFuelStack)
60+
be.storedFuelStack = ItemStack.EMPTY
61+
}
5962
return InteractionResult.SUCCESS
6063
}
6164
if (FuelRegistry.get(item)>0 && !player.isShiftKeyDown) {

0 commit comments

Comments
 (0)