# Minecraft Development ### Balance To get card's balance => ```java= @Override public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand){ if(!player.getStackInHand(hand).hasNbt()){ NbtCompound nbt = new NbtCompound(); nbt.putInt("financial.balance", 11); player.getStackInHand(hand).setNbt(nbt.copy()); } return super.use(world, player, hand); } @Override public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) { if (stack.hasNbt()) { int currentBalance = stack.getNbt().getInt("financial.balance"); String currentB = String.valueOf(currentBalance); tooltip.add(new LiteralText(currentB)); } } ``` ### Delegate Pattern [Example Source](https://carsonwah.github.io/delegation-pattern.html) #### Inheritance ```java= public interface IMonitor { public void display(); } public class ColorMonitor implements IMonitor { public void display() { System.out.println("Something colourful"); } } public class BWMonitor implements IMonitor { public void display() { System.out.println("Something in B&W"); } } ColorMonitor monitor = new ColorMonitor(); monitor.display(); // Something colourful**** ``` #### Delegation ```java= public interface DisplayDelegate { public void display(); } public class ColorDisplayDelegate implements DisplayDelegate { public void display() { System.out.println("Something colourful"); } } public class BWDisplayDelegate implements DisplayDelegate { public void display() { System.out.println("Something in B&W"); } } ``` ```java= public interface IMonitor { public void display(); } public class ConcreteMonitor implements IMonitor { private DisplayDelegate displayDelegate; public ConcreteMonitor() { // Set up a delegate for displaying this.displayDelegate = new ColorDisplayDelegate(); } public void display() { this.displayDelegate.display(); } } ColorMonitor monitor = new ColorMonitor(); monitor.display(); // Something colourful ``` > Benefits: Run-time flexibility ### How to set the limit of taking out the itemstack ```java= @Override default ItemStack removeStack(int slot, int count) { ItemStack result = null; /** * If we want take out the itemstack, the balance will decrease * */ if(slot >= 2 && slot <= 31){ int balance = Coin.getBalance(getStack(0)); if(balance > 0 ){ result = Inventories.splitStack(getItems(), slot, count); Coin.modifyBalance(getStack(0), 2); if (!result.isEmpty()) { markDirty(); } } else { /** * If the player's balance is inefficient, then send the message * */ MinecraftClient mc = MinecraftClient.getInstance(); mc.inGameHud.addChatMessage( MessageType.CHAT, new LiteralText("The balance is ineffiecient"), mc.player.getUuid()); return result; } } else { result = Inventories.splitStack(getItems(), slot, count); return result; } return result; } ``` ## Todo ### 1.卡 - [x] Done ![](https://i.imgur.com/4aUHvq5.png) (1)模組交易都用這個 (2)可以用ATM把特定物品加值進去 (3)綁定玩家(會顯示是哪個玩家的卡) (4)無論合成多少張卡 卡的數值同步(這點是防刷錢,不方便的話可以讓新合成的卡為零) (5)可直接使用指令轉帳給其他玩家(預設想法是//msmod give [玩家名稱] [金額(最大值你定)]) ### 2.ATM - [x] Done ![](https://i.imgur.com/RVR6Wkc.png) (1)用來將特定物品轉換成錢 腐肉 5元 骨頭 10元 火藥 20元 蜘蛛眼 50元 烈焰桿 100元 終界珍珠 100元 種子 1元 甜梅 1元 花(各種) 1元 蘑菇(雙色) 5元 小麥 10元 胡蘿蔔 10元 馬鈴薯 10元 甜菜根 10元 西瓜片 10元 蘋果 20元 餅乾 20元 南瓜派 50元 蛋糕 100元 金蘋果 1000元 附魔金蘋果 5000元 雞蛋 5元 生雞肉 10元 生兔肉 10元 生豬肉 10元 生牛肉 20元 生羊肉 20元 生鱈魚 10元 生鮭魚 10元 熱帶魚 10元 河豚 100元 鱈魚桶 200元 鮭魚桶 200元 熱帶魚桶 200元 河豚桶 500元 煤炭 10元 鐵錠 50元 銅錠 50元 紅石 50元 石英 50元 金錠 100元 青晶石 200元 綠寶石 200元 鑽石 500元 獄髓錠 1000元 (以上為官方ATM預設數值) ### 3.收銀機 - [ ] Done ![](https://i.imgur.com/3Iqedfx.png) (1)可自訂販售物品及金額(與自訂義村民類似) (2)擁有者才可開啟自定義介面 且收銀機可存放30格物品(商品) --> 右鍵使用後才是擁有者 (3)若商品售鑿 則交易選項打叉 (4)暫不開放用物品交易錢(即收銀機收購物品 因為收銀機要放錢麻煩) ### 4.電腦 - [ ] Done ![](https://i.imgur.com/GRl2lVc.png) (1)可與隨機NPC交易 (2)可與同伺服器玩家線上交易 (3)交易時的金額直接從卡內扣除 商品則送至信箱 ### 5.信箱 - [ ] Done ![](https://i.imgur.com/slIoAIo.png) (1)電腦訂購的物品會到這裡 (2)有30格物品空間 如果一次訂超過則須將信箱物品取出後 重新開啟信箱 ### 6.足球(都是羊毛) - [ ] Done ![](https://i.imgur.com/mF9enTn.png) (1)可用雞的模組 使其不能走動並改外觀 (2)對他使用右鍵為小擊退(擊退1)左鍵為大擊退 手持木棒則是右鍵將其位置與格子對齊 左鍵破壞 (3)不損血 無耐久度 ### 7.老虎機 - [ ] Done ![](https://i.imgur.com/wQPm9a8.png) (1)賭一次1000 (2)共三個圖示 倒立貓林機率10% 口水貓林機率40% 貓林罐罐機率50% 3個倒立貓林 100000 2個倒立貓林 50000 3個口水貓林 10000 2個口水貓林 5000 3個貓林罐罐 1000 2個貓林罐罐 500 以上都沒中就是沒錢 ### 8.菜刀 - [x] Done ![](https://i.imgur.com/jLVPrYU.png) (1)用於合成其他食物 (2)有耐久度 使用64次損壞 (接下來我用烈焰桿代替菜刀合成) ### 9.鱈魚生魚片 - [x] Done ![](https://i.imgur.com/53lFBHJ.png) (1)飽食度兩格 (2)1%機率劇毒1 10秒 (3)100%跳躍提升2 10秒 ### 10.鮭魚生魚片 - [x] Done ![](https://i.imgur.com/3OJb0KA.png) (1)飽食度兩格 (2)1%劇毒1 10秒 (3)100%加速2 10秒 ### 11.河豚生魚片 - [x] Done ![](https://i.imgur.com/QZSnSXN.png) (1)飽食度一格 (2)10%劇毒 10秒 (3)100%夜視1 60秒 (4)100%回復1 60秒 ### 12.肉肉串燒 - [x] Done ![](https://i.imgur.com/BYnja80.png) (1)飽食度8格 (2)100%飽食 20秒 (3)100%力量2 60秒 ### 13.大豐盛沙拉 - [x] Done ![](https://i.imgur.com/PWTqLCs.png) (1)飽食度10格 (2)100%加速2 30秒 (3)100%跳躍提升2 30秒 ### 14.甜梅果醬 - [x] Done ![](https://i.imgur.com/V4o7m0a.png) (1)合成用 ### 15.蘋果果醬 - [x] Done ![](https://i.imgur.com/NDtWorp.png) (1)合成用 ### 16.西瓜果醬 - [x] Done ![](https://i.imgur.com/8r6JBad.png) (1)合成用 ### 17.吐司 - [x] Done ![](https://i.imgur.com/F2YAJvh.png) (1)飽食度1格 (2)切一次會拿到8片 ### 18.果醬吐司 - [x] Done (1)吐司+任一果醬即為該種果醬吐司 (2)飽食度皆為3格 (3)皆100%生命值提升5點 持續20秒 ### 19.貓林風格早餐 - [x] Done > (1)肉肉串燒+大豐盛沙拉 (2)飽食度10格 (3)100% 飽食 180秒 (4)100% 生命值提升40 180秒 (5)100% 力量 180秒 (6)100% 緩速 10秒 (7)100% 立即治療 60秒 ### 20.盤子 - [x] Done > (1)用於合成其他食物 (Sashimis and Jam Toasts) (2)看你要不要他能放出來當裝飾 ### 21.研磨碗 - [x] Done > (1)用於合成其他食物 (2)有耐久度 使用64次損壞 (3)看你要不要他能放出來當裝飾 - Modificatoin: shift from durability to a crafting ingredients ### 22. ## 檔案 ### [GitHub(Code)](https://github.com/JessYu-1011/financialMod) ### [Github(Design)](https://github.com/MowLinStudio/Financial_System_Blockbench) # Instresting notes 1. Minecraft source code: between 160 thousand and 600 thousand lines of code
{"metaMigratedAt":"2023-06-16T23:30:28.653Z","metaMigratedFrom":"YAML","title":"Minecraft Development","breaks":true,"contributors":"[{\"id\":\"4cb4b623-adc8-44b8-8d9e-6cfa1bef0fb2\",\"add\":4367,\"del\":136},{\"id\":null,\"add\":5,\"del\":19},{\"id\":\"203ff621-3594-48c7-805d-0f308cc04020\",\"add\":3262,\"del\":594}]"}
    313 views