Skip to content

Commit

Permalink
fix(difficulty_rework): 💙[Crystal Memory] when clicking over [Replica…
Browse files Browse the repository at this point in the history
…tor] shows difficulty of Owner first
  • Loading branch information
Krutoy242 committed Jun 19, 2024
1 parent 2b78a72 commit a6bfa8a
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions scripts/do/acquire/info.zs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#priority -1800
#reloadable

import crafttweaker.block.IBlock;
import crafttweaker.data.IData;
import crafttweaker.player.IPlayer;
import crafttweaker.item.IIngredient;
import crafttweaker.item.IItemStack;
import scripts.do.hand_over_your_items.tellrawItemObj;
import mods.zenutils.StringList;
import scripts.do.acquire.data.sendAcquireMessage;
import crafttweaker.player.IPlayer;
import mods.zenutils.StaticString.format;
import mods.zenutils.StaticString.repeat;
import mods.zenutils.StringList;
import scripts.do.acquire.data.sendAcquireMessage;
import scripts.do.hand_over_your_items.tellrawItemObj;

static MAX_SUGGESTED_ITEMS as int = 20;
static playersCompleted as bool[string] = {} as bool[string];

function show(player as IPlayer, item as IItemStack) as bool {
function show(player as IPlayer, item as IItemStack, block as IBlock) as bool {
if (
isNull(player.world)
|| player.world.remote
Expand All @@ -28,8 +29,16 @@ function show(player as IPlayer, item as IItemStack) as bool {
var encodedItem = IItemStack.fromData(item.tag.Pattern);
if(isNull(encodedItem)) return false;

val dfclty = isNull(block)
|| isNull(block.data)
|| isNull(block.data.variables)
|| isNull(block.data.variables.ownerUUID)
|| block.data.variables.ownerUUID.asString() == ''
? player.difficulty
: scripts.lib.offline.op.get(block.data.variables.ownerUUID.asString(), 'difficulty', 0, 1000);

// collect all items that cost more than required one
val requiredCost = scripts.category.uu.getCost(encodedItem, player.difficulty);
val requiredCost = scripts.category.uu.getCost(encodedItem, dfclty);
var strList = StringList.empty();
for itemID, metaData in scripts.category.uu.values {
for meta, cost in metaData {
Expand Down Expand Up @@ -60,7 +69,7 @@ function show(player as IPlayer, item as IItemStack) as bool {
: [
{ translate: 'e2ee.acquire.to_replicate', with: [
tellrawItemObj(encodedItem, 'aqua'),
formatDfclty(player.difficulty),
formatDfclty(dfclty),
scripts.category.uu.formatUUCost(requiredCost),
]},
prefix,
Expand All @@ -77,11 +86,11 @@ function show(player as IPlayer, item as IItemStack) as bool {
}

events.register(function (e as crafttweaker.event.PlayerRightClickItemEvent) {
if(show(e.player, e.item)) e.cancel();
if(show(e.player, e.item, e.block)) e.cancel();
}, mods.zenutils.EventPriority.low());

events.register(function (e as crafttweaker.event.PlayerLeftClickBlockEvent) {
if(show(e.player, e.item)) e.cancel();
if(show(e.player, e.item, e.block)) e.cancel();
}, mods.zenutils.EventPriority.low());

function formatDfclty(dfclty as double) as string {
Expand Down

0 comments on commit a6bfa8a

Please sign in to comment.