Skip to content

Commit

Permalink
salepoint peripheral and recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
techno-sam committed Aug 7, 2024
1 parent 9687054 commit e0c6a7c
Show file tree
Hide file tree
Showing 20 changed files with 436 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.1 2024-08-07T20:38:49.196715017 Create: Numismatics/Numismatics' Advancements
// 1.20.1 2024-08-07T23:05:34.25307421 Create: Numismatics/Numismatics' Advancements
4ab84595dc44460d6d89ff3608940dd8694b93d6 data/numismatics/advancements/is_this_legal.json
645c92e6e449889ed4cf617432fd6fa87ffe355b data/numismatics/advancements/questionable_investment.json
8f32fb49ef81058e2e660fac983dbef2f554db38 data/numismatics/advancements/root.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.1 2024-08-07T20:38:49.194454214 Create: Numismatics/Numismatics Standard Recipes
// 1.20.1 2024-08-07T23:05:34.251904854 Create: Numismatics/Numismatics Standard Recipes
0e1680b878cfa51c04809504b3542cb6312027a1 data/numismatics/recipes/crafting/gray_id_card.json
61954216f844eecdbee266da7e517a983993d2f8 data/numismatics/advancements/recipes/misc/crafting/brown_card.json
2c732f9c3bc02a29a4d86a0552f4dbbae986a34a data/numismatics/recipes/crafting/blue_authorized_card.json
Expand Down Expand Up @@ -26,9 +26,10 @@ ce32a3a7c2a5564e84b30bb1b71007ca4adc985d data/numismatics/recipes/crafting/lime_
501f27ee03faeb675a05b63b0c8058f1473f02d5 data/numismatics/advancements/recipes/misc/crafting/purple_id_card.json
8d863132d01d516db98d228e9038425923b7354d data/numismatics/recipes/crafting/black_card.json
78af0a7f17e04133eae7172df3255aaa34034537 data/numismatics/advancements/recipes/misc/crafting/red_id_card.json
86ccf10cd1549f633f99674b002c543bd46aefd0 data/numismatics/recipes/crafting/yellow_card.json
e16d9a5134c226db94bb389c44e55a8b393ca6c4 data/numismatics/recipes/crafting/brass_depositor.json
86ccf10cd1549f633f99674b002c543bd46aefd0 data/numismatics/recipes/crafting/yellow_card.json
1d0c5ff8b555ba922b0699a93dceb4cb9d49c4f9 data/numismatics/advancements/recipes/misc/crafting/lime_card.json
b8f2498c1400a0f96c494cdbd8824b19b8bca742 data/numismatics/advancements/recipes/misc/crafting/salepoint.json
3cfbeee014050f945e5fa2299dbbcfbf120bf29a data/numismatics/recipes/crafting/red_authorized_card.json
6d90141ba018612413149776136ccb11b26add7c data/numismatics/advancements/recipes/misc/crafting/light_gray_authorized_card.json
8ae4c3c323f9b8ea0261f5e0d1fb9f7c15e9cf6b data/numismatics/recipes/crafting/light_gray_card.json
Expand Down Expand Up @@ -61,8 +62,8 @@ b33377448ad6812c10b1405051359e58172299e9 data/numismatics/advancements/recipes/m
ea20b56eaa5e6c8af48b7b8c3c33cd15c0107bc1 data/numismatics/advancements/recipes/misc/crafting/gray_authorized_card.json
d7a7609aa109440f0f47b8ba7c598d9f7a667734 data/numismatics/advancements/recipes/misc/crafting/blue_id_card.json
4ef1874d44a47c50706505c00f866b9ecb6d860d data/numismatics/recipes/crafting/purple_authorized_card.json
dccd117562bb9bf28890aa0aa53273b4587504ee data/numismatics/recipes/crafting/white_card.json
cee2975b897e1c1216e301ad69dea85258902546 data/numismatics/advancements/recipes/misc/crafting/black_id_card.json
dccd117562bb9bf28890aa0aa53273b4587504ee data/numismatics/recipes/crafting/white_card.json
6ed249679ea9168906e4e00a7c6f85f432f9cd16 data/numismatics/advancements/recipes/misc/crafting/orange_authorized_card.json
20434910bb6e5fa2e8350f52b30c728b091a85d3 data/numismatics/recipes/crafting/brown_card.json
24bb0a27737622bbc1dfce601b0030372f0b6bcf data/numismatics/recipes/crafting/black_authorized_card.json
Expand All @@ -84,6 +85,7 @@ b359f00206e8522f61fa06cc6bda43142f180e30 data/numismatics/recipes/crafting/lime_
8ede57d6fa0fb30cc5edf0eb842844071f8c2026 data/numismatics/advancements/recipes/misc/crafting/green_authorized_card.json
cded917dee4ac35f9499992f6e0767a8638a5113 data/numismatics/recipes/crafting/orange_authorized_card.json
fca73628e0fc837c1e8f06f0f63d4b8983651d83 data/numismatics/advancements/recipes/misc/crafting/yellow_id_card.json
3f5ad3c091647c23017b749dc54becf6042562ab data/numismatics/recipes/crafting/salepoint.json
0d9dc5041578195c578860f7af550cae670b1016 data/numismatics/advancements/recipes/misc/crafting/cyan_authorized_card.json
d8a8bdef01cc07e8902c89c247da5b53c6b3cda8 data/numismatics/advancements/recipes/misc/crafting/yellow_card.json
ba04c62863e2c847ad7ac240e282c3f6ecd85d62 data/numismatics/recipes/crafting/banking_guide.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.1 2024-08-07T20:38:49.189381552 Create: Numismatics/Numismatics EMI excluded tags
// 1.20.1 2024-08-07T23:05:34.248846149 Create: Numismatics/Numismatics EMI excluded tags
b57edab6f7e7a6e1b1211daa4c3b217ffd09ce62 assets/emi/tag/exclusions/numismatics.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// 1.20.1 2024-08-07T20:38:49.19624371 Create: Numismatics/Numismatics' Sequenced Assembly Recipes
// 1.20.1 2024-08-07T23:05:34.252881766 Create: Numismatics/Numismatics' Sequenced Assembly Recipes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.1 2024-08-07T20:38:49.191281686 Create: Numismatics/Registrate Provider for numismatics [Recipes, Advancements, Loot Tables, Tags (blocks), Tags (items), Tags (fluids), Tags (entity_types), Blockstates, Item models, Lang (en_us/en_ud)]
// 1.20.1 2024-08-07T23:05:34.250006007 Create: Numismatics/Registrate Provider for numismatics [Recipes, Advancements, Loot Tables, Tags (blocks), Tags (items), Tags (fluids), Tags (entity_types), Blockstates, Item models, Lang (en_us/en_ud)]
2f1dad2a2e0086d54cf4b88378feacc04341d87f data/numismatics/tags/items/internal/ingots/iron_ingots.json
dc5c60bbbaf3a5d7bc1f9bc0c9377757dbd8de49 data/numismatics/loot_tables/blocks/bank_terminal.json
5b0244502972f49d063d98fa0cb3f6fc65af82b2 data/numismatics/tags/items/internal/string.json
Expand Down Expand Up @@ -55,9 +55,9 @@ bde18ccd9c21484154597c6271750c0406082f61 data/c/tags/blocks/relocation_not_suppo
d048d04208faa63f0014d614d6026a66fe118c11 data/numismatics/loot_tables/blocks/brass_depositor.json
790ff3c5da6a67a5de1ceb7138fa3e1c0fe97f80 data/numismatics/tags/items/internal/dyes/lime_dyes.json
a8cb82f19034a0e724e12df45c883e9cd469c210 assets/numismatics/models/item/green_card.json
e1087e56db7b4d8812ab4617344f0ac8b0f0e6c7 assets/numismatics/models/item/light_gray_authorized_card.json
390db78c5393fca4f90018df51d1a79d11a64f72 assets/numismatics/models/item/light_blue_authorized_card.json
c09892d2d189f147997d77f4ce39b0570729f030 assets/numismatics/models/item/lime_authorized_card.json
e1087e56db7b4d8812ab4617344f0ac8b0f0e6c7 assets/numismatics/models/item/light_gray_authorized_card.json
06ecd28cd97f4e8200dc396858695cad57b871c8 assets/numismatics/blockstates/blaze_banker.json
95ef415a564eba1d212053195d25b199427b94e3 assets/numismatics/blockstates/creative_vendor.json
9fdcd12c871f136e66973a8c02be94a675a4b727 data/numismatics/tags/items/internal/dyes/yellow_dyes.json
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_item": {
"conditions": {
"items": [
{
"items": [
"numismatics:vendor"
]
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "numismatics:crafting///salepoint"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_item",
"has_the_recipe"
]
],
"rewards": {
"recipes": [
"numismatics:crafting///salepoint"
]
},
"sends_telemetry_event": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"key": {
"@": {
"item": "create:precision_mechanism"
},
"I": {
"item": "create:electron_tube"
},
"p": {
"item": "create:placard"
},
"v": {
"item": "numismatics:vendor"
}
},
"pattern": [
" p ",
"IvI",
" @ "
],
"result": {
"item": "numismatics:salepoint"
},
"show_notification": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import dev.ithundxr.createnumismatics.Numismatics;
import dev.ithundxr.createnumismatics.content.backend.Coin;
import dev.ithundxr.createnumismatics.multiloader.CommonTags;
import dev.ithundxr.createnumismatics.registry.NumismaticsBlocks;
import dev.ithundxr.createnumismatics.registry.NumismaticsItems;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.PackOutput;
Expand Down Expand Up @@ -181,5 +182,13 @@ public static ItemLike paper() {
public static ItemLike framedGlass() {
return AllPaletteBlocks.FRAMED_GLASS;
}

public static ItemLike vendor() {
return NumismaticsBlocks.VENDOR.get();
}

public static ItemLike placard() {
return AllBlocks.PLACARD.get();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ public class NumismaticsStandardRecipeGen extends NumismaticsRecipeProvider {
.define('#', Ingredients.brassCasing())
.define('I', Ingredients.electronTube()));

GeneratedRecipe SALEPOINT = create(NumismaticsBlocks.SALEPOINT)
.unlockedBy(Ingredients::vendor)
.viaShaped(b -> b
.pattern(" p ")
.pattern("IvI")
.pattern(" @ ")
.define('p', Ingredients.placard())
.define('I', Ingredients.electronTube())
.define('v', Ingredients.vendor())
.define('@', Ingredients.precisionMechanism()));

DyedRecipeList CARDS = new DyedRecipeList(color -> create(NumismaticsItems.CARDS.get(color))
.unlockedBy(Ingredients::precisionMechanism)
.viaShaped(b -> b
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
import dev.architectury.injectables.annotations.ExpectPlatform;
import dev.ithundxr.createnumismatics.compat.Mods;
import dev.ithundxr.createnumismatics.compat.computercraft.implementation.Details;
import dev.ithundxr.createnumismatics.multiloader.fluid.MultiloaderFluidStack;
import net.minecraft.world.item.ItemStack;

import java.util.Map;
import java.util.function.Function;

public class ComputerCraftProxy {
Expand All @@ -44,4 +48,14 @@ static void registerWithDependency() {
public static AbstractComputerBehaviour behaviour(SmartBlockEntity sbe) {
throw new AssertionError();
}

public static Map<String, Object> getItemDetail(ItemStack stack) {
return Mods.COMPUTERCRAFT.runIfInstalled(() -> () -> Details.getItemDetail(stack))
.orElse(Map.of());
}

public static Map<String, Object> getFluidDetail(MultiloaderFluidStack stack) {
return Mods.COMPUTERCRAFT.runIfInstalled(() -> () -> Details.getFluidDetail(stack))
.orElse(Map.of());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
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.compat.computercraft.implementation.peripherals.SalepointPeripheral;
import dev.ithundxr.createnumismatics.compat.computercraft.implementation.peripherals.VendorPeripheral;
import dev.ithundxr.createnumismatics.content.depositor.BrassDepositorBlockEntity;
import dev.ithundxr.createnumismatics.content.salepoint.SalepointBlockEntity;
import dev.ithundxr.createnumismatics.content.vendor.VendorBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
Expand All @@ -51,6 +53,8 @@ public static Supplier<IPeripheral> getPeripheralFor(SmartBlockEntity be) {
return () -> new BrassDepositorPeripheral(scbe);
if (be instanceof VendorBlockEntity scbe)
return () -> new VendorPeripheral(scbe);
if (be instanceof SalepointBlockEntity sbe)
return () -> new SalepointPeripheral(sbe);

throw new IllegalArgumentException("No peripheral available for " + be.getType());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package dev.ithundxr.createnumismatics.compat.computercraft.implementation;

import dev.architectury.injectables.annotations.ExpectPlatform;
import dev.ithundxr.createnumismatics.multiloader.fluid.MultiloaderFluidStack;
import net.minecraft.world.item.ItemStack;

import java.util.Map;

public class Details {
@ExpectPlatform
public static Map<String, Object> getItemDetail(ItemStack stack) {
throw new AssertionError();
}

@ExpectPlatform
public static Map<String, Object> getFluidDetail(MultiloaderFluidStack stack) {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* 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 Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 com.simibubi.create.foundation.utility.Components;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.lua.LuaFunction;
import dev.ithundxr.createnumismatics.Numismatics;
import dev.ithundxr.createnumismatics.content.backend.*;
import dev.ithundxr.createnumismatics.content.backend.sub_authorization.Authorization;
import dev.ithundxr.createnumismatics.content.backend.sub_authorization.SubAccount;
import dev.ithundxr.createnumismatics.content.salepoint.SalepointBlockEntity;
import dev.ithundxr.createnumismatics.content.salepoint.Transaction;
import dev.ithundxr.createnumismatics.content.salepoint.states.ISalepointState;
import net.minecraft.network.chat.Component;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import static dev.ithundxr.createnumismatics.content.backend.Coin.getCoinFromName;
import static dev.ithundxr.createnumismatics.content.backend.Coin.getCoinsFromSpurAmount;

public class SalepointPeripheral extends SyncedPeripheral<SalepointBlockEntity> {
public SalepointPeripheral(SalepointBlockEntity 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);
}

@LuaFunction
public final Map<String, Object> getSaleObject() throws LuaException {
ISalepointState<?> state = blockEntity.getSalepointState();
if (state == null)
throw new LuaException("Salepoint is not initialized");
return state.writeForComputerCraft();
}

@LuaFunction(mainThread = true)
public final Map<String, Object> getTransaction() throws LuaException {
Transaction<?> transaction = blockEntity.getTransaction();
if (transaction == null)
throw new LuaException("No transaction is currently active");
return Map.of(
"object", blockEntity.getSalepointState().writeForComputerCraft(),
"totalPrice", transaction.totalPrice(),
"targetCount", transaction.multiplier(),
"currentCount", transaction.progress()
);
}

@LuaFunction(mainThread = true)
public final void startTransaction(String accountID, String authorizationID, int count) throws LuaException {
if (count <= 0)
throw new LuaException("Count must be at least 1");

UUID account$, authorization$;
try {
account$ = UUID.fromString(accountID);
authorization$ = UUID.fromString(authorizationID);
} catch (IllegalArgumentException e) {
throw new LuaException("Invalid UUID");
}

Authorization authorization = new Authorization.Anonymous(authorization$);
BankAccount account = Numismatics.BANK.getAccount(account$);
if (account == null) {
throw new LuaException("Account not found");
}

ReasonHolder reasonHolder = new ReasonHolder();
SubAccount subAccount = account.getSubAccount(authorization, reasonHolder);

if (subAccount == null) {
Component errorMessage = reasonHolder.getMessageOrDefault(Components.translatable("error.numismatics.authorized_card.account_not_found"));
throw new LuaException(errorMessage.getString());
}

IDeductable deductable = subAccount.getDeductor(authorization);

if (deductable == null) {
throw new LuaException("Deductor not found");
}

IAuthorizationCheckingDeductable authorizationCheckingDeductable = IAuthorizationCheckingDeductable.of(deductable, authorization, subAccount);

if (!blockEntity.startTransaction(authorizationCheckingDeductable, count))
throw new LuaException("Failed to start transaction");
}

@Override
public String getType() {
return "Numismatics_Salepoint";
}
}
Loading

0 comments on commit e0c6a7c

Please sign in to comment.