-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Szedann <[email protected]>
- Loading branch information
Showing
19 changed files
with
533 additions
and
4 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
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
47 changes: 47 additions & 0 deletions
47
...src/main/java/dev/ithundxr/createnumismatics/compat/computercraft/ComputerCraftProxy.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,47 @@ | ||
/* | ||
* Numismatics | ||
* Copyright (c) 2024 The Railways Team | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.ithundxr.createnumismatics.compat.computercraft; | ||
|
||
import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; | ||
import com.simibubi.create.compat.computercraft.FallbackComputerBehaviour; | ||
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity; | ||
import dev.architectury.injectables.annotations.ExpectPlatform; | ||
import dev.ithundxr.createnumismatics.compat.Mods; | ||
|
||
import java.util.function.Function; | ||
|
||
public class ComputerCraftProxy { | ||
public static void register() { | ||
fallbackFactory = FallbackComputerBehaviour::new; | ||
Mods.COMPUTERCRAFT.executeIfInstalled(() -> ComputerCraftProxy::registerWithDependency); | ||
} | ||
|
||
@ExpectPlatform | ||
static void registerWithDependency() { | ||
throw new AssertionError(); | ||
} | ||
|
||
public static Function<SmartBlockEntity, ? extends AbstractComputerBehaviour> fallbackFactory; | ||
public static Function<SmartBlockEntity, ? extends AbstractComputerBehaviour> computerFactory; | ||
|
||
@ExpectPlatform | ||
public static AbstractComputerBehaviour behaviour(SmartBlockEntity sbe) { | ||
throw new AssertionError(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...dev/ithundxr/createnumismatics/compat/computercraft/implementation/ComputerBehaviour.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,62 @@ | ||
/* | ||
* Numismatics | ||
* Copyright (c) 2024 The Railways Team | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.ithundxr.createnumismatics.compat.computercraft.implementation; | ||
|
||
import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; | ||
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity; | ||
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; | ||
import com.tterrag.registrate.util.nullness.NonNullSupplier; | ||
import dan200.computercraft.api.peripheral.IPeripheral; | ||
import dev.ithundxr.createnumismatics.compat.computercraft.implementation.peripherals.BrassDepositorPeripheral; | ||
import dev.ithundxr.createnumismatics.compat.computercraft.implementation.peripherals.VendorPeripheral; | ||
import dev.ithundxr.createnumismatics.content.depositor.BrassDepositorBlockEntity; | ||
import dev.ithundxr.createnumismatics.content.vendor.VendorBlockEntity; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.Level; | ||
|
||
public class ComputerBehaviour extends AbstractComputerBehaviour { | ||
NonNullSupplier<IPeripheral> peripheralSupplier; | ||
|
||
public static IPeripheral peripheralProvider(Level level, BlockPos blockPos) { | ||
AbstractComputerBehaviour behavior = BlockEntityBehaviour.get(level, blockPos, AbstractComputerBehaviour.TYPE); | ||
if (behavior instanceof ComputerBehaviour real) | ||
return real.getPeripheral(); | ||
return null; | ||
} | ||
|
||
public ComputerBehaviour(SmartBlockEntity te) { | ||
super(te); | ||
this.peripheralSupplier = getPeripheralFor(te); | ||
} | ||
|
||
public static NonNullSupplier<IPeripheral> getPeripheralFor(SmartBlockEntity be) { | ||
if (be instanceof BrassDepositorBlockEntity scbe) | ||
return () -> new BrassDepositorPeripheral(scbe); | ||
if (be instanceof VendorBlockEntity scbe) | ||
return () -> new VendorPeripheral(scbe); | ||
|
||
throw new IllegalArgumentException("No peripheral available for " + be.getType()); | ||
} | ||
|
||
@Override | ||
public <T> T getPeripheral() { | ||
//noinspection unchecked | ||
return (T) peripheralSupplier.get(); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...numismatics/compat/computercraft/implementation/peripherals/BrassDepositorPeripheral.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,71 @@ | ||
/* | ||
* Numismatics | ||
* Copyright (c) 2024 The Railways Team | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.ithundxr.createnumismatics.compat.computercraft.implementation.peripherals; | ||
|
||
import com.simibubi.create.compat.computercraft.implementation.peripherals.SyncedPeripheral; | ||
import dan200.computercraft.api.lua.LuaException; | ||
import dan200.computercraft.api.lua.LuaFunction; | ||
import dev.ithundxr.createnumismatics.content.backend.Coin; | ||
import dev.ithundxr.createnumismatics.content.depositor.BrassDepositorBlockEntity; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static dev.ithundxr.createnumismatics.content.backend.Coin.getCoinFromName; | ||
import static dev.ithundxr.createnumismatics.content.backend.Coin.getCoinsFromSpurAmount; | ||
|
||
public class BrassDepositorPeripheral extends SyncedPeripheral<BrassDepositorBlockEntity> { | ||
public BrassDepositorPeripheral(BrassDepositorBlockEntity blockEntity) { | ||
super(blockEntity); | ||
} | ||
|
||
@LuaFunction(mainThread = true) | ||
public final void setCoinAmount(String coinName, int amount) throws LuaException { | ||
Coin coin = getCoinFromName(coinName); | ||
if(coin == null) throw new LuaException("incorrect coin name"); | ||
blockEntity.setPrice(coin, amount); | ||
blockEntity.notifyUpdate(); | ||
} | ||
|
||
@LuaFunction(mainThread = true) | ||
public final void setTotalPrice(int spurAmount) { | ||
List<Map.Entry<Coin, Integer>> coins = getCoinsFromSpurAmount(spurAmount); | ||
for (Map.Entry<Coin, Integer> coin : coins) { | ||
blockEntity.setPrice(coin.getKey(), coin.getValue()); | ||
} | ||
blockEntity.notifyUpdate(); | ||
} | ||
|
||
@LuaFunction | ||
public final int getTotalPrice() { | ||
return blockEntity.getTotalPrice(); | ||
} | ||
|
||
@LuaFunction | ||
public final int getPrice(String coinName) throws LuaException { | ||
Coin coin = getCoinFromName(coinName); | ||
if(coin == null) throw new LuaException("incorrect coin name"); | ||
return blockEntity.getPrice(coin); | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return "Numismatics_Depositor"; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...r/createnumismatics/compat/computercraft/implementation/peripherals/VendorPeripheral.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,71 @@ | ||
/* | ||
* Numismatics | ||
* Copyright (c) 2024 The Railways Team | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.ithundxr.createnumismatics.compat.computercraft.implementation.peripherals; | ||
|
||
import com.simibubi.create.compat.computercraft.implementation.peripherals.SyncedPeripheral; | ||
import dan200.computercraft.api.lua.LuaException; | ||
import dan200.computercraft.api.lua.LuaFunction; | ||
import dev.ithundxr.createnumismatics.content.backend.Coin; | ||
import dev.ithundxr.createnumismatics.content.vendor.VendorBlockEntity; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static dev.ithundxr.createnumismatics.content.backend.Coin.getCoinFromName; | ||
import static dev.ithundxr.createnumismatics.content.backend.Coin.getCoinsFromSpurAmount; | ||
|
||
public class VendorPeripheral extends SyncedPeripheral<VendorBlockEntity> { | ||
public VendorPeripheral(VendorBlockEntity blockEntity) { | ||
super(blockEntity); | ||
} | ||
|
||
@LuaFunction(mainThread = true) | ||
public final void setCoinAmount(String coinName, int amount) throws LuaException { | ||
Coin coin = getCoinFromName(coinName); | ||
if(coin == null) throw new LuaException("incorrect coin name"); | ||
blockEntity.setPrice(coin, amount); | ||
blockEntity.notifyUpdate(); | ||
} | ||
|
||
@LuaFunction(mainThread = true) | ||
public final void setTotalPrice(int spurAmount) { | ||
List<Map.Entry<Coin, Integer>> coins = getCoinsFromSpurAmount(spurAmount); | ||
for (Map.Entry<Coin, Integer> coin : coins) { | ||
blockEntity.setPrice(coin.getKey(), coin.getValue()); | ||
} | ||
blockEntity.notifyUpdate(); | ||
} | ||
|
||
@LuaFunction | ||
public final int getTotalPrice() { | ||
return blockEntity.getTotalPrice(); | ||
} | ||
|
||
@LuaFunction | ||
public final int getPrice(String coinName) throws LuaException { | ||
Coin coin = getCoinFromName(coinName); | ||
if(coin == null) throw new LuaException("incorrect coin name"); | ||
return blockEntity.getPrice(coin); | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return "Numismatics_Vendor"; | ||
} | ||
} |
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
Oops, something went wrong.