Skip to content

Commit

Permalink
fix: Fixed the issue where some functions did not work
Browse files Browse the repository at this point in the history
  • Loading branch information
Dream-Rainy committed Dec 2, 2024
1 parent b7e53bf commit 44cf5dd
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 166 deletions.
4 changes: 3 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

[![Lisense](https://img.shields.io/github/license/Dream-Rainy/ImyvmVillagerShop?style=for-the-badge)](https://github.com/Dream-Rainy/ImyvmVillagerShop/blob/1.19/LICENSE)![Build](https://img.shields.io/github/actions/workflow/status/Dream-Rainy/ImyvmVillagerShop/build.yml?style=for-the-badge)

已知不兼容模组: [OffersHUD](https://github.com/naari3/offers-hud)

## 一、配置文件
文件位置:`config/imyvm_villagershop.conf`

Expand Down Expand Up @@ -70,7 +72,7 @@ f(x) = p \times c \times t
创建了一个名为`DreamRain`并出售`樱花树叶`的商店。
那么,我可以使用`100`货币买到`2`个`樱花树叶`。而不是商店中`樱花树叶`的库存为`2`。
- 所有商店都有一个唯一的`id`标识符,并且永远不可能重复。
- 目前商品支持保存NBT(未经充分测试),可能会导致无法获取到指定的物品,无法保留自定义NBT等问题
- 目前商品支持保存NBT。
### 2.系统商店
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ kotlin.code.style = official

# Gradle Plugins
kotlin_version = 2.0.0
loom_version = 1.6-SNAPSHOT
loom_version = 1.8-SNAPSHOT

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version = 1.21
yarn_mappings = 1.21+build.1
loader_version = 0.15.11
yarn_mappings = 1.21+build.9
loader_version = 0.16.9

# Mod Properties
mod_version = 1.0.0
maven_group = com.imyvm

# Dependencies
fabric_version= 0.100.1+1.21
fabric_version= 0.102.0+1.21
fabric_kotlin_version = 1.11.0+kotlin.2.0.0
brigadier_version = 1.0.18
fabric_permissions_api_version = 0.3.1
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ private void selectNewTrade(int tradeIndex, CallbackInfo ci) {
if (this.merchant.getOffers().size() > tradeIndex && this.merchant.getOffers().get(tradeIndex).getFirstBuyItem().item().value() == Items.BAMBOO) {
var imyvmCurry = this.merchant.getOffers().get(tradeIndex).getFirstBuyItem().itemStack();
this.merchantInventory.setStack(0, imyvmCurry);
var barrierItem = Registries.ITEM.getOrEmpty(Identifier.tryParse("minecraft:barrier")).orElseThrow();
var barrierItemStack = barrierItem.getDefaultStack();
barrierItemStack.set(DataComponentTypes.CUSTOM_NAME, Translator.INSTANCE.tr("shop.buy.failed.lack"));
barrierItemStack.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, true);
var customData = imyvmCurry.get(DataComponentTypes.CUSTOM_DATA);
if (customData != null && customData.contains("imyvmCurry")) {
if (customData != null && customData.contains("securityCode")) {
var moneyShouldTake = imyvmCurry.get(DataComponentTypes.DAMAGE);
var player = this.getGui().getPlayer();
var playerBalance = EconomyMod.data.getOrCreate(player).getMoney();
if (moneyShouldTake != null && playerBalance < moneyShouldTake * 100) {
var barrierItem = Registries.ITEM.getOrEmpty(Identifier.tryParse("minecraft:barrier")).orElseThrow();
var barrierItemStack = barrierItem.getDefaultStack();
barrierItemStack.set(DataComponentTypes.CUSTOM_NAME, Translator.INSTANCE.tr("shop.buy.failed.lack"));
barrierItemStack.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, true);
this.merchantInventory.setStack(1, barrierItemStack);
}
}
Expand All @@ -59,7 +59,7 @@ private void onClosed(PlayerEntity playerEntity, CallbackInfo ci) {
if (!playerEntity.getWorld().isClient && playerEntity instanceof ServerPlayerEntity) {
var firstItemStack = this.merchantInventory.getStack(0);
var firstItemStackCustomData = firstItemStack.get(DataComponentTypes.CUSTOM_DATA);
if (firstItemStack.getItem() == Items.BAMBOO && firstItemStackCustomData != null && firstItemStackCustomData.contains("imyvmCurry")) {
if (firstItemStack.getItem() == Items.BAMBOO && firstItemStackCustomData != null && firstItemStackCustomData.contains("securityCode")) {
this.merchantInventory.removeStack(0);
this.merchantInventory.removeStack(1);
this.merchantInventory.removeStack(2);
Expand Down
7 changes: 5 additions & 2 deletions src/main/kotlin/com/imyvm/villagerShop/VillagerShopMain.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.imyvm.villagerShop

import com.imyvm.villagerShop.apis.*
import com.imyvm.villagerShop.apis.EconomyData
import com.imyvm.villagerShop.apis.ModConfig
import com.imyvm.villagerShop.apis.ShopService
import com.imyvm.villagerShop.apis.ShopService.Companion.resetRefreshableSellAndBuy
import com.imyvm.villagerShop.apis.Translator.tr
import com.imyvm.villagerShop.commands.register
Expand All @@ -27,11 +29,12 @@ import java.time.Duration
import java.time.LocalDateTime
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.TimeUnit


class VillagerShopMain : ModInitializer {
val scheduler = Executors.newScheduledThreadPool(1)
val scheduler: ScheduledExecutorService = Executors.newScheduledThreadPool(1)
override fun onInitialize() {
CONFIG.loadAndSave()
CommandRegistrationCallback.EVENT.register { dispatcher, commandRegistryAccess, _ ->
Expand Down
Loading

0 comments on commit 44cf5dd

Please sign in to comment.