-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed some of the methods. It might work.
- Loading branch information
1 parent
25854b9
commit b2e1e7c
Showing
18 changed files
with
609 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ing/vs_addition/mixinducks/vs_clockwork/flap_bearing/FlapBearingBlockEntityMixinDuck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.github.xiewuzhiying.vs_addition.mixinducks.vs_clockwork.flap_bearing; | ||
|
||
public interface FlapBearingBlockEntityMixinDuck { | ||
void setLockedFlapAngle(float angle); | ||
float getLockedFlapAngle(); | ||
void setIsLocked(boolean bl); | ||
boolean getIsLocked(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
...b/xiewuzhiying/vs_addition/compats/computercraft/peripheral/CheatFlapBearingPeripheral.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
.../github/xiewuzhiying/vs_addition/fabric/mixin/computercraft/InventoryMethodsAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.github.xiewuzhiying.vs_addition.fabric.mixin.computercraft; | ||
|
||
import dan200.computercraft.api.peripheral.IPeripheral; | ||
import dan200.computercraft.shared.peripheral.generic.methods.InventoryMethods; | ||
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; | ||
import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; | ||
import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage; | ||
import net.minecraft.world.item.ItemStack; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(InventoryMethods.class) | ||
public interface InventoryMethodsAccessor { | ||
@Invoker(value = "moveItem", remap = false) | ||
static int moveItem(SlottedStorage<ItemVariant> from, int fromSlot, SlottedStorage<ItemVariant> to, int toSlot, final int limit) { | ||
throw new AssertionError(); | ||
} | ||
@Invoker(value = "toStack", remap = false) | ||
static ItemStack toStack(SingleSlotStorage<ItemVariant> variant) { | ||
throw new AssertionError(); | ||
} | ||
@Invoker(value = "extractHandler", remap = false) | ||
static SlottedStorage<ItemVariant> extractHandler(IPeripheral peripheral) { | ||
throw new AssertionError(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
.../main/kotlin/io/xiewuzhiying/vs_addition/fabric/compats/computercraft/PeripheralFabric.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.xiewuzhiying.vs_addition.fabric.compats.computercraft | ||
|
||
import dan200.computercraft.api.peripheral.IPeripheral | ||
import io.github.xiewuzhiying.vs_addition.VSAdditionConfig | ||
import io.github.xiewuzhiying.vs_addition.VSAdditionMod | ||
import io.github.xiewuzhiying.vs_addition.compats.computercraft.PeripheralCommon.PeripheralSupplier | ||
import io.github.xiewuzhiying.vs_addition.compats.computercraft.peripheral.CannonMountPeripheral | ||
import io.github.xiewuzhiying.vs_addition.compats.computercraft.peripheral.CheatCannonMountPeripheral | ||
import net.minecraft.core.BlockPos | ||
import net.minecraft.world.level.Level | ||
import net.minecraft.world.level.block.Block | ||
import net.minecraft.world.level.block.entity.BlockEntity | ||
import rbasamoyai.createbigcannons.cannon_control.cannon_mount.CannonMountBlockEntity | ||
import rbasamoyai.createbigcannons.index.CBCBlocks | ||
|
||
object PeripheralFabric { | ||
private val peripheralMap: MutableMap<Block, PeripheralSupplier> = HashMap() | ||
|
||
init { | ||
if (VSAdditionMod.CBC_ACTIVE) { | ||
peripheralMap[CBCBlocks.CANNON_MOUNT.get()] = | ||
PeripheralSupplier { be: BlockEntity, _: Level, _: BlockPos -> | ||
if (VSAdditionConfig.SERVER.computercraft.enableCheatCannonMountPeripheral) { | ||
CheatCannonMountPeripheral( | ||
"cbc_cannon_mount", | ||
be as CannonMountBlockEntity | ||
) | ||
} else { | ||
CannonMountPeripheral( | ||
"cbc_cannon_mount", | ||
be as CannonMountBlockEntity | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun getPeripheralFarbic(level: Level, blockPos: BlockPos): IPeripheral? { | ||
val s = level.getBlockState(blockPos) | ||
val be = level.getBlockEntity(blockPos) | ||
val supplier = peripheralMap[s.block] | ||
return be?.let { supplier?.get(it, level, blockPos) } | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
...vs_addition/fabric/compats/computercraft/peripheral/CannonMountPeripheralWithInventory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package io.xiewuzhiying.vs_addition.fabric.compats.computercraft.peripheral | ||
|
||
import dan200.computercraft.api.detail.VanillaDetailRegistries | ||
import dan200.computercraft.api.lua.LuaException | ||
import dan200.computercraft.api.lua.LuaFunction | ||
import dan200.computercraft.api.peripheral.IComputerAccess | ||
import dan200.computercraft.core.util.ArgumentHelpers | ||
import dan200.computercraft.shared.peripheral.generic.methods.InventoryMethods.StorageWrapper | ||
import io.github.xiewuzhiying.vs_addition.compats.computercraft.peripheral.CannonMountPeripheral | ||
import io.github.xiewuzhiying.vs_addition.fabric.mixin.computercraft.InventoryMethodsAccessor | ||
import rbasamoyai.createbigcannons.cannon_control.cannon_mount.CannonMountBlockEntity | ||
import java.util.* | ||
|
||
class CannonMountPeripheralWithInventory(peripheralType: String, tileEntity: CannonMountBlockEntity, val inventory: StorageWrapper) : CannonMountPeripheral(peripheralType, | ||
tileEntity | ||
){ | ||
@LuaFunction(mainThread = true) | ||
fun size(): Int { | ||
return inventory.storage.slots.size | ||
} | ||
|
||
@LuaFunction(mainThread = true) | ||
fun list(): Map<Int, Map<String, *>> { | ||
val result: MutableMap<Int, Map<String, *>> = HashMap() | ||
val slots = inventory.storage.slots | ||
val size = slots.size | ||
for (i in 0 until size) { | ||
val stack = InventoryMethodsAccessor.toStack(slots[i]) | ||
if (!stack.isEmpty) result[i + 1] = VanillaDetailRegistries.ITEM_STACK.getBasicDetails(stack) | ||
} | ||
|
||
return result | ||
} | ||
|
||
@LuaFunction(mainThread = true) | ||
@Throws(LuaException::class) | ||
fun getItemDetail(slot: Int): Map<String, *>? { | ||
ArgumentHelpers.assertBetween(slot, 1, inventory.storage.slotCount, "Slot out of range (%s)") | ||
|
||
val stack = InventoryMethodsAccessor.toStack(inventory.storage.getSlot(slot - 1)) | ||
return if (stack.isEmpty) null else VanillaDetailRegistries.ITEM_STACK.getDetails(stack) | ||
} | ||
|
||
@LuaFunction(mainThread = true) | ||
@Throws(LuaException::class) | ||
fun getItemLimit(slot: Int): Long { | ||
ArgumentHelpers.assertBetween(slot, 1, inventory.storage.slotCount, "Slot out of range (%s)") | ||
return inventory.storage.getSlot(slot - 1).capacity | ||
} | ||
|
||
@LuaFunction(mainThread = true) | ||
@Throws(LuaException::class) | ||
fun pushItems( | ||
computer: IComputerAccess, | ||
toName: String, fromSlot: Int, limit: Optional<Int>, toSlot: Optional<Int> | ||
): Int { | ||
// Find location to transfer to | ||
val location = computer.getAvailablePeripheral(toName) | ||
?: throw LuaException("Target '$toName' does not exist") | ||
|
||
val to = InventoryMethodsAccessor.extractHandler(location) | ||
?: throw LuaException("Target '$toName' is not an inventory") | ||
|
||
val fromStorage = inventory.storage | ||
|
||
// Validate slots | ||
val actualLimit = limit.orElse(Int.MAX_VALUE) | ||
ArgumentHelpers.assertBetween(fromSlot, 1, fromStorage.slotCount, "From slot out of range (%s)") | ||
if (toSlot.isPresent) ArgumentHelpers.assertBetween(toSlot.get(), 1, to.slots.size, "To slot out of range (%s)") | ||
|
||
if (actualLimit <= 0) return 0 | ||
return InventoryMethodsAccessor.moveItem(fromStorage, fromSlot - 1, to, toSlot.orElse(0) - 1, actualLimit) | ||
} | ||
|
||
@LuaFunction(mainThread = true) | ||
@Throws(LuaException::class) | ||
fun pullItems( | ||
computer: IComputerAccess, | ||
fromName: String, fromSlot: Int, limit: Optional<Int>, toSlot: Optional<Int> | ||
): Int { | ||
// Find location to transfer to | ||
val location = computer.getAvailablePeripheral(fromName) | ||
?: throw LuaException("Source '$fromName' does not exist") | ||
|
||
val toStorage = inventory.storage | ||
|
||
val from = InventoryMethodsAccessor.extractHandler(location) | ||
?: throw LuaException("Source '$fromName' is not an inventory") | ||
|
||
// Validate slots | ||
val actualLimit = limit.orElse(Int.MAX_VALUE) | ||
ArgumentHelpers.assertBetween(fromSlot, 1, from.slots.size, "From slot out of range (%s)") | ||
if (toSlot.isPresent) ArgumentHelpers.assertBetween( | ||
toSlot.get(), | ||
1, | ||
toStorage.slotCount, | ||
"To slot out of range (%s)" | ||
) | ||
|
||
if (actualLimit <= 0) return 0 | ||
return InventoryMethodsAccessor.moveItem(from, fromSlot - 1, toStorage, toSlot.orElse(0) - 1, actualLimit) | ||
} | ||
} |
Oops, something went wrong.