Skip to content

Commit

Permalink
fabric energy salepoint implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
techno-sam committed Aug 6, 2024
1 parent 13a853f commit 551c45b
Show file tree
Hide file tree
Showing 58 changed files with 1,581 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.1 2024-08-05T17:31:05.743168034 Create: Numismatics/Numismatics' Advancements
// 1.20.1 2024-08-06T08:53:15.211188553 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-05T17:31:05.737487381 Create: Numismatics/Numismatics Standard Recipes
// 1.20.1 2024-08-06T08:53:15.209360144 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
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.1 2024-08-05T17:31:05.725976583 Create: Numismatics/Numismatics EMI excluded tags
// 1.20.1 2024-08-06T08:53:15.205438956 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-05T17:31:05.741816291 Create: Numismatics/Numismatics' Sequenced Assembly Recipes
// 1.20.1 2024-08-06T08:53:15.210829061 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-05T17:31:05.729416827 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-06T08:53:15.206680411 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 All @@ -8,17 +8,17 @@ a96d3d02794064cd9be1bca25a9ba6217675e6c5 assets/numismatics/models/item/white_id
bb2a77462e6213eddde134f3cc3e9a3f07f07f3f assets/numismatics/models/item/yellow_authorized_card.json
74a4c7ca7a48382782e5dba33018dfc8255192c5 assets/numismatics/models/block/brass_depositor_locked.json
3f0d912779200aaaf55bef102d9b96acead1a636 data/numismatics/tags/items/internal/dyes/purple_dyes.json
3346bd25775d94025b9cc65c03d9a7151d316355 assets/numismatics/lang/en_us.json
854b42b3b8d16001c7ba3ecf38736343281313df assets/numismatics/lang/en_us.json
377e460c0dcf6d7de1b7ae235959105a7c45e4c4 assets/numismatics/models/item/cyan_authorized_card.json
bde18ccd9c21484154597c6271750c0406082f61 data/forge/tags/blocks/relocation_not_supported.json
eca751589c40725750e2c2baa6607e83255fd5f4 assets/numismatics/models/item/brown_authorized_card.json
ad712dd2a2a7268dfa773f38a50d526952758d5c data/numismatics/tags/items/internal/dyes/cyan_dyes.json
84ab8c91452f94501b3acc31ec1e0bc64417f839 assets/numismatics/models/item/black_card.json
83ce6c9d27970b4c643f0f9f3dfeb58668fca3d4 assets/numismatics/models/item/banking_guide.json
8550097149cebbfd50bdeac2003327b60a4aee9a assets/numismatics/models/item/light_gray_card.json
83ce6c9d27970b4c643f0f9f3dfeb58668fca3d4 assets/numismatics/models/item/banking_guide.json
95b492bd9230dc90fca9395c823cef39e644d8f2 assets/numismatics/models/item/sprocket.json
70c481f36a9718ac48632e6939ac6ba785be4c9e assets/numismatics/models/item/black_id_card.json
8343a58fb3d5ce9eeecabdeaa911eccae29409d1 assets/numismatics/lang/en_ud.json
975cd8a9ed6f70432ae5514aac58513d47dd4bae assets/numismatics/lang/en_ud.json
1e78f650091a4a2c43e36fb815f23d0591e058a6 assets/numismatics/models/item/magenta_card.json
909f5d14f23199c064f6b91a421bb7b15e0f1a7d assets/numismatics/models/item/orange_authorized_card.json
d6f017479b3cc538f73d7fb0a1e65d1742bab266 assets/numismatics/models/item/light_blue_id_card.json
Expand Down Expand Up @@ -57,8 +57,8 @@ d048d04208faa63f0014d614d6026a66fe118c11 data/numismatics/loot_tables/blocks/bra
5cfb64f42dbeaa0720a7dd952e47d638c17a1056 assets/numismatics/models/block/salepoint.json
a8cb82f19034a0e724e12df45c883e9cd469c210 assets/numismatics/models/item/green_card.json
390db78c5393fca4f90018df51d1a79d11a64f72 assets/numismatics/models/item/light_blue_authorized_card.json
e1087e56db7b4d8812ab4617344f0ac8b0f0e6c7 assets/numismatics/models/item/light_gray_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
Expand Up @@ -66,6 +66,7 @@
"gui.numismatics.limit.none": "ʇıɯıן oN",
"gui.numismatics.salepoint.cancel": "uoıʇɔɐsuɐɹʇ ןǝɔuɐƆ",
"gui.numismatics.salepoint.count": "sʇıu∩",
"gui.numismatics.salepoint.energy": "ʎbɹǝuƎ",
"gui.numismatics.salepoint.fluid_empty": "ʎʇdɯƎ",
"gui.numismatics.salepoint.fluid_filter_empty.0": "ɹǝʇןıℲ pınןℲ",
"gui.numismatics.salepoint.fluid_filter_empty.1": "ǝןʇʇoq ɐ ɹo ʇǝʞɔnq ɐ sɐ ɥɔns ɯǝʇı buıpןoɥ-pınןɟ ɐ ɥʇıʍ ʞɔıןƆ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"gui.numismatics.limit.none": "No limit",
"gui.numismatics.salepoint.cancel": "Cancel transaction",
"gui.numismatics.salepoint.count": "Units",
"gui.numismatics.salepoint.energy": "Energy",
"gui.numismatics.salepoint.fluid_empty": "Empty",
"gui.numismatics.salepoint.fluid_filter_empty.0": "Fluid Filter",
"gui.numismatics.salepoint.fluid_filter_empty.1": "Click with a fluid-holding item such as a bucket or a bottle",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.simibubi.create.foundation.gui.AllGuiTextures;
import com.simibubi.create.foundation.utility.Color;
import dev.ithundxr.createnumismatics.registry.NumismaticsGuiTextures;
import net.minecraft.client.gui.GuiGraphics;
Expand All @@ -40,10 +41,28 @@ public static void drawStretched(GuiGraphics graphics, int left, int top, int w,
public static void drawCropped(GuiGraphics graphics, int left, int top, int w, int h, int z, NumismaticsGuiTextures tex) {
tex.bind();
drawTexturedQuad(graphics.pose().last()
.pose(), Color.WHITE, left, left + w, top, top + h, z, tex.startX / 256f, (tex.startX + w) / 256f,
.pose(), Color.WHITE, left, left + w, top, top + h, z, tex.startX / 256f, (tex.startX + w) / 256f,
tex.startY / 256f, (tex.startY + h) / 256f);
}

public static void drawCropped(GuiGraphics graphics, int left, int top, int minU, int minV, int maxU, int maxV, int z, NumismaticsGuiTextures tex) {
tex.bind();
drawTexturedQuad(graphics.pose().last().pose(), Color.WHITE,
left + minU, left + (maxU),
top + minV, top + (maxV), z,
(tex.startX + minU) / 256f, (tex.startX + maxU) / 256f,
(tex.startY + minV) / 256f, (tex.startY + maxV) / 256f);
}

public static void drawCropped(GuiGraphics graphics, int left, int top, int minU, int minV, int maxU, int maxV, int z, AllGuiTextures tex) {
tex.bind();
drawTexturedQuad(graphics.pose().last().pose(), Color.WHITE,
left, left + maxU - minU,
top, top + maxV - minV, z,
(tex.startX + minU) / 256f, (tex.startX + maxU) / 256f,
(tex.startY + minV) / 256f, (tex.startY + maxV) / 256f);
}

private static void drawTexturedQuad(Matrix4f m, Color c, int left, int right, int top, int bot, int z, float u1, float u2, float v1, float v2) {
Tesselator tesselator = Tesselator.getInstance();
BufferBuilder bufferbuilder = tesselator.getBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public enum Mods {
SODIUM("sodium"),
COMPUTERCRAFT("computercraft"),
EMI("emi"),
JEI("jei")
JEI("jei"),
CREATEADDITION("createaddition"),
;

public final boolean isLoaded;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.content.backend;

import com.simibubi.create.foundation.utility.Components;
import dev.ithundxr.createnumismatics.content.backend.sub_authorization.Authorization;
import org.jetbrains.annotations.NotNull;

class AuthorizationCheckingDeductableImpl implements IAuthorizationCheckingDeductable {
private final @NotNull IDeductable wrapped;
private final @NotNull Authorization authorization;
private final @NotNull IAuthorizationChecker authorizationChecker;

AuthorizationCheckingDeductableImpl(@NotNull IDeductable wrapped, @NotNull Authorization authorization, @NotNull IAuthorizationChecker authorizationChecker) {
this.wrapped = wrapped;
this.authorization = authorization;
this.authorizationChecker = authorizationChecker;
}

@Override
public boolean deduct(Coin coin, int amount, ReasonHolder reasonHolder) {
if (!authorizationChecker.isAuthorized(authorization)) {
reasonHolder.setMessage(Components.translatable("error.numismatics.card.not_authorized"));
return false;
}

return wrapped.deduct(coin, amount, reasonHolder);
}

@Override
public boolean deduct(int spurs, ReasonHolder reasonHolder) {
if (!authorizationChecker.isAuthorized(authorization)) {
reasonHolder.setMessage(Components.translatable("error.numismatics.card.not_authorized"));
return false;
}

return wrapped.deduct(spurs, reasonHolder);
}

@Override
public int getMaxWithdrawal() {
if (!authorizationChecker.isAuthorized(authorization))
return 0;

return wrapped.getMaxWithdrawal();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

import static dev.ithundxr.createnumismatics.Numismatics.crashDev;

public class BankAccount implements MenuProvider, IDeductable {
public class BankAccount implements MenuProvider, IDeductable, IAuthorizationChecker {
public enum Type {
PLAYER(false, false),
BLAZE_BANKER(true, true);
Expand Down Expand Up @@ -420,6 +420,14 @@ public boolean isAuthorized(@Nullable UUID uuid) {
return uuid.equals(this.id) || (this.type.useTrustList && this.trustList != null && this.trustList.contains(uuid));
}

@Override
public boolean isAuthorized(Authorization authorization) {
if (!authorization.isHuman())
return false;

return isAuthorized(authorization.getPersonalID());
}

public void updateTrustList(Consumer<List<UUID>> updater) {
if (trustList != null) {
updater.accept(trustList);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.content.backend;

import dev.ithundxr.createnumismatics.content.backend.sub_authorization.Authorization;

public interface IAuthorizationChecker {
boolean isAuthorized(Authorization authorization);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.content.backend;

import dev.ithundxr.createnumismatics.content.backend.sub_authorization.Authorization;

/**
* This is a marker interface, which should be used on {@link IDeductable} implementations that re-check the authorization before every deduction.
*/
public interface IAuthorizationCheckingDeductable extends IDeductable {

static IAuthorizationCheckingDeductable of(IDeductable deductable, Authorization authorization, IAuthorizationChecker checker) {
if (deductable instanceof IAuthorizationCheckingDeductable authorizationCheckingDeductable)
return authorizationCheckingDeductable;

return new AuthorizationCheckingDeductableImpl(deductable, authorization, checker);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,26 @@ public interface IDeductable {

@Nullable
static IDeductable get(ItemStack stack, @Nullable Player player, ReasonHolder reasonHolder) {
return IDeductable.getInternal(stack, player == null ? null : Either.left(player), reasonHolder);
return IDeductable.getInternal(stack, player == null ? null : Either.left(player), reasonHolder, false);
}

@Nullable
static IAuthorizationCheckingDeductable getAuthorizationChecking(ItemStack stack, @Nullable Player player, ReasonHolder reasonHolder) {
return (IAuthorizationCheckingDeductable) IDeductable.getInternal(stack, player == null ? null : Either.left(player), reasonHolder, true);
}

@Nullable
static IDeductable getAutomated(ItemStack stack, @Nullable UUID owningPlayer, ReasonHolder reasonHolder) {
return IDeductable.getInternal(stack, owningPlayer == null ? null : Either.right(owningPlayer), reasonHolder);
return IDeductable.getInternal(stack, owningPlayer == null ? null : Either.right(owningPlayer), reasonHolder, false);
}

@Nullable
private static IDeductable getInternal(ItemStack stack, @Nullable Either<Player, UUID> player, ReasonHolder reasonHolder) {
static IAuthorizationCheckingDeductable getAutomatedAuthorizationChecking(ItemStack stack, @Nullable UUID owningPlayer, ReasonHolder reasonHolder) {
return (IAuthorizationCheckingDeductable) IDeductable.getInternal(stack, owningPlayer == null ? null : Either.right(owningPlayer), reasonHolder, true);
}

@Nullable
private static IDeductable getInternal(ItemStack stack, @Nullable Either<Player, UUID> player, ReasonHolder reasonHolder, boolean mustBeAuthorizedDeductible) {
if (NumismaticsTags.AllItemTags.CARDS.matches(stack)) {
if (player == null)
return null;
Expand All @@ -69,6 +79,9 @@ private static IDeductable getInternal(ItemStack stack, @Nullable Either<Player,
BankAccount account = Numismatics.BANK.getAccount(id);

if (account != null && account.isAuthorized(player$)) {
if (mustBeAuthorizedDeductible) {
return IAuthorizationCheckingDeductable.of(account, new Authorization.Player(player$, UUID.randomUUID()), account);
}
return account;
} else if (account == null) {
reasonHolder.setMessage(Components.translatable("error.numismatics.card.account_not_found"));
Expand Down Expand Up @@ -112,6 +125,9 @@ private static IDeductable getInternal(ItemStack stack, @Nullable Either<Player,
if (deductor == null) {
reasonHolder.setMessage(Components.translatable("error.numismatics.card.not_authorized"));
}
if (mustBeAuthorizedDeductible) {
return IAuthorizationCheckingDeductable.of(deductor, authorization, subAccount);
}
return deductor;
} else if (!reasonHolder.hasMessage()) {
reasonHolder.setMessage(Components.translatable("error.numismatics.authorized_card.account_not_found"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@

public class SliderStylePriceBehaviour extends BlockEntityBehaviour {

private boolean clientReadEnabled = true;

public static final BehaviourType<SliderStylePriceBehaviour> TYPE = new BehaviourType<>("slider-style price");

protected final EnumMap<Coin, Integer> prices = new EnumMap<>(Coin.class);
Expand Down Expand Up @@ -100,6 +102,9 @@ public void write(CompoundTag tag, boolean clientPacket) {

@Override
public void read(CompoundTag tag, boolean clientPacket) {
if (clientPacket && !clientReadEnabled)
return;

super.read(tag, clientPacket);
this.prices.clear();
if (tag.contains("Prices", Tag.TAG_COMPOUND)) {
Expand All @@ -115,6 +120,14 @@ public void read(CompoundTag tag, boolean clientPacket) {
calculateTotalPrice();
}

public void enableClientRead() {
this.clientReadEnabled = true;
}

public void disableClientRead() {
this.clientReadEnabled = false;
}

public int deduct(@NotNull Player player, @NotNull InteractionHand hand, boolean addToSource, ReasonHolder reasonHolder, int maximumCount) {
int count = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public SliderStylePriceConfigurationPacket(SyncedBlockEntity be) {
this.prices = new int[Coin.values().length];

SliderStylePriceBehaviour priceBehaviour = BlockEntityBehaviour.get(be, getType());
priceBehaviour.enableClientRead();
for (Coin coin : Coin.values()) {
this.prices[coin.ordinal()] = priceBehaviour.getPrice(coin);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@

import com.simibubi.create.foundation.utility.Components;
import dev.ithundxr.createnumismatics.Numismatics;
import dev.ithundxr.createnumismatics.content.backend.BankAccount;
import dev.ithundxr.createnumismatics.content.backend.Coin;
import dev.ithundxr.createnumismatics.content.backend.IDeductable;
import dev.ithundxr.createnumismatics.content.backend.ReasonHolder;
import dev.ithundxr.createnumismatics.content.backend.*;
import dev.ithundxr.createnumismatics.content.backend.trust_list.TrustListContainer;
import dev.ithundxr.createnumismatics.multiloader.PlayerSelection;
import dev.ithundxr.createnumismatics.registry.NumismaticsPackets;
Expand All @@ -38,7 +35,7 @@
import java.util.List;
import java.util.UUID;

public final class SubAccount {
public final class SubAccount implements IAuthorizationChecker {
private final BankAccount parentAccount;

@NotNull
Expand Down Expand Up @@ -259,7 +256,7 @@ public void setRemoved() {
markDirty();
}

private class PreAuthorizedDeductor implements IDeductable {
private class PreAuthorizedDeductor implements IAuthorizationCheckingDeductable {
private final Authorization authorization;

private PreAuthorizedDeductor(Authorization authorization) {
Expand Down
Loading

0 comments on commit 551c45b

Please sign in to comment.