-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
215 additions
and
1 deletion.
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
31 changes: 31 additions & 0 deletions
31
...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,31 @@ | ||
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; | ||
private static Function<SmartBlockEntity, ? extends AbstractComputerBehaviour> computerFactory; | ||
|
||
@ExpectPlatform | ||
public static AbstractComputerBehaviour behaviour(SmartBlockEntity sbe) { | ||
throw new AssertionError(); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...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,41 @@ | ||
package dev.ithundxr.createnumismatics.compat.computercraft.implementation; | ||
|
||
import com.jozufozu.flywheel.util.NonNullSupplier; | ||
import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; | ||
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity; | ||
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; | ||
import dan200.computercraft.api.peripheral.IPeripheral; | ||
import dev.ithundxr.createnumismatics.compat.computercraft.implementation.peripherals.BrassDepositorPeripheral; | ||
import dev.ithundxr.createnumismatics.content.depositor.BrassDepositorBlockEntity; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.Level; | ||
|
||
public class ComputerBehaviour extends AbstractComputerBehaviour { | ||
|
||
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; | ||
} | ||
|
||
IPeripheral peripheral; | ||
public ComputerBehaviour(SmartBlockEntity te) { | ||
super(te); | ||
this.peripheral = getPeripheralFor(te); | ||
} | ||
|
||
public static IPeripheral getPeripheralFor(SmartBlockEntity be) { | ||
if (be instanceof BrassDepositorBlockEntity scbe) | ||
return new BrassDepositorPeripheral(scbe); | ||
|
||
|
||
throw new IllegalArgumentException("No peripheral available for " + be.getType()); | ||
} | ||
|
||
@Override | ||
public <T> T getPeripheral() { | ||
//noinspection unchecked | ||
return (T) peripheral; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...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,47 @@ | ||
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; | ||
|
||
public class BrassDepositorPeripheral extends SyncedPeripheral<BrassDepositorBlockEntity> { | ||
|
||
public BrassDepositorPeripheral(BrassDepositorBlockEntity blockEntity) { | ||
super(blockEntity); | ||
} | ||
|
||
@LuaFunction(mainThread = true) | ||
public final void setPrice(String coin, int amount) throws LuaException { | ||
blockEntity.setPrice(getCoinFromString(coin), amount); | ||
|
||
} | ||
|
||
@LuaFunction | ||
public final int getPrice(){ | ||
return blockEntity.getTotalPrice(); | ||
} | ||
|
||
@LuaFunction | ||
public final int getTotalPrice(String coin) throws LuaException { | ||
return blockEntity.getPrice(getCoinFromString(coin)); | ||
} | ||
|
||
Coin getCoinFromString(String coin) throws LuaException { | ||
return switch (coin){ | ||
case "spur" -> Coin.SPUR; | ||
case "bevel" -> Coin.BEVEL; | ||
case "sprocket" -> Coin.SPROCKET; | ||
case "cog" -> Coin.COG; | ||
case "crown" -> Coin.CROWN; | ||
case "sun" -> Coin.SUN; | ||
default -> throw new LuaException("incorrect coin name"); | ||
}; | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return "Numismatics_Depositor"; | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
...va/dev/ithundxr/createnumismatics/compat/computercraft/fabric/ComputerCraftProxyImpl.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,29 @@ | ||
package dev.ithundxr.createnumismatics.compat.computercraft.fabric; | ||
|
||
import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; | ||
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity; | ||
import dan200.computercraft.api.peripheral.PeripheralLookup; | ||
import dev.ithundxr.createnumismatics.compat.computercraft.implementation.ComputerBehaviour; | ||
|
||
import java.util.function.Function; | ||
|
||
import static dev.ithundxr.createnumismatics.compat.computercraft.ComputerCraftProxy.fallbackFactory; | ||
import static dev.ithundxr.createnumismatics.compat.computercraft.implementation.ComputerBehaviour.peripheralProvider; | ||
|
||
public class ComputerCraftProxyImpl { | ||
|
||
public static Function<SmartBlockEntity, ? extends AbstractComputerBehaviour> computerFactory; | ||
|
||
public static void registerWithDependency() { | ||
/* Comment if computercraft.implementation is not in the source set */ | ||
computerFactory = ComputerBehaviour::new; | ||
|
||
PeripheralLookup.get().registerFallback((level, blockPos, blockState, blockEntity, direction) -> peripheralProvider(level, blockPos)); | ||
} | ||
|
||
public static AbstractComputerBehaviour behaviour(SmartBlockEntity sbe) { | ||
if (computerFactory == null) | ||
return fallbackFactory.apply(sbe); | ||
return computerFactory.apply(sbe); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
...ava/dev/ithundxr/createnumismatics/compat/computercraft/forge/ComputerCraftProxyImpl.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,25 @@ | ||
package dev.ithundxr.createnumismatics.compat.computercraft.forge; | ||
|
||
import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; | ||
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity; | ||
import dev.ithundxr.createnumismatics.compat.computercraft.implementation.ComputerBehaviour; | ||
|
||
import java.util.function.Function; | ||
|
||
import static dev.ithundxr.createnumismatics.compat.computercraft.ComputerCraftProxy.fallbackFactory; | ||
import static dev.ithundxr.createnumismatics.compat.computercraft.implementation.ComputerBehaviour.peripheralProvider; | ||
|
||
public class ComputerCraftProxyImpl { | ||
|
||
public static Function<SmartBlockEntity, ? extends AbstractComputerBehaviour> computerFactory; | ||
|
||
public static void registerWithDependency() { | ||
/* Comment if computercraft.implementation is not in the source set */ | ||
computerFactory = ComputerBehaviour::new; | ||
} | ||
public static AbstractComputerBehaviour behaviour(SmartBlockEntity sbe) { | ||
if (computerFactory == null) | ||
return fallbackFactory.apply(sbe); | ||
return computerFactory.apply(sbe); | ||
} | ||
} |
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