✨ Jei, exclusive condition, biome condition, maany more things
This commit is contained in:
@@ -200,10 +200,10 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (create_enabled.toBoolean()) {
|
//if (create_enabled.toBoolean()) {
|
||||||
implementation fg.deobf("com.simibubi.create:create-${create_minecraft_version}:${create_version}:slim") { transitive = false }
|
implementation fg.deobf("com.simibubi.create:create-${create_minecraft_version}:${create_version}:slim") { transitive = false }
|
||||||
implementation fg.deobf("com.jozufozu.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}")
|
implementation fg.deobf("com.jozufozu.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}")
|
||||||
}
|
//}
|
||||||
|
|
||||||
if (ct_enabled.toBoolean()) {
|
if (ct_enabled.toBoolean()) {
|
||||||
def minecraftVersion= "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
|
def minecraftVersion= "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ registrate_version = MC1.19-1.1.5
|
|||||||
jei_minecraft_version = 1.19.2
|
jei_minecraft_version = 1.19.2
|
||||||
jei_version = 11.4.0.290
|
jei_version = 11.4.0.290
|
||||||
|
|
||||||
create_enabled = false;
|
create_enabled = true;
|
||||||
create_minecraft_version = 1.19.2
|
create_minecraft_version = 1.19.2
|
||||||
flywheel_minecraft_version = 1.19.2
|
flywheel_minecraft_version = 1.19.2
|
||||||
create_version = 0.5.1.c-36
|
create_version = 0.5.1.c-36
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
// 1.19.2 2023-08-16T17:59:11.715017504 Registrate Provider for trading_station [Recipes, Advancements, Loot tables, Tags (blocks), Tags (items), Tags (fluids), Tags (entity_types), Blockstates, Item models, Lang (en_us/en_ud)]
|
// 1.19.2 2023-08-19T22:34:02.349925986 Registrate Provider for trading_station [Recipes, Advancements, Loot tables, Tags (blocks), Tags (items), Tags (fluids), Tags (entity_types), Blockstates, Item models, Lang (en_us/en_ud)]
|
||||||
ac427e21e7a0915809800ce83800780c045678c6 assets/trading_station/blockstates/powered_trading_station.json
|
d529016ef556a0231f5da8dd90e7b84a30aad7f7 assets/trading_station/blockstates/powered_trading_station.json
|
||||||
391b0f87f6c9bd80e20dfc8b949e7dd99cd16fe9 assets/trading_station/blockstates/trading_station.json
|
d529016ef556a0231f5da8dd90e7b84a30aad7f7 assets/trading_station/blockstates/trading_station.json
|
||||||
2c8a8b7c6874dcb7e5474ba19b33fbb2d166c834 assets/trading_station/lang/en_ud.json
|
72f9bf61c9db46a4fefece27497879b91d0290e3 assets/trading_station/lang/en_ud.json
|
||||||
efb3401e9c37c753973bf81e4da4bb0946061a19 assets/trading_station/lang/en_us.json
|
b39694f8daf13daba09feddb32de6f23e9bf20ad assets/trading_station/lang/en_us.json
|
||||||
373be6ce42eee460888161c967f098e5943e3778 assets/trading_station/models/item/powered_trading_station.json
|
373be6ce42eee460888161c967f098e5943e3778 assets/trading_station/models/item/powered_trading_station.json
|
||||||
7ddda578b6d6072db924599a9959579470354897 assets/trading_station/models/item/trading_station.json
|
7ddda578b6d6072db924599a9959579470354897 assets/trading_station/models/item/trading_station.json
|
||||||
c3b4c04c1cecdc5001fcddda7b30b11b15f0b2b2 data/trading_station/loot_tables/blocks/powered_trading_station.json
|
c3b4c04c1cecdc5001fcddda7b30b11b15f0b2b2 data/trading_station/loot_tables/blocks/powered_trading_station.json
|
||||||
|
|||||||
@@ -1,33 +1,63 @@
|
|||||||
{
|
{
|
||||||
"variants": {
|
"variants": {
|
||||||
"facing=east,powered=false": {
|
"facing=east,lit=false,powered=false": {
|
||||||
"model": "trading_station:block/powered_trading_station",
|
"model": "trading_station:block/trading_station",
|
||||||
"y": 90
|
"y": 90
|
||||||
},
|
},
|
||||||
"facing=east,powered=true": {
|
"facing=east,lit=false,powered=true": {
|
||||||
"model": "trading_station:block/powered_trading_station_powered",
|
"model": "trading_station:block/trading_station_powered",
|
||||||
"y": 90
|
"y": 90
|
||||||
},
|
},
|
||||||
"facing=north,powered=false": {
|
"facing=east,lit=true,powered=false": {
|
||||||
"model": "trading_station:block/powered_trading_station"
|
"model": "trading_station:block/trading_station_lit",
|
||||||
|
"y": 90
|
||||||
},
|
},
|
||||||
"facing=north,powered=true": {
|
"facing=east,lit=true,powered=true": {
|
||||||
"model": "trading_station:block/powered_trading_station_powered"
|
"model": "trading_station:block/trading_station_powered_lit",
|
||||||
|
"y": 90
|
||||||
},
|
},
|
||||||
"facing=south,powered=false": {
|
"facing=north,lit=false,powered=false": {
|
||||||
"model": "trading_station:block/powered_trading_station",
|
"model": "trading_station:block/trading_station"
|
||||||
|
},
|
||||||
|
"facing=north,lit=false,powered=true": {
|
||||||
|
"model": "trading_station:block/trading_station_powered"
|
||||||
|
},
|
||||||
|
"facing=north,lit=true,powered=false": {
|
||||||
|
"model": "trading_station:block/trading_station_lit"
|
||||||
|
},
|
||||||
|
"facing=north,lit=true,powered=true": {
|
||||||
|
"model": "trading_station:block/trading_station_powered_lit"
|
||||||
|
},
|
||||||
|
"facing=south,lit=false,powered=false": {
|
||||||
|
"model": "trading_station:block/trading_station",
|
||||||
"y": 180
|
"y": 180
|
||||||
},
|
},
|
||||||
"facing=south,powered=true": {
|
"facing=south,lit=false,powered=true": {
|
||||||
"model": "trading_station:block/powered_trading_station_powered",
|
"model": "trading_station:block/trading_station_powered",
|
||||||
"y": 180
|
"y": 180
|
||||||
},
|
},
|
||||||
"facing=west,powered=false": {
|
"facing=south,lit=true,powered=false": {
|
||||||
"model": "trading_station:block/powered_trading_station",
|
"model": "trading_station:block/trading_station_lit",
|
||||||
|
"y": 180
|
||||||
|
},
|
||||||
|
"facing=south,lit=true,powered=true": {
|
||||||
|
"model": "trading_station:block/trading_station_powered_lit",
|
||||||
|
"y": 180
|
||||||
|
},
|
||||||
|
"facing=west,lit=false,powered=false": {
|
||||||
|
"model": "trading_station:block/trading_station",
|
||||||
"y": 270
|
"y": 270
|
||||||
},
|
},
|
||||||
"facing=west,powered=true": {
|
"facing=west,lit=false,powered=true": {
|
||||||
"model": "trading_station:block/powered_trading_station_powered",
|
"model": "trading_station:block/trading_station_powered",
|
||||||
|
"y": 270
|
||||||
|
},
|
||||||
|
"facing=west,lit=true,powered=false": {
|
||||||
|
"model": "trading_station:block/trading_station_lit",
|
||||||
|
"y": 270
|
||||||
|
},
|
||||||
|
"facing=west,lit=true,powered=true": {
|
||||||
|
"model": "trading_station:block/trading_station_powered_lit",
|
||||||
"y": 270
|
"y": 270
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,64 @@
|
|||||||
{
|
{
|
||||||
"variants": {
|
"variants": {
|
||||||
"facing=east,powered=false": {
|
"facing=east,lit=false,powered=false": {
|
||||||
"model": "trading_station:block/trading_station",
|
"model": "trading_station:block/trading_station",
|
||||||
"y": 90
|
"y": 90
|
||||||
},
|
},
|
||||||
"facing=east,powered=true": {
|
"facing=east,lit=false,powered=true": {
|
||||||
"model": "trading_station:block/trading_station_powered",
|
"model": "trading_station:block/trading_station_powered",
|
||||||
"y": 90
|
"y": 90
|
||||||
},
|
},
|
||||||
"facing=north,powered=false": {
|
"facing=east,lit=true,powered=false": {
|
||||||
|
"model": "trading_station:block/trading_station_lit",
|
||||||
|
"y": 90
|
||||||
|
},
|
||||||
|
"facing=east,lit=true,powered=true": {
|
||||||
|
"model": "trading_station:block/trading_station_powered_lit",
|
||||||
|
"y": 90
|
||||||
|
},
|
||||||
|
"facing=north,lit=false,powered=false": {
|
||||||
"model": "trading_station:block/trading_station"
|
"model": "trading_station:block/trading_station"
|
||||||
},
|
},
|
||||||
"facing=north,powered=true": {
|
"facing=north,lit=false,powered=true": {
|
||||||
"model": "trading_station:block/trading_station_powered"
|
"model": "trading_station:block/trading_station_powered"
|
||||||
},
|
},
|
||||||
"facing=south,powered=false": {
|
"facing=north,lit=true,powered=false": {
|
||||||
|
"model": "trading_station:block/trading_station_lit"
|
||||||
|
},
|
||||||
|
"facing=north,lit=true,powered=true": {
|
||||||
|
"model": "trading_station:block/trading_station_powered_lit"
|
||||||
|
},
|
||||||
|
"facing=south,lit=false,powered=false": {
|
||||||
"model": "trading_station:block/trading_station",
|
"model": "trading_station:block/trading_station",
|
||||||
"y": 180
|
"y": 180
|
||||||
},
|
},
|
||||||
"facing=south,powered=true": {
|
"facing=south,lit=false,powered=true": {
|
||||||
"model": "trading_station:block/trading_station_powered",
|
"model": "trading_station:block/trading_station_powered",
|
||||||
"y": 180
|
"y": 180
|
||||||
},
|
},
|
||||||
"facing=west,powered=false": {
|
"facing=south,lit=true,powered=false": {
|
||||||
|
"model": "trading_station:block/trading_station_lit",
|
||||||
|
"y": 180
|
||||||
|
},
|
||||||
|
"facing=south,lit=true,powered=true": {
|
||||||
|
"model": "trading_station:block/trading_station_powered_lit",
|
||||||
|
"y": 180
|
||||||
|
},
|
||||||
|
"facing=west,lit=false,powered=false": {
|
||||||
"model": "trading_station:block/trading_station",
|
"model": "trading_station:block/trading_station",
|
||||||
"y": 270
|
"y": 270
|
||||||
},
|
},
|
||||||
"facing=west,powered=true": {
|
"facing=west,lit=false,powered=true": {
|
||||||
"model": "trading_station:block/trading_station_powered",
|
"model": "trading_station:block/trading_station_powered",
|
||||||
"y": 270
|
"y": 270
|
||||||
|
},
|
||||||
|
"facing=west,lit=true,powered=false": {
|
||||||
|
"model": "trading_station:block/trading_station_lit",
|
||||||
|
"y": 270
|
||||||
|
},
|
||||||
|
"facing=west,lit=true,powered=true": {
|
||||||
|
"model": "trading_station:block/trading_station_powered_lit",
|
||||||
|
"y": 270
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"block.trading_station.powered_trading_station": "uoıʇɐʇS buıpɐɹ⟘ pǝɹǝʍoԀ",
|
||||||
|
"block.trading_station.trading_station": "uoıʇɐʇS buıpɐɹ⟘",
|
||||||
|
"config.jade.plugin_trading_station.trading_station_data": "ɐʇɐp uoıʇɐʇS buıpɐɹ⟘",
|
||||||
|
"itemGroup.trading_station": "uoıʇɐʇS buıpɐɹ⟘",
|
||||||
|
"trading_station.screen.redstone.high": "ɥbıH",
|
||||||
|
"trading_station.screen.redstone.ignored": "pǝɹoubI",
|
||||||
|
"trading_station.screen.redstone.low": "ʍoꞀ",
|
||||||
|
"trading_station.screen.redstone.redstoneMode": " :ǝuoʇspǝᴚ",
|
||||||
|
"trading_station.select_target.button": "ʇǝbɹɐʇ ʇɔǝןǝS",
|
||||||
|
"trading_station.select_target.clear": "ɹɐǝןƆ",
|
||||||
|
"trading_station.select_target.title": "ʇǝbɹɐʇ ʇndʇno uɐ ʇɔǝןǝS",
|
||||||
|
"trading_station.tooltip.progress": "%d%% :ssǝɹboɹԀ",
|
||||||
|
"trading_station.trading.recipe": "ǝdıɔǝɹ buıpɐɹ⟘",
|
||||||
|
"trading_station.trading.recipe.biome": "pǝɹınbǝɹ ǝɯoıq %s",
|
||||||
|
"trading_station.trading.recipe.biomeRequired": "ʇuǝɯıɹǝnbǝɹ ǝɯoıq ɔıɟıɔǝdS"
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"block.trading_station.powered_trading_station": "Powered Trading Station",
|
||||||
|
"block.trading_station.trading_station": "Trading Station",
|
||||||
|
"config.jade.plugin_trading_station.trading_station_data": "Trading Station data",
|
||||||
|
"itemGroup.trading_station": "Trading Station",
|
||||||
|
"trading_station.screen.redstone.high": "High",
|
||||||
|
"trading_station.screen.redstone.ignored": "Ignored",
|
||||||
|
"trading_station.screen.redstone.low": "Low",
|
||||||
|
"trading_station.screen.redstone.redstoneMode": "Redstone: ",
|
||||||
|
"trading_station.select_target.button": "Select target",
|
||||||
|
"trading_station.select_target.clear": "Clear",
|
||||||
|
"trading_station.select_target.title": "Select an output target",
|
||||||
|
"trading_station.tooltip.progress": "Progress: %d%%",
|
||||||
|
"trading_station.trading.recipe": "Trading recipe",
|
||||||
|
"trading_station.trading.recipe.biome": "%s biome required",
|
||||||
|
"trading_station.trading.recipe.biomeRequired": "Specific biome requeriment"
|
||||||
|
}
|
||||||
@@ -70,14 +70,19 @@ public class TradingStation
|
|||||||
}
|
}
|
||||||
private static void registerLanguageKeys(){
|
private static void registerLanguageKeys(){
|
||||||
registrate().addRawLang("itemGroup.trading_station", "Trading Station");
|
registrate().addRawLang("itemGroup.trading_station", "Trading Station");
|
||||||
registrate().addRawLang(ModLang.key("trading_station.block.display"), "Trading Station");
|
|
||||||
registrate().addRawLang(ModLang.key("powered_trading_station.block.display"), "Powered Trading Station");
|
|
||||||
registrate().addRawLang(ModLang.key("trading.recipe"), "Trading recipe");
|
registrate().addRawLang(ModLang.key("trading.recipe"), "Trading recipe");
|
||||||
|
registrate().addRawLang(ModLang.key("trading.recipe.biome"), "%s biome required");
|
||||||
|
registrate().addRawLang(ModLang.key("trading.recipe.biomeRequired"), "Specific biome requeriment");
|
||||||
registrate().addRawLang(ModLang.key("tooltip.progress"), "Progress: %d%%");
|
registrate().addRawLang(ModLang.key("tooltip.progress"), "Progress: %d%%");
|
||||||
registrate().addRawLang(ModLang.key("select_target.title"), "Select an output target");
|
registrate().addRawLang(ModLang.key("select_target.title"), "Select an output target");
|
||||||
registrate().addRawLang(ModLang.key("select_target.button"), "Select target");
|
registrate().addRawLang(ModLang.key("select_target.button"), "Select target");
|
||||||
registrate().addRawLang(ModLang.key("select_target.clear"), "Clear");
|
registrate().addRawLang(ModLang.key("select_target.clear"), "Clear");
|
||||||
registrate().addRawLang("config.jade.plugin_trading_station.trading_station_data", "Trading Station data");
|
registrate().addRawLang("config.jade.plugin_trading_station.trading_station_data", "Trading Station data");
|
||||||
|
|
||||||
|
registrate().addRawLang(ModLang.key("screen.redstone.redstoneMode"), "Redstone: ");
|
||||||
|
registrate().addRawLang(ModLang.key("screen.redstone.ignored"), "Ignored");
|
||||||
|
registrate().addRawLang(ModLang.key("screen.redstone.low"), "Low");
|
||||||
|
registrate().addRawLang(ModLang.key("screen.redstone.high"), "High");
|
||||||
}
|
}
|
||||||
public static Registrate registrate() {
|
public static Registrate registrate() {
|
||||||
return REGISTRATE.get();
|
return REGISTRATE.get();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.oierbravo.trading_station.compat.jade;
|
package com.oierbravo.trading_station.compat.jade;
|
||||||
|
|
||||||
|
import com.oierbravo.trading_station.content.trading_station.ITradingStationBlockEntity;
|
||||||
import com.oierbravo.trading_station.content.trading_station.TradingStationBlockEntity;
|
import com.oierbravo.trading_station.content.trading_station.TradingStationBlockEntity;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
@@ -32,8 +33,8 @@ public class ProgressComponentProvider implements IBlockComponentProvider, ISer
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendServerData(CompoundTag compoundTag, ServerPlayer serverPlayer, Level level, BlockEntity blockEntity, boolean b) {
|
public void appendServerData(CompoundTag compoundTag, ServerPlayer serverPlayer, Level level, BlockEntity blockEntity, boolean b) {
|
||||||
if(blockEntity instanceof TradingStationBlockEntity){
|
if(blockEntity instanceof ITradingStationBlockEntity){
|
||||||
TradingStationBlockEntity trading_station = (TradingStationBlockEntity) blockEntity;
|
ITradingStationBlockEntity trading_station = (ITradingStationBlockEntity) blockEntity;
|
||||||
compoundTag.putInt("trading_station.progress",trading_station.getProgressPercent());
|
compoundTag.putInt("trading_station.progress",trading_station.getProgressPercent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.oierbravo.trading_station.compat.jade;
|
|||||||
import com.oierbravo.trading_station.TradingStation;
|
import com.oierbravo.trading_station.TradingStation;
|
||||||
import com.oierbravo.trading_station.content.trading_station.TradingStationBlock;
|
import com.oierbravo.trading_station.content.trading_station.TradingStationBlock;
|
||||||
import com.oierbravo.trading_station.content.trading_station.TradingStationBlockEntity;
|
import com.oierbravo.trading_station.content.trading_station.TradingStationBlockEntity;
|
||||||
|
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationBlock;
|
||||||
|
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationBlockEntity;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import snownee.jade.api.*;
|
import snownee.jade.api.*;
|
||||||
|
|
||||||
@@ -13,10 +15,12 @@ public class TradingStationPlugin implements IWailaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void register(IWailaCommonRegistration registration) {
|
public void register(IWailaCommonRegistration registration) {
|
||||||
registration.registerBlockDataProvider(new ProgressComponentProvider(), TradingStationBlockEntity.class);
|
registration.registerBlockDataProvider(new ProgressComponentProvider(), TradingStationBlockEntity.class);
|
||||||
|
//registration.registerBlockDataProvider(new ProgressComponentProvider(), PoweredTradingStationBlockEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerClient(IWailaClientRegistration registration) {
|
public void registerClient(IWailaClientRegistration registration) {
|
||||||
registration.registerBlockComponent(new ProgressComponentProvider(), TradingStationBlock.class);
|
registration.registerBlockComponent(new ProgressComponentProvider(), TradingStationBlock.class);
|
||||||
|
//registration.registerBlockComponent(new ProgressComponentProvider(), PoweredTradingStationBlock.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,23 @@ package com.oierbravo.trading_station.compat.jei;
|
|||||||
|
|
||||||
import com.oierbravo.trading_station.TradingStation;
|
import com.oierbravo.trading_station.TradingStation;
|
||||||
import com.oierbravo.trading_station.content.trading_recipe.TradingRecipe;
|
import com.oierbravo.trading_station.content.trading_recipe.TradingRecipe;
|
||||||
import com.oierbravo.trading_station.content.trading_station.TradingStationConfig;
|
import com.oierbravo.trading_station.content.trading_station.TradingStationMenu;
|
||||||
|
import com.oierbravo.trading_station.foundation.gui.AbstractTradingMenu;
|
||||||
|
import com.oierbravo.trading_station.registrate.ModRecipes;
|
||||||
import com.oierbravo.trading_station.registrate.PoweredTradingStationRegistrate;
|
import com.oierbravo.trading_station.registrate.PoweredTradingStationRegistrate;
|
||||||
import com.oierbravo.trading_station.registrate.TradingStationRegistrate;
|
import com.oierbravo.trading_station.registrate.TradingStationRegistrate;
|
||||||
import mezz.jei.api.IModPlugin;
|
import mezz.jei.api.IModPlugin;
|
||||||
import mezz.jei.api.JeiPlugin;
|
import mezz.jei.api.JeiPlugin;
|
||||||
|
import mezz.jei.api.constants.RecipeTypes;
|
||||||
import mezz.jei.api.recipe.RecipeType;
|
import mezz.jei.api.recipe.RecipeType;
|
||||||
import mezz.jei.api.registration.IRecipeCatalystRegistration;
|
import mezz.jei.api.registration.IRecipeCatalystRegistration;
|
||||||
import mezz.jei.api.registration.IRecipeCategoryRegistration;
|
import mezz.jei.api.registration.IRecipeCategoryRegistration;
|
||||||
import mezz.jei.api.registration.IRecipeRegistration;
|
import mezz.jei.api.registration.IRecipeRegistration;
|
||||||
|
import mezz.jei.api.registration.IRecipeTransferRegistration;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.inventory.MenuType;
|
||||||
|
import net.minecraft.world.inventory.SmithingMenu;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.crafting.RecipeManager;
|
import net.minecraft.world.item.crafting.RecipeManager;
|
||||||
|
|
||||||
@@ -21,6 +27,7 @@ import java.util.Objects;
|
|||||||
|
|
||||||
@JeiPlugin
|
@JeiPlugin
|
||||||
public class JEIPlugin implements IModPlugin {
|
public class JEIPlugin implements IModPlugin {
|
||||||
|
static RecipeType<TradingRecipe> TRAING_RECIPE = new RecipeType<>(TradingRecipeCategory.UID, TradingRecipe.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getPluginUid() {
|
public ResourceLocation getPluginUid() {
|
||||||
@@ -35,8 +42,8 @@ public class JEIPlugin implements IModPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
|
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
|
||||||
registration.addRecipeCatalyst(new ItemStack(TradingStationRegistrate.TRADING_STATION_BLOCK.get()),new RecipeType<>(TradingRecipeCategory.UID, TradingRecipe.class));
|
registration.addRecipeCatalyst(new ItemStack(TradingStationRegistrate.BLOCK.get()),new RecipeType<>(TradingRecipeCategory.UID, TradingRecipe.class));
|
||||||
registration.addRecipeCatalyst(new ItemStack(PoweredTradingStationRegistrate.POWERED_TRADING_STATION_BLOCK.get()),new RecipeType<>(TradingRecipeCategory.UID, TradingRecipe.class));
|
registration.addRecipeCatalyst(new ItemStack(PoweredTradingStationRegistrate.BLOCK.get()),new RecipeType<>(TradingRecipeCategory.UID, TradingRecipe.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -44,7 +51,14 @@ public class JEIPlugin implements IModPlugin {
|
|||||||
RecipeManager rm = Objects.requireNonNull(Minecraft.getInstance().level).getRecipeManager();
|
RecipeManager rm = Objects.requireNonNull(Minecraft.getInstance().level).getRecipeManager();
|
||||||
|
|
||||||
List<TradingRecipe> tradingRecipes = rm.getAllRecipesFor(TradingRecipe.Type.INSTANCE);
|
List<TradingRecipe> tradingRecipes = rm.getAllRecipesFor(TradingRecipe.Type.INSTANCE);
|
||||||
registration.addRecipes(new RecipeType<>(TradingRecipeCategory.UID, TradingRecipe.class), tradingRecipes);
|
registration.addRecipes(TRAING_RECIPE, tradingRecipes);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) {
|
||||||
|
registration.addRecipeTransferHandler(new TradingRecipeHandler(), TRAING_RECIPE);
|
||||||
|
//registration.addRecipeTransferHandler(TradingStationMenu.class, TradingStationRegistrate.MENU.get(), new RecipeType<>(TradingRecipeCategory.UID, TradingRecipe.class), 36, 2, 0, 36);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.google.common.cache.CacheLoader;
|
|||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.oierbravo.trading_station.TradingStation;
|
import com.oierbravo.trading_station.TradingStation;
|
||||||
|
import com.oierbravo.trading_station.content.trading_recipe.BiomeCondition;
|
||||||
import com.oierbravo.trading_station.content.trading_recipe.TradingRecipe;
|
import com.oierbravo.trading_station.content.trading_recipe.TradingRecipe;
|
||||||
import com.oierbravo.trading_station.foundation.util.ModLang;
|
import com.oierbravo.trading_station.foundation.util.ModLang;
|
||||||
import com.oierbravo.trading_station.registrate.TradingStationRegistrate;
|
import com.oierbravo.trading_station.registrate.TradingStationRegistrate;
|
||||||
@@ -26,7 +27,6 @@ import net.minecraft.network.chat.Component;
|
|||||||
import net.minecraft.network.chat.MutableComponent;
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Items;
|
|
||||||
import net.minecraft.world.item.crafting.Ingredient;
|
import net.minecraft.world.item.crafting.Ingredient;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -64,7 +64,7 @@ public class TradingRecipeCategory implements IRecipeCategory<TradingRecipe> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.icon = helper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(TradingStationRegistrate.TRADING_STATION_BLOCK.get()));
|
this.icon = helper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(TradingStationRegistrate.BLOCK.get()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,13 +97,19 @@ public class TradingRecipeCategory implements IRecipeCategory<TradingRecipe> {
|
|||||||
for(int index = 0; index < ingredients.size(); index++) {
|
for(int index = 0; index < ingredients.size(); index++) {
|
||||||
Ingredient ing = ingredients.get(index);
|
Ingredient ing = ingredients.get(index);
|
||||||
builder.addSlot(RecipeIngredientRole.INPUT, 41 + index * 18, 11)
|
builder.addSlot(RecipeIngredientRole.INPUT, 41 + index * 18, 11)
|
||||||
.addIngredients(ingredients.get(index));
|
.addIngredients(ingredients.get(index))
|
||||||
|
.setSlotName("input_" + index);
|
||||||
//.addItemStacks(Arrays.asList(ingredients.get(0).getItems()));
|
//.addItemStacks(Arrays.asList(ingredients.get(0).getItems()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.addSlot(RecipeIngredientRole.OUTPUT, 113, 11)
|
builder.addSlot(RecipeIngredientRole.OUTPUT, 113, 11)
|
||||||
.addItemStack(recipe.getResultItem());
|
.addItemStack(recipe.getResultItem())
|
||||||
|
.addTooltipCallback((recipeSlotView, tooltip) -> {
|
||||||
|
if(recipe.getBiomeCondition() != BiomeCondition.EMPTY)
|
||||||
|
tooltip.add(recipe.getBiomeCondition().toComponent());
|
||||||
|
})
|
||||||
|
.setSlotName("output");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -111,7 +117,8 @@ public class TradingRecipeCategory implements IRecipeCategory<TradingRecipe> {
|
|||||||
IRecipeCategory.super.draw(recipe, recipeSlotsView, stack, mouseX, mouseY);
|
IRecipeCategory.super.draw(recipe, recipeSlotsView, stack, mouseX, mouseY);
|
||||||
IDrawableAnimated arrow = getArrow();
|
IDrawableAnimated arrow = getArrow();
|
||||||
arrow.draw(stack, 75, 14);
|
arrow.draw(stack, 75, 14);
|
||||||
drawProcessingTime(recipe, stack, 81,4);
|
//drawProcessingTime(recipe, stack, 81,4);
|
||||||
|
drawBiome(recipe, stack, 1,34);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -125,4 +132,11 @@ public class TradingRecipeCategory implements IRecipeCategory<TradingRecipe> {
|
|||||||
fontRenderer.draw(poseStack, timeString, x, y, 0xFF808080);
|
fontRenderer.draw(poseStack, timeString, x, y, 0xFF808080);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
protected void drawBiome(TradingRecipe recipe, PoseStack poseStack, int x, int y) {
|
||||||
|
if(recipe.getBiomeCondition() == BiomeCondition.EMPTY)
|
||||||
|
return;
|
||||||
|
Minecraft minecraft = Minecraft.getInstance();
|
||||||
|
Font fontRenderer = minecraft.font;
|
||||||
|
fontRenderer.draw(poseStack, recipe.getBiomeCondition().toComponent(), x, y, 0xFF808080);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,50 @@
|
|||||||
package com.oierbravo.trading_station.compat.jei;
|
package com.oierbravo.trading_station.compat.jei;
|
||||||
|
|
||||||
public class TradingRecipeHandler {
|
import com.oierbravo.trading_station.content.trading_recipe.TradingRecipe;
|
||||||
|
import com.oierbravo.trading_station.content.trading_station.TradingStationMenu;
|
||||||
|
import com.oierbravo.trading_station.foundation.gui.AbstractTradingMenu;
|
||||||
|
import com.oierbravo.trading_station.registrate.ModRecipes;
|
||||||
|
import com.oierbravo.trading_station.registrate.TradingStationRegistrate;
|
||||||
|
import mezz.jei.api.gui.ingredient.IRecipeSlotView;
|
||||||
|
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
|
||||||
|
import mezz.jei.api.recipe.RecipeType;
|
||||||
|
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
|
||||||
|
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
|
||||||
|
import mezz.jei.common.gui.ingredients.RecipeSlot;
|
||||||
|
import mezz.jei.common.transfer.RecipeTransferHandlerHelper;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.inventory.MenuType;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class TradingRecipeHandler implements IRecipeTransferHandler<TradingStationMenu, TradingRecipe> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends TradingStationMenu> getContainerClass() {
|
||||||
|
return TradingStationMenu.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<MenuType<TradingStationMenu>> getMenuType() {
|
||||||
|
return Optional.of(TradingStationRegistrate.MENU.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RecipeType<TradingRecipe> getRecipeType() {
|
||||||
|
return JEIPlugin.TRAING_RECIPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable IRecipeTransferError transferRecipe(TradingStationMenu container, TradingRecipe recipe, IRecipeSlotsView recipeSlots, Player player, boolean maxTransfer, boolean doTransfer) {
|
||||||
|
// for( index = 0; index < recipe.)
|
||||||
|
if(!doTransfer)
|
||||||
|
return null;
|
||||||
|
Optional<IRecipeSlotView> input_0 = recipeSlots.findSlotByName("input_0");
|
||||||
|
List<ItemStack> itemStacks= input_0.get().getItemStacks().toList();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,50 @@
|
|||||||
package com.oierbravo.trading_station.compat.kubejs;public class BiomeConditionComponent {
|
package com.oierbravo.trading_station.compat.kubejs;
|
||||||
}
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.oierbravo.trading_station.content.trading_recipe.BiomeCondition;
|
||||||
|
import dev.latvian.mods.kubejs.recipe.RecipeJS;
|
||||||
|
import dev.latvian.mods.kubejs.recipe.component.ComponentRole;
|
||||||
|
import dev.latvian.mods.kubejs.recipe.component.RecipeComponent;
|
||||||
|
import dev.latvian.mods.rhino.NativeObject;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
|
||||||
|
public class BiomeConditionComponent implements RecipeComponent<BiomeCondition> {
|
||||||
|
public static final RecipeComponent<BiomeCondition> BIOME_CONDITION= new BiomeConditionComponent();
|
||||||
|
|
||||||
|
public ComponentRole role() {
|
||||||
|
return ComponentRole.OTHER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> componentClass() {
|
||||||
|
return BiomeCondition.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement write(RecipeJS recipe, BiomeCondition value) {
|
||||||
|
return value.toJson();
|
||||||
|
}
|
||||||
|
|
||||||
|
private BiomeCondition fromNativeObject(NativeObject nativeObject ){
|
||||||
|
if(nativeObject.containsKey("tag"))
|
||||||
|
return BiomeCondition.fromString("#" + nativeObject.get("tag"));
|
||||||
|
return BiomeCondition.fromString(nativeObject.get("name").toString());
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public BiomeCondition read(RecipeJS recipe, Object from) {
|
||||||
|
if (from instanceof BiomeCondition bc) {
|
||||||
|
return bc;
|
||||||
|
|
||||||
|
} else if (from instanceof Biome b) {
|
||||||
|
return BiomeCondition.fromBiome(b);
|
||||||
|
} else if (from instanceof JsonObject je) {
|
||||||
|
return BiomeCondition.fromJson(je);
|
||||||
|
} else if(from instanceof NativeObject no){
|
||||||
|
return fromNativeObject(no);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return BiomeCondition.fromString(String.valueOf(from));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,14 +3,20 @@ package com.oierbravo.trading_station.compat.kubejs;
|
|||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.oierbravo.trading_station.content.trading_recipe.BiomeCondition;
|
import com.oierbravo.trading_station.content.trading_recipe.BiomeCondition;
|
||||||
|
import com.oierbravo.trading_station.content.trading_recipe.ExclusiveToCondition;
|
||||||
import dev.latvian.mods.kubejs.recipe.RecipeJS;
|
import dev.latvian.mods.kubejs.recipe.RecipeJS;
|
||||||
import dev.latvian.mods.kubejs.recipe.component.ComponentRole;
|
import dev.latvian.mods.kubejs.recipe.component.ComponentRole;
|
||||||
import dev.latvian.mods.kubejs.recipe.component.RecipeComponent;
|
import dev.latvian.mods.kubejs.recipe.component.RecipeComponent;
|
||||||
|
import dev.latvian.mods.rhino.NativeArray;
|
||||||
import dev.latvian.mods.rhino.NativeObject;
|
import dev.latvian.mods.rhino.NativeObject;
|
||||||
|
import net.minecraft.core.NonNullList;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
|
||||||
public class ExclusiveToConditionComponent implements RecipeComponent<BiomeCondition> {
|
import java.util.List;
|
||||||
public static final RecipeComponent<BiomeCondition> BIOME_CONDITION= new ExclusiveToConditionComponent();
|
|
||||||
|
public class ExclusiveToConditionComponent implements RecipeComponent<ExclusiveToCondition> {
|
||||||
|
public static final RecipeComponent<ExclusiveToCondition> EXCLUSIVE_CONDITION = new ExclusiveToConditionComponent();
|
||||||
|
|
||||||
|
|
||||||
public ComponentRole role() {
|
public ComponentRole role() {
|
||||||
return ComponentRole.OTHER;
|
return ComponentRole.OTHER;
|
||||||
@@ -18,33 +24,26 @@ public class ExclusiveToConditionComponent implements RecipeComponent<BiomeCondi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<?> componentClass() {
|
public Class<?> componentClass() {
|
||||||
return BiomeCondition.class;
|
return ExclusiveToCondition.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonElement write(RecipeJS recipe, BiomeCondition value) {
|
public JsonElement write(RecipeJS recipe, ExclusiveToCondition value) {
|
||||||
return value.toJson();
|
return value.toJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
private BiomeCondition fromNativeObject(NativeObject nativeObject ){
|
private ExclusiveToCondition fromNativeArray(NativeArray pNativeArray){
|
||||||
if(nativeObject.containsKey("tag"))
|
return ExclusiveToCondition.fromList(pNativeArray.stream().toList());
|
||||||
return BiomeCondition.fromString("#" + nativeObject.get("tag"));
|
}
|
||||||
return BiomeCondition.fromString(nativeObject.get("name").toString());
|
|
||||||
}
|
|
||||||
@Override
|
@Override
|
||||||
public BiomeCondition read(RecipeJS recipe, Object from) {
|
public ExclusiveToCondition read(RecipeJS recipe, Object from) {
|
||||||
if (from instanceof BiomeCondition bc) {
|
if (from instanceof ExclusiveToCondition ec) {
|
||||||
return bc;
|
return ec;
|
||||||
|
} else if(from instanceof NativeArray nativeArray){
|
||||||
} else if (from instanceof Biome b) {
|
return fromNativeArray(nativeArray);
|
||||||
return BiomeCondition.fromBiome(b);
|
|
||||||
} else if (from instanceof JsonObject je) {
|
|
||||||
return BiomeCondition.fromJson(je);
|
|
||||||
} else if(from instanceof NativeObject no){
|
|
||||||
return fromNativeObject(no);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return BiomeCondition.fromString(String.valueOf(from));
|
return ExclusiveToCondition.fromString(String.valueOf(from));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,8 @@ package com.oierbravo.trading_station.compat.kubejs;
|
|||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import com.oierbravo.trading_station.content.trading_recipe.BiomeCondition;
|
||||||
|
import com.oierbravo.trading_station.content.trading_recipe.ExclusiveToCondition;
|
||||||
import dev.latvian.mods.kubejs.item.InputItem;
|
import dev.latvian.mods.kubejs.item.InputItem;
|
||||||
import dev.latvian.mods.kubejs.item.OutputItem;
|
import dev.latvian.mods.kubejs.item.OutputItem;
|
||||||
import dev.latvian.mods.kubejs.recipe.RecipeJS;
|
import dev.latvian.mods.kubejs.recipe.RecipeJS;
|
||||||
@@ -14,7 +16,11 @@ public interface TradingRecipeSchema {
|
|||||||
RecipeKey<InputItem[]> INGREDIENTS = ItemComponents.INPUT_ARRAY.key("ingredients");
|
RecipeKey<InputItem[]> INGREDIENTS = ItemComponents.INPUT_ARRAY.key("ingredients");
|
||||||
RecipeKey<OutputItem> RESULT = ItemComponents.OUTPUT.key("result");
|
RecipeKey<OutputItem> RESULT = ItemComponents.OUTPUT.key("result");
|
||||||
RecipeKey<Integer> PROCESSING_TIME = NumberComponent.INT.key("processingTime").optional(1);
|
RecipeKey<Integer> PROCESSING_TIME = NumberComponent.INT.key("processingTime").optional(1);
|
||||||
public class TradingRecipeJS extends RecipeJS{
|
RecipeKey<BiomeCondition> BIOME = BiomeConditionComponent.BIOME_CONDITION.key("biome").allowEmpty().defaultOptional();
|
||||||
|
RecipeKey<ExclusiveToCondition> EXCLUSIVE_TO = ExclusiveToConditionComponent.EXCLUSIVE_CONDITION.key("exclusiveTo").allowEmpty().defaultOptional();
|
||||||
|
|
||||||
|
|
||||||
|
public class TradingRecipeJS extends RecipeJS{
|
||||||
@Override
|
@Override
|
||||||
public JsonElement writeInputItem(InputItem value) {
|
public JsonElement writeInputItem(InputItem value) {
|
||||||
JsonObject json = super.writeInputItem(value).getAsJsonObject();
|
JsonObject json = super.writeInputItem(value).getAsJsonObject();
|
||||||
@@ -24,6 +30,6 @@ public interface TradingRecipeSchema {
|
|||||||
return (JsonElement) json;
|
return (JsonElement) json;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RecipeSchema SCHEMA = new RecipeSchema(TradingRecipeJS.class, TradingRecipeJS::new, RESULT, INGREDIENTS, PROCESSING_TIME);
|
RecipeSchema SCHEMA = new RecipeSchema(TradingRecipeJS.class, TradingRecipeJS::new, RESULT, INGREDIENTS, PROCESSING_TIME,BIOME, EXCLUSIVE_TO);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ package com.oierbravo.trading_station.content.trading_recipe;
|
|||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
import com.oierbravo.trading_station.foundation.util.ModLang;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
@@ -96,10 +98,9 @@ public class BiomeCondition {
|
|||||||
}
|
}
|
||||||
protected boolean testInternal(Biome b, LevelAccessor pLevel){
|
protected boolean testInternal(Biome b, LevelAccessor pLevel){
|
||||||
if(biome == null)
|
if(biome == null)
|
||||||
return false;
|
return true;
|
||||||
if (biome.toString() != b.toString())
|
ResourceKey<Biome> key = pLevel.registryAccess().registryOrThrow(ForgeRegistries.BIOMES.getRegistryKey()).getResourceKey(b).get();
|
||||||
return false;
|
return Objects.equals(getKeyOrThrow(biome).toString(), key.location().toString());
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public void write(FriendlyByteBuf buffer) {
|
public void write(FriendlyByteBuf buffer) {
|
||||||
@@ -113,12 +114,21 @@ public class BiomeCondition {
|
|||||||
biome.readInternal(buffer);
|
biome.readInternal(buffer);
|
||||||
return biome;
|
return biome;
|
||||||
}
|
}
|
||||||
public JsonObject serialize() {
|
public JsonObject toJson() {
|
||||||
JsonObject json = new JsonObject();
|
JsonObject json = new JsonObject();
|
||||||
writeInternal(json);
|
writeInternal(json);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
public static BiomeCondition fromJson(@Nullable JsonElement je) {
|
||||||
|
if (!isBiomeCondition(je))
|
||||||
|
throw new JsonSyntaxException("Invalid biome condition: " + Objects.toString(je));
|
||||||
|
|
||||||
|
JsonObject json = je.getAsJsonObject();
|
||||||
|
BiomeCondition condition = json.has("tag") ? new BiomeTagCondition() : new BiomeCondition();
|
||||||
|
condition.readInternal(json);
|
||||||
|
|
||||||
|
return condition;
|
||||||
|
}
|
||||||
public static boolean isBiomeCondition(@Nullable JsonElement je) {
|
public static boolean isBiomeCondition(@Nullable JsonElement je) {
|
||||||
if (je == null || je.isJsonNull())
|
if (je == null || je.isJsonNull())
|
||||||
return false;
|
return false;
|
||||||
@@ -131,20 +141,12 @@ public class BiomeCondition {
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BiomeCondition deserialize(@Nullable JsonElement je) {
|
|
||||||
if (!isBiomeCondition(je))
|
|
||||||
throw new JsonSyntaxException("Invalid biome condition: " + Objects.toString(je));
|
|
||||||
|
|
||||||
JsonObject json = je.getAsJsonObject();
|
|
||||||
BiomeCondition condition = json.has("tag") ? new BiomeTagCondition() : new BiomeCondition();
|
|
||||||
condition.readInternal(json);
|
|
||||||
|
|
||||||
return condition;
|
|
||||||
}
|
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return toStringInternal();
|
return toStringInternal();
|
||||||
}
|
}
|
||||||
|
public Component toComponent(){
|
||||||
|
return ModLang.translate("trading.recipe.biome", toString());
|
||||||
|
}
|
||||||
|
|
||||||
protected String toStringInternal(){
|
protected String toStringInternal(){
|
||||||
if(biome == null)
|
if(biome == null)
|
||||||
@@ -152,6 +154,7 @@ public class BiomeCondition {
|
|||||||
return ForgeRegistries.BIOMES.getKey(biome).toString();
|
return ForgeRegistries.BIOMES.getKey(biome).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class BiomeTagCondition extends BiomeCondition {
|
public static class BiomeTagCondition extends BiomeCondition {
|
||||||
|
|
||||||
protected TagKey<Biome> tag;
|
protected TagKey<Biome> tag;
|
||||||
@@ -159,9 +162,8 @@ public class BiomeCondition {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean testInternal(Biome b, LevelAccessor pLevel) {
|
protected boolean testInternal(Biome b, LevelAccessor pLevel) {
|
||||||
Registry<Biome> biomeRegistry = pLevel.registryAccess().registryOrThrow(ForgeRegistries.BIOMES.getRegistryKey());
|
Registry<Biome> biomeRegistry = pLevel.registryAccess().registryOrThrow(ForgeRegistries.BIOMES.getRegistryKey());
|
||||||
ResourceKey<Biome> key = biomeRegistry.getResourceKey(b).get();
|
ResourceKey<Biome> key = biomeRegistry.getResourceKey(b).get();
|
||||||
boolean result = biomeRegistry.getOrCreateTag(tag).contains(biomeRegistry.getOrCreateHolderOrThrow(key));
|
|
||||||
return biomeRegistry.getOrCreateTag(tag).contains(biomeRegistry.getOrCreateHolderOrThrow(key));
|
return biomeRegistry.getOrCreateTag(tag).contains(biomeRegistry.getOrCreateHolderOrThrow(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,4 +196,5 @@ public class BiomeCondition {
|
|||||||
return "#" + tag.location().toString();
|
return "#" + tag.location().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,116 @@
|
|||||||
package com.oierbravo.trading_station.content.trading_recipe;
|
package com.oierbravo.trading_station.content.trading_recipe;
|
||||||
|
|
||||||
public class ExclusiveToCondition {
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
import net.minecraft.core.NonNullList;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.util.GsonHelper;
|
||||||
|
import net.minecraft.world.item.crafting.Ingredient;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
public class ExclusiveToCondition implements Predicate {
|
||||||
|
public static final ExclusiveToCondition EMPTY = new ExclusiveToCondition();
|
||||||
|
public NonNullList<String> exclusives;
|
||||||
|
|
||||||
|
public ExclusiveToCondition(){
|
||||||
|
exclusives = NonNullList.create();
|
||||||
|
}
|
||||||
|
public ExclusiveToCondition(NonNullList<String> pExclusives){
|
||||||
|
exclusives = pExclusives;
|
||||||
|
}
|
||||||
|
public static ExclusiveToCondition fromString(String exclusive) {
|
||||||
|
NonNullList<String> exclusives = NonNullList.create();
|
||||||
|
exclusives.add(exclusive);
|
||||||
|
return new ExclusiveToCondition(exclusives);
|
||||||
|
}
|
||||||
|
public static ExclusiveToCondition fromList(NonNullList<String> exclusives) {
|
||||||
|
return new ExclusiveToCondition(exclusives);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ExclusiveToCondition fromList(List<String> pExclusives) {
|
||||||
|
NonNullList<String> exclusives = NonNullList.create();
|
||||||
|
exclusives.addAll(pExclusives);
|
||||||
|
return new ExclusiveToCondition(exclusives);
|
||||||
|
}
|
||||||
|
public ExclusiveToCondition add(String value){
|
||||||
|
exclusives.add(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ExclusiveToCondition fromJson(@Nullable JsonElement je) {
|
||||||
|
ExclusiveToCondition condition = new ExclusiveToCondition();
|
||||||
|
if(je.isJsonNull())
|
||||||
|
return condition;
|
||||||
|
if(je.isJsonArray()){
|
||||||
|
condition.readInternal((JsonArray) je);
|
||||||
|
return condition;
|
||||||
|
}
|
||||||
|
JsonObject jsonObject = je.getAsJsonObject();
|
||||||
|
if(jsonObject.has("exclusivesTo"))
|
||||||
|
condition.readInternal(jsonObject.getAsJsonArray("exclusivesTo"));
|
||||||
|
return condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonElement toJson() {
|
||||||
|
JsonArray json = new JsonArray();
|
||||||
|
writeInternal(json);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
/*public JsonArray toJsonArray(){
|
||||||
|
|
||||||
|
}*/
|
||||||
|
protected void readInternal(FriendlyByteBuf buffer){
|
||||||
|
NonNullList<String> exclusives = NonNullList.create();
|
||||||
|
|
||||||
|
int size = buffer.readVarInt();
|
||||||
|
for (int i = 0; i < size; i++)
|
||||||
|
exclusives.add(buffer.readUtf());
|
||||||
|
this.exclusives = exclusives;
|
||||||
|
};
|
||||||
|
public void write(FriendlyByteBuf buffer) {
|
||||||
|
writeInternal(buffer);
|
||||||
|
}
|
||||||
|
protected void writeInternal(FriendlyByteBuf buffer){
|
||||||
|
buffer.writeVarInt(exclusives.size());
|
||||||
|
exclusives.forEach(buffer::writeUtf);
|
||||||
|
};
|
||||||
|
public static ExclusiveToCondition read(FriendlyByteBuf buffer) {
|
||||||
|
ExclusiveToCondition condition = new ExclusiveToCondition();
|
||||||
|
condition.readInternal(buffer);
|
||||||
|
return condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void readInternal(JsonArray json){
|
||||||
|
NonNullList<String> exclusivesList = NonNullList.create();
|
||||||
|
json.forEach(element -> {
|
||||||
|
exclusivesList.add(element.getAsString());
|
||||||
|
});
|
||||||
|
this.exclusives = exclusivesList;
|
||||||
|
};
|
||||||
|
protected void readInternal(String element){
|
||||||
|
NonNullList<String> exclusives = NonNullList.create();
|
||||||
|
exclusives.add(element);
|
||||||
|
this.exclusives = exclusives;
|
||||||
|
};
|
||||||
|
|
||||||
|
protected void writeInternal(JsonArray jsonArray){
|
||||||
|
for (String exclusive : exclusives) {
|
||||||
|
jsonArray.add(exclusive.toString());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@Override
|
||||||
|
public boolean test(Object o) {
|
||||||
|
if(exclusives.isEmpty())
|
||||||
|
return true;
|
||||||
|
return exclusives.contains(o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ import net.minecraft.world.SimpleContainer;
|
|||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.crafting.*;
|
import net.minecraft.world.item.crafting.*;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class TradingRecipe implements Recipe<SimpleContainer> {
|
public class TradingRecipe implements Recipe<SimpleContainer> {
|
||||||
private final ResourceLocation id;
|
private final ResourceLocation id;
|
||||||
@@ -20,22 +23,41 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
|||||||
|
|
||||||
private final int processingTime;
|
private final int processingTime;
|
||||||
|
|
||||||
|
private BiomeCondition biomeCondition;
|
||||||
|
private ExclusiveToCondition exclusiveToCondition;
|
||||||
|
|
||||||
|
|
||||||
public TradingRecipe(TradingRecipeParams params) {
|
public TradingRecipe(TradingRecipeParams params) {
|
||||||
this.id = params.id;
|
this.id = params.id;
|
||||||
this.result = params.result;
|
this.result = params.result;
|
||||||
this.itemIngredients = params.itemIngredients;
|
this.itemIngredients = params.itemIngredients;
|
||||||
this.processingTime = params.processingTime;
|
this.processingTime = params.processingTime;
|
||||||
|
this.biomeCondition = params.biome;
|
||||||
|
this.exclusiveToCondition = params.exclusiveTo;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(SimpleContainer pContainer, Level pLevel) {
|
public boolean matches(SimpleContainer pContainer, Level pLevel) {
|
||||||
|
return matches(pContainer, pLevel, (Biome) null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean matchesBiome(Biome biome, Level pLevel){
|
||||||
|
return biomeCondition.test(biome, pLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean matchesExclusiveTo(String targetedMachine){
|
||||||
|
return exclusiveToCondition.test(targetedMachine);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean matches(SimpleContainer pContainer, Level pLevel, @Nullable Biome biome) {
|
||||||
if(pLevel.isClientSide)
|
if(pLevel.isClientSide)
|
||||||
return false;
|
return false;
|
||||||
if(pContainer.getContainerSize() != itemIngredients.size())
|
if(pContainer.getContainerSize() != itemIngredients.size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if(!getBiomeCondition().test(biome,pLevel))
|
||||||
|
return false;
|
||||||
|
|
||||||
int matchedIngredients = 0;
|
int matchedIngredients = 0;
|
||||||
for (int i = 0; i < itemIngredients.size(); i++) {
|
for (int i = 0; i < itemIngredients.size(); i++) {
|
||||||
Ingredient ingredient = itemIngredients.get(i);
|
Ingredient ingredient = itemIngredients.get(i);
|
||||||
@@ -76,8 +98,18 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
|||||||
public boolean canCraftInDimensions(int pWidth, int pHeight) {
|
public boolean canCraftInDimensions(int pWidth, int pHeight) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
public int getProcessingTime() {
|
||||||
|
return processingTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public BiomeCondition getBiomeCondition(){
|
||||||
|
return biomeCondition;
|
||||||
|
}
|
||||||
|
public ExclusiveToCondition getExclusiveToCondition(){
|
||||||
|
return exclusiveToCondition;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getResultItem() {
|
public ItemStack getResultItem() {
|
||||||
return result.copy();
|
return result.copy();
|
||||||
@@ -86,6 +118,7 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
|||||||
return result.copy();
|
return result.copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getId() {
|
public ResourceLocation getId() {
|
||||||
return id;
|
return id;
|
||||||
@@ -103,6 +136,7 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
|||||||
public static class Type implements RecipeType<TradingRecipe> {
|
public static class Type implements RecipeType<TradingRecipe> {
|
||||||
private Type() { }
|
private Type() { }
|
||||||
public static final Type INSTANCE = new Type();
|
public static final Type INSTANCE = new Type();
|
||||||
|
public static final RecipeType<TradingRecipe> RECIPE_TYPE = new Type();
|
||||||
public static final String ID = "trading";
|
public static final String ID = "trading";
|
||||||
}
|
}
|
||||||
public static class Serializer implements RecipeSerializer<TradingRecipe> {
|
public static class Serializer implements RecipeSerializer<TradingRecipe> {
|
||||||
@@ -115,6 +149,8 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
|||||||
TradingRecipeBuilder builder = new TradingRecipeBuilder(id);
|
TradingRecipeBuilder builder = new TradingRecipeBuilder(id);
|
||||||
NonNullList<Ingredient> itemIngredients = NonNullList.create();
|
NonNullList<Ingredient> itemIngredients = NonNullList.create();
|
||||||
int processingTime = 1;
|
int processingTime = 1;
|
||||||
|
BiomeCondition biomeCondition = BiomeCondition.EMPTY;
|
||||||
|
ExclusiveToCondition exclusiveToCondition = ExclusiveToCondition.EMPTY;
|
||||||
|
|
||||||
for (JsonElement je : GsonHelper.getAsJsonArray(json, "ingredients")) {
|
for (JsonElement je : GsonHelper.getAsJsonArray(json, "ingredients")) {
|
||||||
JsonObject jsonObject = je.getAsJsonObject();
|
JsonObject jsonObject = je.getAsJsonObject();
|
||||||
@@ -133,9 +169,19 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
|||||||
processingTime = GsonHelper.getAsInt(json,"processingTime");
|
processingTime = GsonHelper.getAsInt(json,"processingTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(GsonHelper.isValidNode(json,"biome")){
|
||||||
|
biomeCondition = BiomeCondition.fromJson(json.get("biome"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(GsonHelper.isValidNode(json,"exclusiveTo")){
|
||||||
|
exclusiveToCondition = ExclusiveToCondition.fromJson(json.get("exclusiveTo"));
|
||||||
|
}
|
||||||
|
|
||||||
builder.withItemIngredients(itemIngredients)
|
builder.withItemIngredients(itemIngredients)
|
||||||
.withSingleItemOutput(result)
|
.withSingleItemOutput(result)
|
||||||
.processingTime(processingTime);
|
.processingTime(processingTime)
|
||||||
|
.withBiomeCondition(biomeCondition)
|
||||||
|
.exclusiveTo(exclusiveToCondition);
|
||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
@@ -145,6 +191,8 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
|||||||
TradingRecipeBuilder builder = new TradingRecipeBuilder(id);
|
TradingRecipeBuilder builder = new TradingRecipeBuilder(id);
|
||||||
NonNullList<Ingredient> itemIngredients = NonNullList.create();
|
NonNullList<Ingredient> itemIngredients = NonNullList.create();
|
||||||
int processingTime = 1;
|
int processingTime = 1;
|
||||||
|
BiomeCondition biomeCondition = BiomeCondition.EMPTY;
|
||||||
|
ExclusiveToCondition exclusiveToCondition = ExclusiveToCondition.EMPTY;
|
||||||
|
|
||||||
int size = buffer.readVarInt();
|
int size = buffer.readVarInt();
|
||||||
for (int i = 0; i < size; i++)
|
for (int i = 0; i < size; i++)
|
||||||
@@ -152,11 +200,17 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
|||||||
|
|
||||||
ItemStack result = buffer.readItem();
|
ItemStack result = buffer.readItem();
|
||||||
processingTime = buffer.readInt();
|
processingTime = buffer.readInt();
|
||||||
|
biomeCondition = BiomeCondition.read(buffer);
|
||||||
|
exclusiveToCondition = exclusiveToCondition.read(buffer);
|
||||||
|
|
||||||
|
|
||||||
builder.withItemIngredients(itemIngredients)
|
builder.withItemIngredients(itemIngredients)
|
||||||
.withSingleItemOutput(result)
|
.withSingleItemOutput(result)
|
||||||
.processingTime(processingTime);
|
.processingTime(processingTime)
|
||||||
|
.withBiomeCondition(biomeCondition)
|
||||||
|
.exclusiveTo(exclusiveToCondition);
|
||||||
|
|
||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,18 +218,19 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
|||||||
public void toNetwork(FriendlyByteBuf buffer, TradingRecipe recipe) {
|
public void toNetwork(FriendlyByteBuf buffer, TradingRecipe recipe) {
|
||||||
NonNullList<Ingredient> itemIngredients = recipe.itemIngredients;
|
NonNullList<Ingredient> itemIngredients = recipe.itemIngredients;
|
||||||
int processingTime = recipe.getProcessingTime();
|
int processingTime = recipe.getProcessingTime();
|
||||||
|
BiomeCondition biomeCondition = recipe.getBiomeCondition();
|
||||||
|
ExclusiveToCondition exclusiveToCondition = recipe.getExclusiveToCondition();
|
||||||
|
|
||||||
buffer.writeVarInt(itemIngredients.size());
|
buffer.writeVarInt(itemIngredients.size());
|
||||||
itemIngredients.forEach(i -> i.toNetwork(buffer));
|
itemIngredients.forEach(i -> i.toNetwork(buffer));
|
||||||
buffer.writeItem(recipe.getResultItem());
|
buffer.writeItem(recipe.getResultItem());
|
||||||
buffer.writeInt(processingTime);
|
buffer.writeInt(processingTime);
|
||||||
|
biomeCondition.write(buffer);
|
||||||
|
exclusiveToCondition.write(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getProcessingTime() {
|
|
||||||
return processingTime;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,21 @@ public class TradingRecipeBuilder {
|
|||||||
params.processingTime = time;
|
params.processingTime = time;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public TradingRecipeBuilder exclusiveTo(NonNullList<String> exclusiveTo) {
|
||||||
|
return exclusiveTo(ExclusiveToCondition.fromList(exclusiveTo));
|
||||||
|
}
|
||||||
|
public TradingRecipeBuilder exclusiveTo(String exclusiveTo) {
|
||||||
|
return exclusiveTo(ExclusiveToCondition.fromString(exclusiveTo));
|
||||||
|
}
|
||||||
|
public TradingRecipeBuilder exclusiveTo(ExclusiveToCondition exclusiveToCondition) {
|
||||||
|
params.exclusiveTo = exclusiveToCondition;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TradingRecipeBuilder withBiomeCondition(BiomeCondition biomeCondition) {
|
||||||
|
params.biome = biomeCondition;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public TradingRecipe build(){
|
public TradingRecipe build(){
|
||||||
@@ -53,6 +68,9 @@ public class TradingRecipeBuilder {
|
|||||||
protected ItemStack result;
|
protected ItemStack result;
|
||||||
protected int fuelConsumed;
|
protected int fuelConsumed;
|
||||||
protected int processingTime;
|
protected int processingTime;
|
||||||
|
protected BiomeCondition biome;
|
||||||
|
public ExclusiveToCondition exclusiveTo;
|
||||||
|
|
||||||
|
|
||||||
protected TradingRecipeParams(ResourceLocation id) {
|
protected TradingRecipeParams(ResourceLocation id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@@ -60,6 +78,8 @@ public class TradingRecipeBuilder {
|
|||||||
result = ItemStack.EMPTY;
|
result = ItemStack.EMPTY;
|
||||||
fuelConsumed = 0;
|
fuelConsumed = 0;
|
||||||
processingTime = 1;
|
processingTime = 1;
|
||||||
|
biome = BiomeCondition.EMPTY;
|
||||||
|
exclusiveTo = ExclusiveToCondition.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,21 @@
|
|||||||
package com.oierbravo.trading_station.content.trading_station;
|
package com.oierbravo.trading_station.content.trading_station;
|
||||||
|
|
||||||
|
import com.oierbravo.trading_station.content.trading_recipe.TradingRecipe;
|
||||||
import com.oierbravo.trading_station.network.packets.ItemStackSyncS2CPacket;
|
import com.oierbravo.trading_station.network.packets.ItemStackSyncS2CPacket;
|
||||||
|
import com.oierbravo.trading_station.registrate.ModRecipes;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.SimpleContainer;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.crafting.Ingredient;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
import net.minecraftforge.energy.IEnergyStorage;
|
import net.minecraftforge.energy.IEnergyStorage;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
import net.minecraftforge.items.ItemStackHandler;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface ITradingStationBlockEntity {
|
public interface ITradingStationBlockEntity {
|
||||||
public int progress = 0;
|
public int progress = 0;
|
||||||
@@ -16,16 +25,99 @@ public interface ITradingStationBlockEntity {
|
|||||||
|
|
||||||
IItemHandler getTargetItemHandler();
|
IItemHandler getTargetItemHandler();
|
||||||
|
|
||||||
BlockPos getBlockPos();
|
|
||||||
|
|
||||||
ItemStack getTargetItemStack();
|
ItemStack getTargetItemStack();
|
||||||
|
|
||||||
Level getLevel();
|
Level getLevel();
|
||||||
|
|
||||||
|
BlockPos getBlockPos();
|
||||||
|
|
||||||
void setPreferedItem(ItemStack itemStack);
|
void setPreferedItem(ItemStack itemStack);
|
||||||
|
|
||||||
void setItemStack(int slot, ItemStack itemStack, ItemStackSyncS2CPacket.SlotType slotType);
|
void setItemStack(int slot, ItemStack itemStack, ItemStackSyncS2CPacket.SlotType slotType);
|
||||||
|
|
||||||
|
|
||||||
IEnergyStorage getEnergyStorage();
|
IEnergyStorage getEnergyStorage();
|
||||||
|
byte currentRedstoneMode = 0;
|
||||||
|
default byte getRedstoneMode(){
|
||||||
|
return currentRedstoneMode;
|
||||||
|
};
|
||||||
|
|
||||||
|
String getTraderType();
|
||||||
|
|
||||||
|
enum REDSTONE_MODES {
|
||||||
|
IGNORE,
|
||||||
|
LOW,
|
||||||
|
HIGH
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
boolean canCraftItem();
|
||||||
|
boolean canProcess(ItemStack stack);
|
||||||
|
void resetProgress();
|
||||||
|
|
||||||
|
default int getProcessingTime(){
|
||||||
|
return getRecipe().map(TradingRecipe::getProcessingTime).orElse(1);
|
||||||
|
}
|
||||||
|
default int getProgressPercent() {
|
||||||
|
return progress * 100 / maxProgress;
|
||||||
|
}
|
||||||
|
default Optional<TradingRecipe> getRecipe(){
|
||||||
|
Level level = this.getLevel();
|
||||||
|
SimpleContainer inputInventory = getInputInventory();
|
||||||
|
if(!getTargetItemHandler().getStackInSlot(0).isEmpty())
|
||||||
|
return ModRecipes.findByOutput(level,getTargetItemHandler().getStackInSlot(0));
|
||||||
|
return ModRecipes.find(inputInventory,level, getBiome());
|
||||||
|
};
|
||||||
|
default SimpleContainer getInputInventory(){
|
||||||
|
int containerSize = 0;
|
||||||
|
for(int index = 0; index < getInputItems().getSlots(); index++) {
|
||||||
|
if (!getInputItems().getStackInSlot(index).isEmpty())
|
||||||
|
containerSize++;
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleContainer inputInventory = new SimpleContainer(containerSize);
|
||||||
|
getInputItemHandler().ifPresent(iItemHandler -> {
|
||||||
|
for(int slot = 0; slot < iItemHandler.getSlots(); slot++) {
|
||||||
|
if(!iItemHandler.getStackInSlot(slot).isEmpty()){
|
||||||
|
inputInventory.addItem(iItemHandler.getStackInSlot(slot));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return inputInventory;
|
||||||
|
}
|
||||||
|
default void craftItem() {
|
||||||
|
SimpleContainer inputInventory = getInputInventory();
|
||||||
|
|
||||||
|
Optional<TradingRecipe> recipe = getRecipe();
|
||||||
|
|
||||||
|
if(recipe.isPresent()){
|
||||||
|
for (int i = 0; i < recipe.get().getIngredients().size(); i++) {
|
||||||
|
Ingredient ingredient = recipe.get().getIngredients().get(i);
|
||||||
|
|
||||||
|
for (int slot = 0; slot < getInputItems().getSlots(); slot++) {
|
||||||
|
ItemStack itemStack = getInputItems().getStackInSlot(slot);
|
||||||
|
if(ingredient.test(itemStack)){
|
||||||
|
getInputItems().extractItem(slot,ingredient.getItems()[0].getCount(),false);
|
||||||
|
inputInventory.setChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getOutputItems().insertItem(0, recipe.get().getResultItem(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.resetProgress();
|
||||||
|
}
|
||||||
|
ItemStackHandler getInputItems();
|
||||||
|
ItemStackHandler getOutputItems();
|
||||||
|
|
||||||
|
void setRedstoneMode(byte mode);
|
||||||
|
byte getCurrentRedstoneMode();
|
||||||
|
boolean isPowered();
|
||||||
|
|
||||||
|
default Biome getBiome(){
|
||||||
|
return this.getLevel().getBiome(getBlockPos()).get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.oierbravo.trading_station.content.trading_station;
|
package com.oierbravo.trading_station.content.trading_station;
|
||||||
|
|
||||||
import com.oierbravo.trading_station.registrate.PoweredTradingStationRegistrate;
|
|
||||||
import com.oierbravo.trading_station.registrate.TradingStationRegistrate;
|
import com.oierbravo.trading_station.registrate.TradingStationRegistrate;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
@@ -35,8 +34,9 @@ import static net.minecraft.world.level.block.state.properties.BlockStatePropert
|
|||||||
|
|
||||||
public class TradingStationBlock extends BaseEntityBlock {
|
public class TradingStationBlock extends BaseEntityBlock {
|
||||||
public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
|
public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
|
||||||
|
public static final BooleanProperty LIT = BlockStateProperties.LIT;
|
||||||
|
|
||||||
private static final VoxelShape RENDER_SHAPE = Shapes.box(0, 0, 0, 1, 1, 1);
|
private static final VoxelShape RENDER_SHAPE = Shapes.box(0, 0, 0, 0.9, 0.9, 0.9);
|
||||||
//public static final BooleanProperty BOTTOM = BlockStateProperties.BOTTOM;
|
//public static final BooleanProperty BOTTOM = BlockStateProperties.BOTTOM;
|
||||||
|
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ public class TradingStationBlock extends BaseEntityBlock {
|
|||||||
|
|
||||||
public TradingStationBlock(Properties pProperties) {
|
public TradingStationBlock(Properties pProperties) {
|
||||||
super(pProperties);
|
super(pProperties);
|
||||||
registerDefaultState(getStateDefinition().any().setValue(HORIZONTAL_FACING, Direction.NORTH).setValue(POWERED,false));
|
registerDefaultState(getStateDefinition().any().setValue(HORIZONTAL_FACING, Direction.NORTH).setValue(POWERED,false).setValue(LIT,false));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,11 +65,12 @@ public class TradingStationBlock extends BaseEntityBlock {
|
|||||||
return null;
|
return null;
|
||||||
return super.getStateForPlacement(context)
|
return super.getStateForPlacement(context)
|
||||||
.setValue(HORIZONTAL_FACING, context.getHorizontalDirection().getOpposite())
|
.setValue(HORIZONTAL_FACING, context.getHorizontalDirection().getOpposite())
|
||||||
.setValue(POWERED, context.getLevel().hasNeighborSignal(context.getClickedPos()));
|
.setValue(POWERED, context.getLevel().hasNeighborSignal(context.getClickedPos()))
|
||||||
|
.setValue(LIT,false);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||||
builder.add(HORIZONTAL_FACING).add(POWERED);
|
builder.add(HORIZONTAL_FACING).add(POWERED).add(LIT);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public RenderShape getRenderShape(BlockState pState) {
|
public RenderShape getRenderShape(BlockState pState) {
|
||||||
@@ -79,7 +80,7 @@ public class TradingStationBlock extends BaseEntityBlock {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
|
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
|
||||||
return TradingStationRegistrate.TRADING_STATION_BLOCK_ENTITY.create(pPos, pState);
|
return TradingStationRegistrate.BLOCK_ENTITY.create(pPos, pState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -95,7 +96,7 @@ public class TradingStationBlock extends BaseEntityBlock {
|
|||||||
if(pLevel.isClientSide()) {
|
if(pLevel.isClientSide()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return createTickerHelper(pBlockEntityType, TradingStationRegistrate.TRADING_STATION_BLOCK_ENTITY.get(),
|
return createTickerHelper(pBlockEntityType, TradingStationRegistrate.BLOCK_ENTITY.get(),
|
||||||
(pLevel1, pPos, pState1, pBlockEntity) -> pBlockEntity.tick(pLevel1, pPos, pState1));
|
(pLevel1, pPos, pState1, pBlockEntity) -> pBlockEntity.tick(pLevel1, pPos, pState1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import net.minecraft.world.item.Item;
|
|||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.crafting.Ingredient;
|
import net.minecraft.world.item.crafting.Ingredient;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.AbstractFurnaceBlock;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
@@ -54,23 +55,29 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
|||||||
|
|
||||||
public int progress = 0;
|
public int progress = 0;
|
||||||
public int maxProgress = 1;
|
public int maxProgress = 1;
|
||||||
|
|
||||||
|
private int lastProgress = 0;
|
||||||
|
private boolean isWorking = false;
|
||||||
private BlockState lastBlockState;
|
private BlockState lastBlockState;
|
||||||
|
|
||||||
protected final ContainerData containerData;
|
protected final ContainerData containerData;
|
||||||
|
|
||||||
|
byte currentRedstoneMode = 0;
|
||||||
|
|
||||||
public TradingStationBlockEntity(BlockEntityType<?> pType, BlockPos pWorldPosition, BlockState pBlockState) {
|
public TradingStationBlockEntity(BlockEntityType<?> pType, BlockPos pWorldPosition, BlockState pBlockState) {
|
||||||
super(pType, pWorldPosition, pBlockState);
|
super(pType, pWorldPosition, pBlockState);
|
||||||
updateTag = getPersistentData();
|
updateTag = getPersistentData();
|
||||||
lastBlockState = this.getBlockState();
|
lastBlockState = this.getBlockState();
|
||||||
containerData = TradingStationBlockEntity.createContainerData(this);
|
containerData = createContainerData();
|
||||||
}
|
}
|
||||||
public static ContainerData createContainerData(TradingStationBlockEntity pBlockEntity){
|
public ContainerData createContainerData(){
|
||||||
return new ContainerData(){
|
return new ContainerData(){
|
||||||
@Override
|
@Override
|
||||||
public int get(int pIndex){
|
public int get(int pIndex){
|
||||||
return switch (pIndex) {
|
return switch (pIndex) {
|
||||||
case 0 -> pBlockEntity.progress;
|
case 0 -> progress;
|
||||||
case 1 -> pBlockEntity.maxProgress;
|
case 1 -> maxProgress;
|
||||||
|
case 2 -> (int) currentRedstoneMode;
|
||||||
default -> 0;
|
default -> 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -79,14 +86,15 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
|||||||
@Override
|
@Override
|
||||||
public void set(int pIndex, int pValue) {
|
public void set(int pIndex, int pValue) {
|
||||||
switch (pIndex) {
|
switch (pIndex) {
|
||||||
case 0 -> pBlockEntity.progress = pValue;
|
case 0 -> progress = pValue;
|
||||||
case 1 -> pBlockEntity.maxProgress = pValue;
|
case 1 -> maxProgress = pValue;
|
||||||
|
case 2 -> currentRedstoneMode = (byte) pValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return 2;
|
return 3;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -169,9 +177,16 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
|
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
|
||||||
if (cap == ForgeCapabilities.ITEM_HANDLER) {
|
if(side == Direction.UP)
|
||||||
|
return super.getCapability(cap, side);
|
||||||
|
if(cap == ForgeCapabilities.ITEM_HANDLER){
|
||||||
|
if(side == Direction.DOWN)
|
||||||
|
return outputItemHandler.cast();
|
||||||
|
|
||||||
|
Direction localDir = this.getBlockState().getValue(BlockStateProperties.HORIZONTAL_FACING);
|
||||||
return inputItemHandler.cast();
|
return inputItemHandler.cast();
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.getCapability(cap, side);
|
return super.getCapability(cap, side);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,6 +222,7 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
|||||||
tag.put("target", targetItemHandler.serializeNBT());
|
tag.put("target", targetItemHandler.serializeNBT());
|
||||||
tag.putInt("trading_station.progress", progress);
|
tag.putInt("trading_station.progress", progress);
|
||||||
tag.putInt("trading_station.maxProgress", maxProgress);
|
tag.putInt("trading_station.maxProgress", maxProgress);
|
||||||
|
tag.putByte("redstoneMode", currentRedstoneMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -217,6 +233,7 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
|||||||
targetItemHandler.deserializeNBT(tag.getCompound("target"));
|
targetItemHandler.deserializeNBT(tag.getCompound("target"));
|
||||||
progress = tag.getInt("trading_station.progress");
|
progress = tag.getInt("trading_station.progress");
|
||||||
maxProgress = tag.getInt("trading_station.maxProgress");
|
maxProgress = tag.getInt("trading_station.maxProgress");
|
||||||
|
currentRedstoneMode = tag.getByte("redstoneMode");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drops() {
|
public void drops() {
|
||||||
@@ -235,89 +252,75 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
|||||||
this.maxProgress = 1;
|
this.maxProgress = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Optional<TradingRecipe> getRecipe(TradingStationBlockEntity pBlockEntity){
|
|
||||||
Level level = pBlockEntity.getLevel();
|
|
||||||
SimpleContainer inputInventory = getInputInventory(pBlockEntity);
|
|
||||||
if(!pBlockEntity.targetItemHandler.getStackInSlot(0).isEmpty())
|
|
||||||
return ModRecipes.findByOutput(level,pBlockEntity.targetItemHandler.getStackInSlot(0));
|
|
||||||
return ModRecipes.find(inputInventory,level);
|
|
||||||
// return level.getRecipeManager().getRecipeFor(TradingRecipe.Type.INSTANCE, inputInventory, level);
|
|
||||||
}
|
|
||||||
protected int getProcessingTime(TradingStationBlockEntity pBlockEntity) {
|
|
||||||
return getRecipe(pBlockEntity).map(TradingRecipe::getProcessingTime).orElse(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tick(Level pLevel, BlockPos pPos, BlockState pState) {
|
public void tick(Level pLevel, BlockPos pPos, BlockState pState) {
|
||||||
|
|
||||||
if(pLevel.isClientSide()) {
|
if(pLevel.isClientSide()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!isPowered(this))
|
if(!isPowered()) {
|
||||||
|
setWorking(false);
|
||||||
return;
|
return;
|
||||||
if(!canCraftItem())
|
}
|
||||||
|
if(!canCraftItem()) {
|
||||||
|
setWorking(false);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.updateProgress();
|
updateProgress();
|
||||||
BlockEntity.setChanged(pLevel, pPos, pState);
|
setWorking(true);
|
||||||
this.maxProgress = this.getProcessingTime(this);
|
|
||||||
if (this.progress > this.maxProgress) {
|
maxProgress = getProcessingTime();
|
||||||
|
if (progress > maxProgress) {
|
||||||
craftItem();
|
craftItem();
|
||||||
}
|
}
|
||||||
BlockEntity.setChanged(pLevel, pPos, pState);
|
|
||||||
|
setChanged(pLevel, pPos, pState);
|
||||||
|
|
||||||
|
}
|
||||||
|
private void setWorking(boolean value){
|
||||||
|
if(isWorking != value){
|
||||||
|
isWorking = value;
|
||||||
|
BlockState pState = getBlockState().setValue(AbstractFurnaceBlock.LIT, Boolean.valueOf(isWorking()));
|
||||||
|
|
||||||
|
// if(lastBlockState.getValue(BlockStateProperties.LIT) != pState.getValue(BlockStateProperties.LIT)){
|
||||||
|
// lastBlockState = pState;
|
||||||
|
getLevel().setBlock(getBlockPos(), pState, 3);
|
||||||
|
setChanged(getLevel(), getBlockPos(), pState);
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isWorking() {
|
||||||
|
return isWorking;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateProgress(){
|
protected void updateProgress(){
|
||||||
this.progress += TradingStationConfig.PROGRESS_PER_TICK.get();
|
this.progress += TradingStationConfig.PROGRESS_PER_TICK.get();
|
||||||
|
|
||||||
}
|
}
|
||||||
private static boolean isPowered(TradingStationBlockEntity pBlockEntity){
|
public boolean isPowered() {
|
||||||
return pBlockEntity.getLevel().getBlockState(pBlockEntity.getBlockPos())
|
if(currentRedstoneMode == REDSTONE_MODES.IGNORE.ordinal())
|
||||||
|
return true;
|
||||||
|
if(currentRedstoneMode == REDSTONE_MODES.LOW.ordinal())
|
||||||
|
return !this.getLevel().getBlockState(getBlockPos())
|
||||||
|
.getValue(BlockStateProperties.POWERED);
|
||||||
|
|
||||||
|
return this.getLevel().getBlockState(getBlockPos())
|
||||||
.getValue(BlockStateProperties.POWERED);
|
.getValue(BlockStateProperties.POWERED);
|
||||||
}
|
}
|
||||||
private static SimpleContainer getInputInventory(TradingStationBlockEntity pBlockEntity){
|
|
||||||
int containerSize = 0;
|
|
||||||
for(int index = 0; index < pBlockEntity.inputItems.getSlots(); index++) {
|
|
||||||
if (!pBlockEntity.inputItems.getStackInSlot(index).isEmpty())
|
|
||||||
containerSize++;
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleContainer inputInventory = new SimpleContainer(containerSize);
|
|
||||||
pBlockEntity.inputItemHandler.ifPresent(iItemHandler -> {
|
|
||||||
for(int slot = 0; slot < iItemHandler.getSlots(); slot++) {
|
|
||||||
if(!iItemHandler.getStackInSlot(slot).isEmpty()){
|
|
||||||
inputInventory.addItem(iItemHandler.getStackInSlot(slot));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return inputInventory;
|
|
||||||
}
|
|
||||||
private void craftItem() {
|
|
||||||
SimpleContainer inputInventory = getInputInventory(this);
|
|
||||||
|
|
||||||
Optional<TradingRecipe> recipe = getRecipe(this);
|
|
||||||
|
|
||||||
if(recipe.isPresent()){
|
|
||||||
for (int i = 0; i < recipe.get().getIngredients().size(); i++) {
|
|
||||||
Ingredient ingredient = recipe.get().getIngredients().get(i);
|
|
||||||
|
|
||||||
for (int slot = 0; slot < this.inputItems.getSlots(); slot++) {
|
|
||||||
ItemStack itemStack = this.inputItems.getStackInSlot(slot);
|
|
||||||
if(ingredient.test(itemStack)){
|
|
||||||
this.inputItems.extractItem(slot,ingredient.getItems()[0].getCount(),false);
|
|
||||||
inputInventory.setChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.outputItems.insertItem(0, recipe.get().getResultItem(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.resetProgress();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected boolean canCraftItem() {
|
|
||||||
SimpleContainer inputInventory = getInputInventory(this);
|
|
||||||
Optional<TradingRecipe> match = getRecipe(this);
|
|
||||||
|
public boolean canCraftItem() {
|
||||||
|
SimpleContainer inputInventory = getInputInventory();
|
||||||
|
Optional<TradingRecipe> match = getRecipe();
|
||||||
|
|
||||||
if(!match.isPresent()) {
|
if(!match.isPresent()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -326,9 +329,9 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
|||||||
&& hasEnoughOutputSpace(this.outputItems, match.get().getResultItem());
|
&& hasEnoughOutputSpace(this.outputItems, match.get().getResultItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canProcess(ItemStack stack) {
|
public boolean canProcess(ItemStack stack) {
|
||||||
|
|
||||||
return getRecipe(this).isPresent();
|
return getRecipe().isPresent();
|
||||||
}
|
}
|
||||||
protected boolean hasEnoughInputItems(SimpleContainer inventory, NonNullList<Ingredient> ingredients){
|
protected boolean hasEnoughInputItems(SimpleContainer inventory, NonNullList<Ingredient> ingredients){
|
||||||
int enough = 0;
|
int enough = 0;
|
||||||
@@ -376,6 +379,27 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
|||||||
return this.progress * 100 / this.maxProgress;
|
return this.progress * 100 / this.maxProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStackHandler getInputItems() {
|
||||||
|
return inputItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStackHandler getOutputItems() {
|
||||||
|
return outputItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRedstoneMode(byte mode) {
|
||||||
|
currentRedstoneMode = mode;
|
||||||
|
setChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getCurrentRedstoneMode() {
|
||||||
|
return currentRedstoneMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setItemStack(int slot, ItemStack itemStack,ItemStackSyncS2CPacket.SlotType slotType) {
|
public void setItemStack(int slot, ItemStack itemStack,ItemStackSyncS2CPacket.SlotType slotType) {
|
||||||
if(slotType == ItemStackSyncS2CPacket.SlotType.INPUT)
|
if(slotType == ItemStackSyncS2CPacket.SlotType.INPUT)
|
||||||
@@ -392,15 +416,20 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTraderType() {
|
||||||
|
return "basic";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getDisplayName() {
|
public Component getDisplayName() {
|
||||||
return ModLang.translate("block.display");
|
return Component.translatable("block.trading_station.trading_station");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) {
|
public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) {
|
||||||
return new TradingStationMenu(pContainerId, pPlayerInventory, this, this.containerData);
|
return new TradingStationMenu(pContainerId, pPlayerInventory, this, containerData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferedItem(ItemStack itemStack) {
|
public void setPreferedItem(ItemStack itemStack) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.oierbravo.trading_station.content.trading_station;
|
package com.oierbravo.trading_station.content.trading_station;
|
||||||
|
|
||||||
import com.oierbravo.trading_station.foundation.gui.AbstractTradingMenu;
|
import com.oierbravo.trading_station.foundation.gui.AbstractTradingMenu;
|
||||||
|
import com.oierbravo.trading_station.foundation.gui.Coords2D;
|
||||||
import com.oierbravo.trading_station.registrate.TradingStationRegistrate;
|
import com.oierbravo.trading_station.registrate.TradingStationRegistrate;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
@@ -12,14 +13,13 @@ import net.minecraft.world.level.block.entity.BlockEntity;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class TradingStationMenu extends AbstractTradingMenu {
|
public class TradingStationMenu extends AbstractTradingMenu {
|
||||||
protected final int[] outputSlotCoords = {131,38};
|
|
||||||
|
|
||||||
public TradingStationMenu(int pContainerId, Inventory pInv, BlockEntity pBlockEntity, ContainerData pData) {
|
public TradingStationMenu(int pContainerId, Inventory pInv, BlockEntity pBlockEntity, ContainerData pData) {
|
||||||
super(TradingStationRegistrate.TRADING_STATION_MENU.get(), pContainerId, pInv, pBlockEntity, pData);
|
super(TradingStationRegistrate.MENU.get(), pContainerId, pInv, pBlockEntity, pData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TradingStationMenu(int pContainerId, Inventory inventory, FriendlyByteBuf buf) {
|
public TradingStationMenu(int pContainerId, Inventory inventory, FriendlyByteBuf buf) {
|
||||||
super(TradingStationRegistrate.TRADING_STATION_MENU.get(), pContainerId, inventory, buf);
|
super(TradingStationRegistrate.MENU.get(), pContainerId, inventory, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TradingStationMenu factory(@Nullable MenuType<TradingStationMenu> pMenuType, int pContainerId, Inventory inventory, FriendlyByteBuf buf) {
|
public static TradingStationMenu factory(@Nullable MenuType<TradingStationMenu> pMenuType, int pContainerId, Inventory inventory, FriendlyByteBuf buf) {
|
||||||
@@ -27,14 +27,22 @@ public class TradingStationMenu extends AbstractTradingMenu {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean stillValid(Player pPlayer) {
|
public boolean stillValid(Player pPlayer) {
|
||||||
return stillValid(ContainerLevelAccess.create(level, blockEntity.getBlockPos()), pPlayer, TradingStationRegistrate.TRADING_STATION_BLOCK.get());
|
return stillValid(ContainerLevelAccess.create(level, getBlockPos()), pPlayer, TradingStationRegistrate.BLOCK.get());
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int[][] getInputSlotCoords() {
|
public Coords2D[] getInputSlotCoords() {
|
||||||
return new int[][]{{19,38},{42,38}};
|
return new Coords2D[]{
|
||||||
|
Coords2D.of(19,49),
|
||||||
|
Coords2D.of(42,49)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int[] getOutputSlotCoords() {
|
public Coords2D getOutputSlotCoords() {
|
||||||
return new int[]{131,38};
|
return Coords2D.of(131,49);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public Coords2D getTargetSlotCoords() {
|
||||||
|
return Coords2D.of(87,40);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
|||||||
import com.oierbravo.trading_station.TradingStation;
|
import com.oierbravo.trading_station.TradingStation;
|
||||||
import com.oierbravo.trading_station.content.trading_recipe.TradingRecipe;
|
import com.oierbravo.trading_station.content.trading_recipe.TradingRecipe;
|
||||||
import com.oierbravo.trading_station.foundation.gui.AbstractTradingScreen;
|
import com.oierbravo.trading_station.foundation.gui.AbstractTradingScreen;
|
||||||
|
import com.oierbravo.trading_station.foundation.gui.Coords2D;
|
||||||
import com.oierbravo.trading_station.foundation.render.FakeItemRenderer;
|
import com.oierbravo.trading_station.foundation.render.FakeItemRenderer;
|
||||||
import com.oierbravo.trading_station.foundation.util.ModLang;
|
import com.oierbravo.trading_station.foundation.util.ModLang;
|
||||||
import com.oierbravo.trading_station.registrate.ModRecipes;
|
import com.oierbravo.trading_station.registrate.ModRecipes;
|
||||||
@@ -21,8 +22,6 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public class TradingStationScreen extends AbstractTradingScreen<TradingStationMenu> {
|
public class TradingStationScreen extends AbstractTradingScreen<TradingStationMenu> {
|
||||||
|
|
||||||
protected static int[] progressArrowCoords = {79,47};
|
|
||||||
protected static int[] targetSelectButtonCoords = {131,18};
|
|
||||||
private static final ResourceLocation TEXTURE = TradingStation.asResource("textures/gui/trading_station.png");
|
private static final ResourceLocation TEXTURE = TradingStation.asResource("textures/gui/trading_station.png");
|
||||||
|
|
||||||
public TradingStationScreen(TradingStationMenu pMenu, Inventory pPlayerInventory, Component pTitle) {
|
public TradingStationScreen(TradingStationMenu pMenu, Inventory pPlayerInventory, Component pTitle) {
|
||||||
@@ -33,15 +32,17 @@ public class TradingStationScreen extends AbstractTradingScreen<TradingStationMe
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] getProgressArrowCoords() {
|
public Coords2D getProgressArrowCoords() {
|
||||||
return progressArrowCoords;
|
return Coords2D.of(79, 47);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int[] getTargetSelectButtonCoords() {
|
protected Coords2D getTargetSelectButtonCoords() {
|
||||||
return targetSelectButtonCoords;
|
return Coords2D.of(131, 31);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Coords2D getRedstoneButtonCoords() { return Coords2D.of(151,31); }
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ResourceLocation getTexture() {
|
protected ResourceLocation getTexture() {
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ import com.oierbravo.trading_station.foundation.util.ModLang;
|
|||||||
import com.oierbravo.trading_station.network.packets.GhostItemSyncC2SPacket;
|
import com.oierbravo.trading_station.network.packets.GhostItemSyncC2SPacket;
|
||||||
import com.oierbravo.trading_station.registrate.ModMessages;
|
import com.oierbravo.trading_station.registrate.ModMessages;
|
||||||
import com.oierbravo.trading_station.registrate.ModRecipes;
|
import com.oierbravo.trading_station.registrate.ModRecipes;
|
||||||
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.components.Button;
|
import net.minecraft.client.gui.components.Button;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.client.renderer.GameRenderer;
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.sounds.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
@@ -51,17 +53,23 @@ public class TradingStationTargetSelectScreen extends Screen {
|
|||||||
protected int leftPos;
|
protected int leftPos;
|
||||||
protected int topPos;
|
protected int topPos;
|
||||||
|
|
||||||
|
private BlockPos blockPos;
|
||||||
protected TradingStationTargetSelectScreen(Component pTitle) {
|
protected TradingStationTargetSelectScreen(Component pTitle) {
|
||||||
super(pTitle);
|
super(pTitle);
|
||||||
}
|
}
|
||||||
public TradingStationTargetSelectScreen(ITradingStationBlockEntity pBlockEntity) {
|
public TradingStationTargetSelectScreen(ITradingStationBlockEntity pBlockEntity, BlockPos pBlockPos) {
|
||||||
this(ModLang.translate("select_target.title"));
|
this(ModLang.translate("select_target.title"));
|
||||||
this.blockEntity = pBlockEntity;
|
this.blockEntity = pBlockEntity;
|
||||||
this.allPossibleOutputs = ModRecipes.getAllOutputs(pBlockEntity.getLevel());
|
this.blockPos = pBlockPos;
|
||||||
|
this.allPossibleOutputs = ModRecipes.getAllOutputs(pBlockEntity.getLevel(),pBlockEntity.getBiome(),pBlockEntity.getTraderType());
|
||||||
resetDisplayedTargets();
|
resetDisplayedTargets();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BlockPos getBlockPos() {
|
||||||
|
return blockPos;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
super.init();
|
super.init();
|
||||||
@@ -73,7 +81,7 @@ public class TradingStationTargetSelectScreen extends Screen {
|
|||||||
Minecraft.getInstance().popGuiLayer();
|
Minecraft.getInstance().popGuiLayer();
|
||||||
}));
|
}));
|
||||||
addRenderableWidget(new Button(getGuiLeft() - 25, getGuiTop() + 30, 25, 20, ModLang.translate("select_target.clear"), (button) -> {
|
addRenderableWidget(new Button(getGuiLeft() - 25, getGuiTop() + 30, 25, 20, ModLang.translate("select_target.clear"), (button) -> {
|
||||||
ModMessages.sendToServer(new GhostItemSyncC2SPacket(ItemStack.EMPTY,this.blockEntity.getBlockPos()));
|
ModMessages.sendToServer(new GhostItemSyncC2SPacket(ItemStack.EMPTY,getBlockPos()));
|
||||||
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_STONECUTTER_SELECT_RECIPE, 1.0f));
|
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_STONECUTTER_SELECT_RECIPE, 1.0f));
|
||||||
Minecraft.getInstance().popGuiLayer();
|
Minecraft.getInstance().popGuiLayer();
|
||||||
}));
|
}));
|
||||||
@@ -119,7 +127,7 @@ public class TradingStationTargetSelectScreen extends Screen {
|
|||||||
ItemStack target = allPossibleOutputs.get(index);
|
ItemStack target = allPossibleOutputs.get(index);
|
||||||
int xStart = getGuiLeft() + targetBoxLeftPosOffset + firstDisplayedIndex % COLUMNS * TARGET_BOX_SIZE + 1;
|
int xStart = getGuiLeft() + targetBoxLeftPosOffset + firstDisplayedIndex % COLUMNS * TARGET_BOX_SIZE + 1;
|
||||||
int yStart = getGuiTop() + targetBoxTopPosOffset + (firstDisplayedIndex / COLUMNS) * TARGET_BOX_SIZE + 3;
|
int yStart = getGuiTop() + targetBoxTopPosOffset + (firstDisplayedIndex / COLUMNS) * TARGET_BOX_SIZE + 3;
|
||||||
if(target.sameItem(selectedTarget))
|
if(ItemStack.isSameItemSameTags(selectedTarget, target ))
|
||||||
blit(pPoseStack, xStart, yStart, 0, imageHeight + 19, TARGET_BOX_SIZE, TARGET_BOX_SIZE);
|
blit(pPoseStack, xStart, yStart, 0, imageHeight + 19, TARGET_BOX_SIZE, TARGET_BOX_SIZE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,7 +141,7 @@ public class TradingStationTargetSelectScreen extends Screen {
|
|||||||
int xStart = getGuiLeft() + targetBoxLeftPosOffset + firstDisplayedIndex % COLUMNS * TARGET_BOX_SIZE + 1;
|
int xStart = getGuiLeft() + targetBoxLeftPosOffset + firstDisplayedIndex % COLUMNS * TARGET_BOX_SIZE + 1;
|
||||||
int yStart = getGuiTop() + targetBoxTopPosOffset + (firstDisplayedIndex / COLUMNS) * TARGET_BOX_SIZE + 3;
|
int yStart = getGuiTop() + targetBoxTopPosOffset + (firstDisplayedIndex / COLUMNS) * TARGET_BOX_SIZE + 3;
|
||||||
|
|
||||||
renderFloatingItem(target, xStart, yStart);
|
renderFloatingItem(target, xStart, yStart );
|
||||||
|
|
||||||
if (pMouseX >= xStart - 1 && pMouseX <= xStart + 16 && pMouseY >= yStart - 1 && pMouseY <= yStart + 16) {
|
if (pMouseX >= xStart - 1 && pMouseX <= xStart + 16 && pMouseY >= yStart - 1 && pMouseY <= yStart + 16) {
|
||||||
renderTooltip(pPoseStack, target, pMouseX, pMouseY);
|
renderTooltip(pPoseStack, target, pMouseX, pMouseY);
|
||||||
@@ -151,7 +159,7 @@ public class TradingStationTargetSelectScreen extends Screen {
|
|||||||
itemRenderer.blitOffset = 2000.0f;
|
itemRenderer.blitOffset = 2000.0f;
|
||||||
|
|
||||||
itemRenderer.renderAndDecorateItem(pItemStack, pX, pY);
|
itemRenderer.renderAndDecorateItem(pItemStack, pX, pY);
|
||||||
itemRenderer.renderGuiItemDecorations(font, pItemStack, pX, pY, "");
|
itemRenderer.renderGuiItemDecorations(font, pItemStack, pX, pY);
|
||||||
|
|
||||||
setBlitOffset(0);
|
setBlitOffset(0);
|
||||||
itemRenderer.blitOffset = 0.0f;
|
itemRenderer.blitOffset = 0.0f;
|
||||||
@@ -185,7 +193,7 @@ public class TradingStationTargetSelectScreen extends Screen {
|
|||||||
|
|
||||||
if (boxX > 0 && boxX <= TARGET_BOX_SIZE + 1 && boxY > 0 && boxY <= TARGET_BOX_SIZE + 1 && isValidRecipeIndex(index)) {
|
if (boxX > 0 && boxX <= TARGET_BOX_SIZE + 1 && boxY > 0 && boxY <= TARGET_BOX_SIZE + 1 && isValidRecipeIndex(index)) {
|
||||||
ItemStack itemStack = getDisplayedItemStacks().get(index);
|
ItemStack itemStack = getDisplayedItemStacks().get(index);
|
||||||
ModMessages.sendToServer(new GhostItemSyncC2SPacket(itemStack,this.blockEntity.getBlockPos()));
|
ModMessages.sendToServer(new GhostItemSyncC2SPacket(itemStack,getBlockPos()));
|
||||||
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_STONECUTTER_SELECT_RECIPE, 1.0f));
|
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_STONECUTTER_SELECT_RECIPE, 1.0f));
|
||||||
Minecraft.getInstance().popGuiLayer();
|
Minecraft.getInstance().popGuiLayer();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class PoweredTradingStationBlock extends TradingStationBlock {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
|
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
|
||||||
return PoweredTradingStationRegistrate.POWERED_TRADING_STATION_BLOCK_ENTITY.create(pPos, pState);
|
return PoweredTradingStationRegistrate.BLOCK_ENTITY.create(pPos, pState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -36,7 +36,7 @@ public class PoweredTradingStationBlock extends TradingStationBlock {
|
|||||||
if(pLevel.isClientSide()) {
|
if(pLevel.isClientSide()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return createTickerHelper(pBlockEntityType, PoweredTradingStationRegistrate.POWERED_TRADING_STATION_BLOCK_ENTITY.get(),
|
return createTickerHelper(pBlockEntityType, PoweredTradingStationRegistrate.BLOCK_ENTITY.get(),
|
||||||
(pLevel1, pPos, pState1, pBlockEntity) -> pBlockEntity.tick(pLevel1, pPos, pState1));
|
(pLevel1, pPos, pState1, pBlockEntity) -> pBlockEntity.tick(pLevel1, pPos, pState1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,12 @@ public class PoweredTradingStationBlockEntity extends TradingStationBlockEntity
|
|||||||
public IEnergyStorage getEnergyStorage() {
|
public IEnergyStorage getEnergyStorage() {
|
||||||
return this.energyStorage;
|
return this.energyStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTraderType() {
|
||||||
|
return "powered";
|
||||||
|
}
|
||||||
|
|
||||||
public void setRemoved() {
|
public void setRemoved() {
|
||||||
super.setRemoved();
|
super.setRemoved();
|
||||||
}
|
}
|
||||||
@@ -79,7 +85,7 @@ public class PoweredTradingStationBlockEntity extends TradingStationBlockEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Component getDisplayName() {
|
public Component getDisplayName() {
|
||||||
return ModLang.translate("powered_trading_station.block.display");
|
return Component.translatable("block.trading_station.powered_trading_station");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -103,7 +109,7 @@ public class PoweredTradingStationBlockEntity extends TradingStationBlockEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean canCraftItem() {
|
public boolean canCraftItem() {
|
||||||
Level level = this.getLevel();
|
Level level = this.getLevel();
|
||||||
if(level == null)
|
if(level == null)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public class PoweredTradingStationConfig {
|
|||||||
COMMON_BUILDER.comment("Settings for the Powered Trading Station").push("powered_trading_station");
|
COMMON_BUILDER.comment("Settings for the Powered Trading Station").push("powered_trading_station");
|
||||||
PROGRESS_PER_TICK = COMMON_BUILDER
|
PROGRESS_PER_TICK = COMMON_BUILDER
|
||||||
.comment("How much progress per tick")
|
.comment("How much progress per tick")
|
||||||
.defineInRange("progressPerTick", 1, 1, Integer.MAX_VALUE);
|
.defineInRange("progressPerTick", 5, 1, Integer.MAX_VALUE);
|
||||||
ENERGY_CAPACITY = COMMON_BUILDER
|
ENERGY_CAPACITY = COMMON_BUILDER
|
||||||
.comment("How much energy capacity has")
|
.comment("How much energy capacity has")
|
||||||
.defineInRange("energyCapacity", 64000, 1, Integer.MAX_VALUE);
|
.defineInRange("energyCapacity", 64000, 1, Integer.MAX_VALUE);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.oierbravo.trading_station.content.trading_station.powered;
|
package com.oierbravo.trading_station.content.trading_station.powered;
|
||||||
|
|
||||||
import com.oierbravo.trading_station.foundation.gui.AbstractTradingMenu;
|
import com.oierbravo.trading_station.foundation.gui.AbstractTradingMenu;
|
||||||
|
import com.oierbravo.trading_station.foundation.gui.Coords2D;
|
||||||
import com.oierbravo.trading_station.registrate.PoweredTradingStationRegistrate;
|
import com.oierbravo.trading_station.registrate.PoweredTradingStationRegistrate;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
@@ -13,11 +14,11 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
public class PoweredTradingStationMenu extends AbstractTradingMenu {
|
public class PoweredTradingStationMenu extends AbstractTradingMenu {
|
||||||
public PoweredTradingStationMenu(int pContainerId, Inventory pInv, BlockEntity pBlockEntity, ContainerData pData) {
|
public PoweredTradingStationMenu(int pContainerId, Inventory pInv, BlockEntity pBlockEntity, ContainerData pData) {
|
||||||
super(PoweredTradingStationRegistrate.POWERED_TRADING_STATION_MENU.get(), pContainerId, pInv, pBlockEntity, pData);
|
super(PoweredTradingStationRegistrate.MENU.get(), pContainerId, pInv, pBlockEntity, pData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PoweredTradingStationMenu(int pContainerId, Inventory inventory, FriendlyByteBuf buf) {
|
public PoweredTradingStationMenu(int pContainerId, Inventory inventory, FriendlyByteBuf buf) {
|
||||||
super(PoweredTradingStationRegistrate.POWERED_TRADING_STATION_MENU.get(), pContainerId, inventory, buf);
|
super(PoweredTradingStationRegistrate.MENU.get(), pContainerId, inventory, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PoweredTradingStationMenu factory(@Nullable MenuType<PoweredTradingStationMenu> pMenuType, int pContainerId, Inventory inventory, FriendlyByteBuf buf) {
|
public static PoweredTradingStationMenu factory(@Nullable MenuType<PoweredTradingStationMenu> pMenuType, int pContainerId, Inventory inventory, FriendlyByteBuf buf) {
|
||||||
@@ -25,14 +26,21 @@ public class PoweredTradingStationMenu extends AbstractTradingMenu {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean stillValid(Player pPlayer) {
|
public boolean stillValid(Player pPlayer) {
|
||||||
return stillValid(ContainerLevelAccess.create(level, blockEntity.getBlockPos()), pPlayer, PoweredTradingStationRegistrate.POWERED_TRADING_STATION_BLOCK.get());
|
return stillValid(ContainerLevelAccess.create(level, getBlockPos()), pPlayer, PoweredTradingStationRegistrate.BLOCK.get());
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int[][] getInputSlotCoords() {
|
public Coords2D[] getInputSlotCoords() {
|
||||||
return new int[][]{{28,38},{51,38}};
|
return new Coords2D[]{
|
||||||
|
Coords2D.of(28,47),
|
||||||
|
Coords2D.of(51,47)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int[] getOutputSlotCoords() {
|
public Coords2D getOutputSlotCoords() {
|
||||||
return new int[]{131,38};
|
return Coords2D.of(131,47);
|
||||||
}
|
}
|
||||||
}
|
public Coords2D getTargetSlotCoords() {
|
||||||
|
return Coords2D.of(87,40);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.oierbravo.trading_station.content.trading_recipe.TradingRecipe;
|
|||||||
import com.oierbravo.trading_station.content.trading_station.TradingStationMenu;
|
import com.oierbravo.trading_station.content.trading_station.TradingStationMenu;
|
||||||
import com.oierbravo.trading_station.content.trading_station.TradingStationTargetSelectScreen;
|
import com.oierbravo.trading_station.content.trading_station.TradingStationTargetSelectScreen;
|
||||||
import com.oierbravo.trading_station.foundation.gui.AbstractTradingScreen;
|
import com.oierbravo.trading_station.foundation.gui.AbstractTradingScreen;
|
||||||
|
import com.oierbravo.trading_station.foundation.gui.Coords2D;
|
||||||
import com.oierbravo.trading_station.foundation.render.EnergyDisplayTooltipArea;
|
import com.oierbravo.trading_station.foundation.render.EnergyDisplayTooltipArea;
|
||||||
import com.oierbravo.trading_station.foundation.render.FakeItemRenderer;
|
import com.oierbravo.trading_station.foundation.render.FakeItemRenderer;
|
||||||
import com.oierbravo.trading_station.foundation.util.ModLang;
|
import com.oierbravo.trading_station.foundation.util.ModLang;
|
||||||
@@ -24,9 +25,7 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public class PoweredTradingStationScreen extends AbstractTradingScreen<PoweredTradingStationMenu> {
|
public class PoweredTradingStationScreen extends AbstractTradingScreen<PoweredTradingStationMenu> {
|
||||||
|
|
||||||
protected static int[] progressArrowCoords = {79,47};
|
private static final ResourceLocation TEXTURE = TradingStation.asResource("textures/gui/trading_station.png");
|
||||||
protected static int[] targetSelectButtonCoords = {131,18};
|
|
||||||
private static final ResourceLocation TEXTURE = TradingStation.asResource("textures/gui/powered_trading_station.png");
|
|
||||||
private EnergyDisplayTooltipArea energyInfoArea;
|
private EnergyDisplayTooltipArea energyInfoArea;
|
||||||
|
|
||||||
|
|
||||||
@@ -48,9 +47,17 @@ public class PoweredTradingStationScreen extends AbstractTradingScreen<PoweredTr
|
|||||||
protected void renderBg(PoseStack pPoseStack, float pPartialTick, int pMouseX, int pMouseY) {
|
protected void renderBg(PoseStack pPoseStack, float pPartialTick, int pMouseX, int pMouseY) {
|
||||||
|
|
||||||
super.renderBg(pPoseStack, pPartialTick, pMouseX, pMouseY);
|
super.renderBg(pPoseStack, pPartialTick, pMouseX, pMouseY);
|
||||||
|
RenderSystem.setShaderTexture(0, getTexture());
|
||||||
|
|
||||||
|
renderSlotPlaceholder(pPoseStack,((width - imageWidth) / 2) + 7,((height - imageHeight) / 2) + 23);
|
||||||
|
|
||||||
energyInfoArea.render(pPoseStack);
|
energyInfoArea.render(pPoseStack);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
private void renderSlotPlaceholder(PoseStack pPoseStack, int pX, int pY){
|
||||||
|
this.blit(pPoseStack, pX , pY , 0, 182,11, 32);
|
||||||
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void renderLabels(PoseStack pPoseStack, int pMouseX, int pMouseY) {
|
protected void renderLabels(PoseStack pPoseStack, int pMouseX, int pMouseY) {
|
||||||
@@ -73,13 +80,13 @@ public class PoweredTradingStationScreen extends AbstractTradingScreen<PoweredTr
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int[] getProgressArrowCoords() {
|
protected Coords2D getProgressArrowCoords() {
|
||||||
return progressArrowCoords;
|
return Coords2D.of(79, 47);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int[] getTargetSelectButtonCoords() {
|
protected Coords2D getTargetSelectButtonCoords() {
|
||||||
return targetSelectButtonCoords;
|
return Coords2D.of(131, 29);
|
||||||
}
|
}
|
||||||
|
protected Coords2D getRedstoneButtonCoords() { return Coords2D.of(151,28); }
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.oierbravo.trading_station.foundation.gui;
|
package com.oierbravo.trading_station.foundation.gui;
|
||||||
|
|
||||||
import com.oierbravo.trading_station.content.trading_station.ITradingStationBlockEntity;
|
import com.oierbravo.trading_station.content.trading_station.ITradingStationBlockEntity;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
@@ -22,38 +23,46 @@ public abstract class AbstractTradingMenu extends AbstractContainerMenu {
|
|||||||
public AbstractTradingMenu(@Nullable MenuType<?> pMenuType, int pContainerId, Inventory pInv, BlockEntity pBlockEntity, ContainerData pData){
|
public AbstractTradingMenu(@Nullable MenuType<?> pMenuType, int pContainerId, Inventory pInv, BlockEntity pBlockEntity, ContainerData pData){
|
||||||
super(pMenuType, pContainerId);
|
super(pMenuType, pContainerId);
|
||||||
checkContainerSize(pInv, 3);
|
checkContainerSize(pInv, 3);
|
||||||
|
checkContainerDataCount(pData,3);
|
||||||
|
blockPos = pBlockEntity.getBlockPos();
|
||||||
blockEntity = (ITradingStationBlockEntity) pBlockEntity;
|
blockEntity = (ITradingStationBlockEntity) pBlockEntity;
|
||||||
level = pInv.player.getLevel();
|
level = pInv.player.getLevel();
|
||||||
containerData = pData;
|
containerData = pData;
|
||||||
inventory = pInv;
|
inventory = pInv;
|
||||||
addPlayerHotbar(pInv);
|
|
||||||
addPlayerInventory(pInv);
|
|
||||||
this.addDataSlots(pData);
|
|
||||||
//this.blockEntity.inputItems
|
|
||||||
int[][] coords = getInputSlotCoords();
|
|
||||||
|
|
||||||
|
addDataSlots(pData);
|
||||||
|
addPlayerInventory(pInv);
|
||||||
|
addPlayerHotbar(pInv);
|
||||||
|
Coords2D co = getOutputSlotCoords();
|
||||||
this.blockEntity.getInputItemHandler().ifPresent(itemHandler -> {
|
this.blockEntity.getInputItemHandler().ifPresent(itemHandler -> {
|
||||||
this.addSlot(new SlotItemHandler(itemHandler,0, getInputSlotCoords()[0][0],getInputSlotCoords()[0][1]));
|
this.addSlot(new SlotItemHandler(itemHandler,0, getInputSlotCoords()[0].x,getInputSlotCoords()[0].y));
|
||||||
this.addSlot(new SlotItemHandler(itemHandler,1, getInputSlotCoords()[1][0],getInputSlotCoords()[1][1]));
|
this.addSlot(new SlotItemHandler(itemHandler,1, getInputSlotCoords()[1].x,getInputSlotCoords()[1].y));
|
||||||
});
|
});
|
||||||
this.blockEntity.getOutputItemHandler().ifPresent(itemHandler -> {
|
this.blockEntity.getOutputItemHandler().ifPresent(itemHandler -> {
|
||||||
this.addSlot(new SlotItemHandler(itemHandler,0,getOutputSlotCoords()[0],getOutputSlotCoords()[1]));
|
this.addSlot(new SlotItemHandler(itemHandler,0,getOutputSlotCoords().x,getOutputSlotCoords().y));
|
||||||
});
|
});
|
||||||
this.addSlot(new SlotItemHandler(this.blockEntity.getTargetItemHandler(),0,87,28));
|
this.addSlot(new SlotItemHandler(this.blockEntity.getTargetItemHandler(),0,getTargetSlotCoords().x,getTargetSlotCoords().y));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractTradingMenu(@Nullable MenuType<?> pMenuType, int pContainerId, Inventory inv, FriendlyByteBuf extraData){
|
public AbstractTradingMenu(@Nullable MenuType<?> pMenuType, int pContainerId, Inventory inv, FriendlyByteBuf extraData){
|
||||||
this(pMenuType, pContainerId, inv, inv.player.level.getBlockEntity(extraData.readBlockPos()), new SimpleContainerData(2));
|
this(pMenuType, pContainerId, inv, inv.player.level.getBlockEntity(extraData.readBlockPos()), new SimpleContainerData(3));
|
||||||
}
|
}
|
||||||
public abstract int[][] getInputSlotCoords();
|
public abstract Coords2D[] getInputSlotCoords();
|
||||||
|
|
||||||
public abstract int[] getOutputSlotCoords();
|
public abstract Coords2D getOutputSlotCoords();
|
||||||
|
public abstract Coords2D getTargetSlotCoords();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean stillValid(Player pPlayer);
|
public abstract boolean stillValid(Player pPlayer);
|
||||||
|
|
||||||
|
private BlockPos blockPos;
|
||||||
|
public byte getCurrentRedstoneMode(){
|
||||||
|
return (byte) this.containerData.get(2);
|
||||||
|
//return 0;
|
||||||
|
}
|
||||||
public int getScaledProgress() {
|
public int getScaledProgress() {
|
||||||
int progress = this.containerData.get(0);
|
int progress = this.containerData.get(0);
|
||||||
int maxProgress = this.containerData.get(1); // Max Progress
|
int maxProgress = this.containerData.get(1); // Max Progress
|
||||||
@@ -61,6 +70,9 @@ public abstract class AbstractTradingMenu extends AbstractContainerMenu {
|
|||||||
|
|
||||||
return maxProgress != 0 && progress != 0 ? progress * progressArrowSize / maxProgress : 0;
|
return maxProgress != 0 && progress != 0 ? progress * progressArrowSize / maxProgress : 0;
|
||||||
}
|
}
|
||||||
|
public BlockPos getBlockPos(){
|
||||||
|
return blockPos;
|
||||||
|
}
|
||||||
public boolean isCrafting() {
|
public boolean isCrafting() {
|
||||||
return containerData.get(0) > 0;
|
return containerData.get(0) > 0;
|
||||||
}
|
}
|
||||||
@@ -113,7 +125,7 @@ public abstract class AbstractTradingMenu extends AbstractContainerMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final int PLAYER_INVENTORY_Y = 64;
|
private static final int PLAYER_INVENTORY_Y = 74;
|
||||||
|
|
||||||
private void addPlayerInventory(Inventory playerInventory) {
|
private void addPlayerInventory(Inventory playerInventory) {
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
@@ -122,7 +134,7 @@ public abstract class AbstractTradingMenu extends AbstractContainerMenu {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static final int HOTBAR_Y = 122;
|
private static final int HOTBAR_Y = 132;
|
||||||
|
|
||||||
private void addPlayerHotbar(Inventory playerInventory) {
|
private void addPlayerHotbar(Inventory playerInventory) {
|
||||||
for (int i = 0; i < 9; ++i) {
|
for (int i = 0; i < 9; ++i) {
|
||||||
|
|||||||
@@ -7,38 +7,64 @@ import com.oierbravo.trading_station.content.trading_recipe.TradingRecipe;
|
|||||||
import com.oierbravo.trading_station.content.trading_station.TradingStationScreen;
|
import com.oierbravo.trading_station.content.trading_station.TradingStationScreen;
|
||||||
import com.oierbravo.trading_station.content.trading_station.TradingStationTargetSelectScreen;
|
import com.oierbravo.trading_station.content.trading_station.TradingStationTargetSelectScreen;
|
||||||
import com.oierbravo.trading_station.foundation.render.FakeItemRenderer;
|
import com.oierbravo.trading_station.foundation.render.FakeItemRenderer;
|
||||||
|
import com.oierbravo.trading_station.foundation.render.LaserIOItemRenderer;
|
||||||
|
import com.oierbravo.trading_station.foundation.util.MiscTools;
|
||||||
import com.oierbravo.trading_station.foundation.util.ModLang;
|
import com.oierbravo.trading_station.foundation.util.ModLang;
|
||||||
import com.oierbravo.trading_station.foundation.util.MouseUtil;
|
import com.oierbravo.trading_station.foundation.util.MouseUtil;
|
||||||
|
import com.oierbravo.trading_station.network.packets.GhostItemSyncC2SPacket;
|
||||||
|
import com.oierbravo.trading_station.network.packets.RedstoneModeSyncC2SPacket;
|
||||||
|
import com.oierbravo.trading_station.registrate.ModMessages;
|
||||||
import com.oierbravo.trading_station.registrate.ModRecipes;
|
import com.oierbravo.trading_station.registrate.ModRecipes;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.components.Button;
|
||||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||||
|
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
||||||
import net.minecraft.client.renderer.GameRenderer;
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.crafting.Ingredient;
|
import net.minecraft.world.item.crafting.Ingredient;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraftforge.client.gui.widget.ExtendedButton;
|
import net.minecraftforge.client.gui.widget.ExtendedButton;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public abstract class AbstractTradingScreen<MENU extends AbstractTradingMenu> extends AbstractContainerScreen<MENU> {
|
public abstract class AbstractTradingScreen<MENU extends AbstractTradingMenu> extends AbstractContainerScreen<MENU> {
|
||||||
|
protected Map<String, Button> buttons = new HashMap<>();
|
||||||
|
protected byte currentRedstoneMode;
|
||||||
|
|
||||||
|
|
||||||
public AbstractTradingScreen(MENU pMenu, Inventory pPlayerInventory, Component pTitle) {
|
public AbstractTradingScreen(MENU pMenu, Inventory pPlayerInventory, Component pTitle) {
|
||||||
super(pMenu, pPlayerInventory, pTitle);
|
super(pMenu, pPlayerInventory, pTitle);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
super.init();
|
super.init();
|
||||||
this.titleLabelX = 4;
|
this.titleLabelX = 4;
|
||||||
this.titleLabelY = 4;
|
this.titleLabelY = 13;
|
||||||
this.inventoryLabelY = 100000;
|
this.inventoryLabelY = 100000;
|
||||||
this.addRenderableWidget(new ExtendedButton(leftPos + getTargetSelectButtonCoords()[0],topPos + getTargetSelectButtonCoords()[1],16,16, ModLang.translate("select_target.button"), btn ->{
|
this.imageWidth = 176;
|
||||||
TradingStationTargetSelectScreen screen = new TradingStationTargetSelectScreen( this.menu.blockEntity);
|
this.imageHeight = 146;
|
||||||
Minecraft.getInstance().pushGuiLayer(screen);
|
|
||||||
|
addTargetSelectButton();
|
||||||
|
|
||||||
|
currentRedstoneMode = menu.getCurrentRedstoneMode();
|
||||||
|
addRedstoneButton();
|
||||||
|
|
||||||
|
for (Map.Entry<String, Button> button : buttons.entrySet()) {
|
||||||
|
addRenderableWidget(button.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
protected abstract ResourceLocation getTexture();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderBg(PoseStack pPoseStack, float pPartialTick, int pMouseX, int pMouseY) {
|
protected void renderBg(PoseStack pPoseStack, float pPartialTick, int pMouseX, int pMouseY) {
|
||||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||||
@@ -51,8 +77,14 @@ public abstract class AbstractTradingScreen<MENU extends AbstractTradingMenu> ex
|
|||||||
this.blit(pPoseStack, x, y, 0, 0, imageWidth, imageHeight);
|
this.blit(pPoseStack, x, y, 0, 0, imageWidth, imageHeight);
|
||||||
|
|
||||||
if (menu.isCrafting()) {
|
if (menu.isCrafting()) {
|
||||||
this.blit(pPoseStack, x + getProgressArrowCoords()[0], y + getProgressArrowCoords()[1], 179, 0, menu.getScaledProgress(), 7);
|
this.blit(pPoseStack, x + getProgressArrowCoords().x, y + getProgressArrowCoords().y, 179, 0, menu.getScaledProgress(), 7);
|
||||||
}
|
}
|
||||||
|
renderSlotPlaceholder(pPoseStack,getGuiLeft() + this.menu.getInputSlotCoords()[0].x -1,getGuiTop() + this.menu.getInputSlotCoords()[0].y -1);
|
||||||
|
renderSlotPlaceholder(pPoseStack,getGuiLeft() + this.menu.getInputSlotCoords()[1].x -1,getGuiTop() + this.menu.getInputSlotCoords()[1].y -1);
|
||||||
|
renderSlotPlaceholder(pPoseStack,getGuiLeft() + this.menu.getOutputSlotCoords().x -1,getGuiTop() + this.menu.getOutputSlotCoords().y -1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(!menu.blockEntity.getTargetItemStack().isEmpty()){
|
if(!menu.blockEntity.getTargetItemStack().isEmpty()){
|
||||||
Optional<TradingRecipe> recipe = ModRecipes.findByOutput(menu.blockEntity.getLevel(),menu.blockEntity.getTargetItemStack());
|
Optional<TradingRecipe> recipe = ModRecipes.findByOutput(menu.blockEntity.getLevel(),menu.blockEntity.getTargetItemStack());
|
||||||
@@ -61,32 +93,73 @@ public abstract class AbstractTradingScreen<MENU extends AbstractTradingMenu> ex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void renderItem( ItemStack pItemStack, int pX, int pY){
|
||||||
|
|
||||||
|
FakeItemRenderer.renderFakeItem(pItemStack, pX, pY);
|
||||||
|
}
|
||||||
|
private void renderSlotPlaceholder(PoseStack pPoseStack, int pX, int pY){
|
||||||
|
this.blit(pPoseStack, pX , pY , 0, 164,18, 18);
|
||||||
|
|
||||||
|
}
|
||||||
private void renderFakeRecipe(TradingRecipe recipe, PoseStack pPoseStack){
|
private void renderFakeRecipe(TradingRecipe recipe, PoseStack pPoseStack){
|
||||||
for(int index = 0; index < recipe.getIngredients().size(); index++){
|
for(int index = 0; index < recipe.getIngredients().size(); index++){
|
||||||
Ingredient ingredient = recipe.getIngredients().get(index);
|
Ingredient ingredient = recipe.getIngredients().get(index);
|
||||||
int[][] coords = this.menu.getInputSlotCoords();
|
|
||||||
|
|
||||||
if(!ingredient.isEmpty())
|
if(!ingredient.isEmpty())
|
||||||
FakeItemRenderer.renderFakeItem(ingredient.getItems()[0],getGuiLeft() + this.menu.getInputSlotCoords()[index][0],getGuiTop() + this.menu.getInputSlotCoords()[index][1], .5f);
|
renderItem(ingredient.getItems()[0],getGuiLeft() + this.menu.getInputSlotCoords()[index].x,getGuiTop() + this.menu.getInputSlotCoords()[index].y);
|
||||||
}
|
}
|
||||||
FakeItemRenderer.renderFakeItem(recipe.getResultItem(),getGuiLeft() + this.menu.getOutputSlotCoords()[0],getGuiTop() + this.menu.getOutputSlotCoords()[1], .5f);
|
renderItem(recipe.getResultItem(),getGuiLeft() + this.menu.getOutputSlotCoords().x,getGuiTop() + this.menu.getOutputSlotCoords().y);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected abstract int[] getProgressArrowCoords();
|
protected abstract Coords2D getProgressArrowCoords();
|
||||||
|
|
||||||
protected abstract int[] getTargetSelectButtonCoords();
|
protected abstract Coords2D getTargetSelectButtonCoords();
|
||||||
|
protected abstract Coords2D getRedstoneButtonCoords();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTick) {
|
public void render(PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTick) {
|
||||||
super.render(pPoseStack, pMouseX, pMouseY, pPartialTick);
|
super.render(pPoseStack, pMouseX, pMouseY, pPartialTick);
|
||||||
|
|
||||||
|
Button redstoneMode = buttons.get("redstoneMode");
|
||||||
|
currentRedstoneMode = this.menu.getCurrentRedstoneMode();
|
||||||
|
((ToggleButton) redstoneMode).setTexturePosition(currentRedstoneMode);
|
||||||
|
if (MiscTools.inBounds(redstoneMode.x, redstoneMode.y, redstoneMode.getWidth(), redstoneMode.getHeight(), pMouseX, pMouseY)) {
|
||||||
|
MutableComponent translatableComponents[] = new MutableComponent[3];
|
||||||
|
translatableComponents[0] = ModLang.translate("screen.redstone.ignored");
|
||||||
|
translatableComponents[1] = ModLang.translate("screen.redstone.low");
|
||||||
|
translatableComponents[2] = ModLang.translate("screen.redstone.high");
|
||||||
|
this.renderTooltip(pPoseStack, ModLang.translate("screen.redstone.redstoneMode").append(translatableComponents[currentRedstoneMode]), pMouseX, pMouseY);
|
||||||
|
}
|
||||||
|
Button targetSelect = buttons.get("targetSelect");
|
||||||
|
if (MiscTools.inBounds(targetSelect.x, targetSelect.y, targetSelect.getWidth(), targetSelect.getHeight(), pMouseX, pMouseY)) {
|
||||||
|
this.renderTooltip(pPoseStack, ModLang.translate("select_target.title"), pMouseX, pMouseY);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract ResourceLocation getTexture();
|
|
||||||
|
|
||||||
protected boolean isMouseAboveArea(int pMouseX, int pMouseY, int x, int y, int offsetX, int offsetY, int width, int height) {
|
protected boolean isMouseAboveArea(int pMouseX, int pMouseY, int x, int y, int offsetX, int offsetY, int width, int height) {
|
||||||
return MouseUtil.isMouseOver(pMouseX, pMouseY, x + offsetX, y + offsetY, width, height);
|
return MouseUtil.isMouseOver(pMouseX, pMouseY, x + offsetX, y + offsetY, width, height);
|
||||||
}
|
}
|
||||||
|
public void addRedstoneButton() {
|
||||||
|
ResourceLocation[] redstoneTextures = new ResourceLocation[3];
|
||||||
|
redstoneTextures[0] = new ResourceLocation(TradingStation.MODID, "textures/gui/buttons/redstoneignore.png");
|
||||||
|
redstoneTextures[1] = new ResourceLocation(TradingStation.MODID, "textures/gui/buttons/redstonelow.png");
|
||||||
|
redstoneTextures[2] = new ResourceLocation(TradingStation.MODID, "textures/gui/buttons/redstonehigh.png");
|
||||||
|
buttons.put("redstoneMode", new ToggleButton(getGuiLeft() + getRedstoneButtonCoords().x, getGuiTop() + getRedstoneButtonCoords().y, 16, 16, redstoneTextures, currentRedstoneMode, (button) -> {
|
||||||
|
currentRedstoneMode = (byte) (currentRedstoneMode == 2 ? 0 : currentRedstoneMode + 1);
|
||||||
|
ModMessages.sendToServer(new RedstoneModeSyncC2SPacket(currentRedstoneMode,this.menu.getBlockPos()));
|
||||||
|
//((ToggleButton) button).setTexturePosition(currentRedstoneMode);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addTargetSelectButton(){
|
||||||
|
buttons.put("targetSelect", new ExtendedButton(leftPos + getTargetSelectButtonCoords().x,topPos + getTargetSelectButtonCoords().y,16,16, ModLang.translate("select_target.button"), btn ->{
|
||||||
|
TradingStationTargetSelectScreen screen = new TradingStationTargetSelectScreen( this.menu.blockEntity, this.menu.getBlockPos());
|
||||||
|
Minecraft.getInstance().pushGuiLayer(screen);
|
||||||
|
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,13 @@
|
|||||||
package com.oierbravo.trading_station.foundation.gui;
|
package com.oierbravo.trading_station.foundation.gui;
|
||||||
|
|
||||||
public class Coords2D {
|
public class Coords2D {
|
||||||
|
public int x;
|
||||||
|
public int y;
|
||||||
|
public Coords2D(int pX, int pY){
|
||||||
|
x = pX;
|
||||||
|
y = pY;
|
||||||
|
}
|
||||||
|
public static Coords2D of(int pX, int pY){
|
||||||
|
return new Coords2D(pX,pY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import net.minecraft.client.renderer.RenderType;
|
|||||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||||
import net.minecraft.client.renderer.entity.ItemRenderer;
|
import net.minecraft.client.renderer.entity.ItemRenderer;
|
||||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||||
|
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||||
import net.minecraft.client.renderer.texture.TextureManager;
|
import net.minecraft.client.renderer.texture.TextureManager;
|
||||||
import net.minecraft.client.resources.model.BakedModel;
|
import net.minecraft.client.resources.model.BakedModel;
|
||||||
import net.minecraft.world.inventory.InventoryMenu;
|
import net.minecraft.world.inventory.InventoryMenu;
|
||||||
@@ -61,9 +62,9 @@ public class FakeItemRenderer {
|
|||||||
if (!model.usesBlockLight()) {
|
if (!model.usesBlockLight()) {
|
||||||
Lighting.setupForFlatItems();
|
Lighting.setupForFlatItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiBufferSource.BufferSource bufferSource = MINECRAFT.renderBuffers().bufferSource();
|
MultiBufferSource.BufferSource bufferSource = MINECRAFT.renderBuffers().bufferSource();
|
||||||
ITEM_RENDERER.render(pItemStack,
|
|
||||||
|
ITEM_RENDERER.render(pItemStack,
|
||||||
ItemTransforms.TransformType.GUI,
|
ItemTransforms.TransformType.GUI,
|
||||||
false,
|
false,
|
||||||
new PoseStack(),
|
new PoseStack(),
|
||||||
@@ -84,7 +85,7 @@ public class FakeItemRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static MultiBufferSource getWrappedBuffer(MultiBufferSource pBufferSource, float pAlpha) {
|
private static MultiBufferSource getWrappedBuffer(MultiBufferSource pBufferSource, float pAlpha) {
|
||||||
return pRenderType -> new WrappedVertexConsumer(pBufferSource.getBuffer(RenderType.entityTranslucent(InventoryMenu.BLOCK_ATLAS)), 1F, 1F, 1F, pAlpha);
|
return pRenderType -> new WrappedVertexConsumer(pBufferSource.getBuffer(RenderType.entityTranslucentCull(InventoryMenu.BLOCK_ATLAS)), 1F, 1F, 1F, pAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BakedModel getBakedModel(ItemStack pItemStack) {
|
private static BakedModel getBakedModel(ItemStack pItemStack) {
|
||||||
@@ -92,6 +93,7 @@ public class FakeItemRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class WrappedVertexConsumer implements VertexConsumer {
|
class WrappedVertexConsumer implements VertexConsumer {
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ import net.minecraft.client.renderer.texture.TextureManager;
|
|||||||
import net.minecraft.client.resources.model.BakedModel;
|
import net.minecraft.client.resources.model.BakedModel;
|
||||||
import net.minecraft.client.resources.model.ModelManager;
|
import net.minecraft.client.resources.model.ModelManager;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@@ -139,27 +141,29 @@ public class LaserIOItemRenderer extends ItemRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderGuiItem(float scale, ItemStack p_115128_, int p_115129_, int p_115130_, BakedModel p_115131_) {
|
|
||||||
|
public void renderGuiItem(float scale, ItemStack pItemStack, int pX, int pY, BakedModel pBakedModel) {
|
||||||
Minecraft.getInstance().getTextureManager().getTexture(TextureAtlas.LOCATION_BLOCKS).setFilter(false, false);
|
Minecraft.getInstance().getTextureManager().getTexture(TextureAtlas.LOCATION_BLOCKS).setFilter(false, false);
|
||||||
RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_BLOCKS);
|
RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_BLOCKS);
|
||||||
RenderSystem.enableBlend();
|
RenderSystem.enableBlend();
|
||||||
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
|
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, .5F);
|
||||||
|
//RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
PoseStack posestack = RenderSystem.getModelViewStack();
|
PoseStack posestack = RenderSystem.getModelViewStack();
|
||||||
posestack.pushPose();
|
posestack.pushPose();
|
||||||
posestack.translate((double) p_115129_, (double) p_115130_, (double) (500.0F + this.blitOffset));
|
posestack.translate((double) pX, (double) pY, (double) (500.0F + this.blitOffset));
|
||||||
posestack.translate(8.0D, 8.0D, 0.0D);
|
posestack.translate(8.0D, 8.0D, 0.0D);
|
||||||
posestack.scale(1.0F, -1.0F, 1.0F);
|
posestack.scale(1.0F, -1.0F, 1.0F);
|
||||||
posestack.scale(scale, scale, scale);
|
posestack.scale(scale, scale, scale);
|
||||||
RenderSystem.applyModelViewMatrix();
|
RenderSystem.applyModelViewMatrix();
|
||||||
PoseStack posestack1 = new PoseStack();
|
PoseStack posestack1 = new PoseStack();
|
||||||
MultiBufferSource.BufferSource multibuffersource$buffersource = Minecraft.getInstance().renderBuffers().bufferSource();
|
MultiBufferSource.BufferSource multibuffersource$buffersource = Minecraft.getInstance().renderBuffers().bufferSource();
|
||||||
boolean flag = !p_115131_.usesBlockLight();
|
boolean flag = !pBakedModel.usesBlockLight();
|
||||||
if (flag) {
|
if (flag) {
|
||||||
Lighting.setupForFlatItems();
|
Lighting.setupForFlatItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.render(p_115128_, ItemTransforms.TransformType.GUI, false, posestack1, multibuffersource$buffersource, 15728880, OverlayTexture.NO_OVERLAY, p_115131_);
|
this.render(pItemStack, ItemTransforms.TransformType.GUI, false, posestack1, multibuffersource$buffersource, 15728880, OverlayTexture.NO_OVERLAY, pBakedModel);
|
||||||
multibuffersource$buffersource.endBatch();
|
multibuffersource$buffersource.endBatch();
|
||||||
RenderSystem.enableDepthTest();
|
RenderSystem.enableDepthTest();
|
||||||
if (flag) {
|
if (flag) {
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.oierbravo.trading_station.foundation.util;
|
package com.oierbravo.trading_station.foundation.util;
|
||||||
|
|
||||||
import com.oierbravo.trading_station.TradingStation;
|
import com.oierbravo.trading_station.TradingStation;
|
||||||
|
import com.simibubi.create.foundation.utility.LangBuilder;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@@ -9,10 +11,17 @@ public class ModLang {
|
|||||||
public static String asId(String name) {
|
public static String asId(String name) {
|
||||||
return name.toLowerCase(Locale.ROOT);
|
return name.toLowerCase(Locale.ROOT);
|
||||||
}
|
}
|
||||||
public static Component translate(String key){
|
public static MutableComponent translate(String key, Object... args){
|
||||||
return Component.translatable(TradingStation.MODID + '.' + key);
|
return Component.translatable(TradingStation.MODID + '.' + key,resolveBuilders(args));
|
||||||
}
|
}
|
||||||
public static String key(String key){
|
public static String key(String key){
|
||||||
return TradingStation.MODID + '.' + key;
|
return TradingStation.MODID + '.' + key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Object[] resolveBuilders(Object[] args) {
|
||||||
|
for (int i = 0; i < args.length; i++)
|
||||||
|
if (args[i]instanceof LangBuilder cb)
|
||||||
|
args[i] = cb.component();
|
||||||
|
return args;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ public class RedstoneModeSyncC2SPacket {
|
|||||||
|
|
||||||
if(sender.getLevel().getBlockEntity(message.pos) instanceof ITradingStationBlockEntity blockEntity) {
|
if(sender.getLevel().getBlockEntity(message.pos) instanceof ITradingStationBlockEntity blockEntity) {
|
||||||
blockEntity.setRedstoneMode(message.mode);
|
blockEntity.setRedstoneMode(message.mode);
|
||||||
blockEntity.setChanged();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
context.setPacketHandled(true);
|
context.setPacketHandled(true);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.oierbravo.trading_station.registrate;
|
|||||||
import com.oierbravo.trading_station.TradingStation;
|
import com.oierbravo.trading_station.TradingStation;
|
||||||
import net.minecraft.world.item.CreativeModeTab;
|
import net.minecraft.world.item.CreativeModeTab;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Items;
|
|
||||||
|
|
||||||
public class ModCreativeTab extends CreativeModeTab {
|
public class ModCreativeTab extends CreativeModeTab {
|
||||||
public static ModCreativeTab MAIN;
|
public static ModCreativeTab MAIN;
|
||||||
@@ -16,7 +15,7 @@ public class ModCreativeTab extends CreativeModeTab {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack makeIcon() {
|
public ItemStack makeIcon() {
|
||||||
return new ItemStack(TradingStationRegistrate.TRADING_STATION_BLOCK.get());
|
return new ItemStack(TradingStationRegistrate.BLOCK.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.oierbravo.trading_station.registrate;
|
|||||||
import com.oierbravo.trading_station.TradingStation;
|
import com.oierbravo.trading_station.TradingStation;
|
||||||
import com.oierbravo.trading_station.network.packets.GhostItemSyncC2SPacket;
|
import com.oierbravo.trading_station.network.packets.GhostItemSyncC2SPacket;
|
||||||
import com.oierbravo.trading_station.network.packets.ItemStackSyncS2CPacket;
|
import com.oierbravo.trading_station.network.packets.ItemStackSyncS2CPacket;
|
||||||
|
import com.oierbravo.trading_station.network.packets.RedstoneModeSyncC2SPacket;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraftforge.network.NetworkDirection;
|
import net.minecraftforge.network.NetworkDirection;
|
||||||
@@ -41,6 +42,12 @@ public class ModMessages {
|
|||||||
.consumerMainThread(GhostItemSyncC2SPacket::handle)
|
.consumerMainThread(GhostItemSyncC2SPacket::handle)
|
||||||
.add();
|
.add();
|
||||||
|
|
||||||
|
net.messageBuilder(RedstoneModeSyncC2SPacket.class, id(), NetworkDirection.PLAY_TO_SERVER)
|
||||||
|
.decoder(RedstoneModeSyncC2SPacket::new)
|
||||||
|
.encoder(RedstoneModeSyncC2SPacket::toBytes)
|
||||||
|
.consumerMainThread(RedstoneModeSyncC2SPacket::handle)
|
||||||
|
.add();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <MSG> void sendToServer(MSG message) {
|
public static <MSG> void sendToServer(MSG message) {
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ import net.minecraft.world.item.ItemStack;
|
|||||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||||
import net.minecraft.world.item.crafting.RecipeType;
|
import net.minecraft.world.item.crafting.RecipeType;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
import net.minecraftforge.registries.DeferredRegister;
|
import net.minecraftforge.registries.DeferredRegister;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
import net.minecraftforge.registries.RegistryObject;
|
import net.minecraftforge.registries.RegistryObject;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@@ -29,11 +31,25 @@ public class ModRecipes {
|
|||||||
public static Optional<TradingRecipe> find(SimpleContainer pInv, Level pLevel) {
|
public static Optional<TradingRecipe> find(SimpleContainer pInv, Level pLevel) {
|
||||||
if(pLevel.isClientSide())
|
if(pLevel.isClientSide())
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
return pLevel.getRecipeManager().getRecipeFor(TradingRecipe.Type.INSTANCE,pInv,pLevel);
|
return find(pInv, pLevel, null);
|
||||||
}
|
}
|
||||||
public static List<ItemStack> getAllOutputs(Level pLevel){
|
|
||||||
|
public static Optional<TradingRecipe> find(SimpleContainer pInv, Level pLevel,@Nullable Biome biome) {
|
||||||
|
if(pLevel.isClientSide())
|
||||||
|
return Optional.empty();
|
||||||
return pLevel.getRecipeManager().getAllRecipesFor(TradingRecipe.Type.INSTANCE).stream()
|
return pLevel.getRecipeManager().getAllRecipesFor(TradingRecipe.Type.INSTANCE).stream()
|
||||||
.map(TradingRecipe::getResult).toList();
|
.filter((tradingRecipe -> tradingRecipe.matchesBiome(biome, pLevel)))
|
||||||
|
.findAny();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ItemStack> getAllOutputs(Level pLevel,@Nullable Biome biome, String machineType){
|
||||||
|
return pLevel.getRecipeManager().getAllRecipesFor(TradingRecipe.Type.INSTANCE).stream()
|
||||||
|
.filter((tradingRecipe -> tradingRecipe.matchesBiome(biome, pLevel)))
|
||||||
|
.filter((tradingRecipe -> tradingRecipe.matchesExclusiveTo(machineType)))
|
||||||
|
.sorted((recipe1, recipe2) -> recipe1.getId().compareNamespaced(recipe2.getId()))
|
||||||
|
.map(TradingRecipe::getResult)
|
||||||
|
.toList();
|
||||||
|
|
||||||
}
|
}
|
||||||
public static Optional<TradingRecipe> findByOutput(Level pLevel,ItemStack targetedOutput){
|
public static Optional<TradingRecipe> findByOutput(Level pLevel,ItemStack targetedOutput){
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.oierbravo.trading_station.registrate;
|
package com.oierbravo.trading_station.registrate;
|
||||||
|
|
||||||
import com.oierbravo.trading_station.TradingStation;
|
import com.oierbravo.trading_station.TradingStation;
|
||||||
import com.oierbravo.trading_station.content.trading_station.TradingStationBlockEntity;
|
|
||||||
import com.oierbravo.trading_station.content.trading_station.TradingStationBlockRenderer;
|
import com.oierbravo.trading_station.content.trading_station.TradingStationBlockRenderer;
|
||||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationBlock;
|
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationBlock;
|
||||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationBlockEntity;
|
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationBlockEntity;
|
||||||
@@ -15,7 +14,7 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|||||||
import net.minecraftforge.client.model.generators.ConfiguredModel;
|
import net.minecraftforge.client.model.generators.ConfiguredModel;
|
||||||
|
|
||||||
public class PoweredTradingStationRegistrate {
|
public class PoweredTradingStationRegistrate {
|
||||||
public static final BlockEntry<PoweredTradingStationBlock> POWERED_TRADING_STATION_BLOCK = TradingStation.registrate()
|
public static final BlockEntry<PoweredTradingStationBlock> BLOCK = TradingStation.registrate()
|
||||||
.block("powered_trading_station", PoweredTradingStationBlock::new)
|
.block("powered_trading_station", PoweredTradingStationBlock::new)
|
||||||
.lang("Powered Trading Station")
|
.lang("Powered Trading Station")
|
||||||
.blockstate((ctx, prov) ->
|
.blockstate((ctx, prov) ->
|
||||||
@@ -23,6 +22,8 @@ public class PoweredTradingStationRegistrate {
|
|||||||
String modelFileName = "trading_station:block/powered_trading_station";
|
String modelFileName = "trading_station:block/powered_trading_station";
|
||||||
if(state.getValue(BlockStateProperties.POWERED))
|
if(state.getValue(BlockStateProperties.POWERED))
|
||||||
modelFileName += "_powered";
|
modelFileName += "_powered";
|
||||||
|
if(state.getValue(BlockStateProperties.LIT))
|
||||||
|
modelFileName += "_lit";
|
||||||
return ConfiguredModel.builder().modelFile(prov.models().getExistingFile(ResourceLocation.tryParse(modelFileName)))
|
return ConfiguredModel.builder().modelFile(prov.models().getExistingFile(ResourceLocation.tryParse(modelFileName)))
|
||||||
.rotationY(((int) state.getValue(BlockStateProperties.HORIZONTAL_FACING).toYRot() + 180) % 360).build();
|
.rotationY(((int) state.getValue(BlockStateProperties.HORIZONTAL_FACING).toYRot() + 180) % 360).build();
|
||||||
|
|
||||||
@@ -33,13 +34,13 @@ public class PoweredTradingStationRegistrate {
|
|||||||
.build()
|
.build()
|
||||||
.register();
|
.register();
|
||||||
|
|
||||||
public static final BlockEntityEntry<PoweredTradingStationBlockEntity> POWERED_TRADING_STATION_BLOCK_ENTITY = TradingStation.registrate()
|
public static final BlockEntityEntry<PoweredTradingStationBlockEntity> BLOCK_ENTITY = TradingStation.registrate()
|
||||||
.blockEntity("powered_trading_station", PoweredTradingStationBlockEntity::new)
|
.blockEntity("powered_trading_station", PoweredTradingStationBlockEntity::new)
|
||||||
.validBlocks(POWERED_TRADING_STATION_BLOCK)
|
.validBlocks(BLOCK)
|
||||||
.renderer(() -> TradingStationBlockRenderer::new)
|
.renderer(() -> TradingStationBlockRenderer::new)
|
||||||
.register();
|
.register();
|
||||||
|
|
||||||
public static final MenuEntry<PoweredTradingStationMenu> POWERED_TRADING_STATION_MENU = TradingStation.registrate()
|
public static final MenuEntry<PoweredTradingStationMenu> MENU = TradingStation.registrate()
|
||||||
.menu("powered_trading_station", PoweredTradingStationMenu::factory, () -> PoweredTradingStationScreen::new)
|
.menu("powered_trading_station", PoweredTradingStationMenu::factory, () -> PoweredTradingStationScreen::new)
|
||||||
.register();
|
.register();
|
||||||
public static void register() {
|
public static void register() {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.oierbravo.trading_station.registrate;
|
|||||||
|
|
||||||
import com.oierbravo.trading_station.TradingStation;
|
import com.oierbravo.trading_station.TradingStation;
|
||||||
import com.oierbravo.trading_station.content.trading_station.*;
|
import com.oierbravo.trading_station.content.trading_station.*;
|
||||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationBlockEntity;
|
|
||||||
import com.tterrag.registrate.Registrate;
|
import com.tterrag.registrate.Registrate;
|
||||||
import com.tterrag.registrate.util.entry.BlockEntityEntry;
|
import com.tterrag.registrate.util.entry.BlockEntityEntry;
|
||||||
import com.tterrag.registrate.util.entry.BlockEntry;
|
import com.tterrag.registrate.util.entry.BlockEntry;
|
||||||
@@ -15,7 +14,7 @@ public class TradingStationRegistrate {
|
|||||||
private static final Registrate REGISTRATE = TradingStation.registrate()
|
private static final Registrate REGISTRATE = TradingStation.registrate()
|
||||||
.creativeModeTab(() -> ModCreativeTab.MAIN);
|
.creativeModeTab(() -> ModCreativeTab.MAIN);
|
||||||
|
|
||||||
public static final BlockEntry<TradingStationBlock> TRADING_STATION_BLOCK = TradingStation.registrate()
|
public static final BlockEntry<TradingStationBlock> BLOCK = TradingStation.registrate()
|
||||||
.block("trading_station", TradingStationBlock::new)
|
.block("trading_station", TradingStationBlock::new)
|
||||||
.lang("Trading Station")
|
.lang("Trading Station")
|
||||||
.blockstate((ctx, prov) ->
|
.blockstate((ctx, prov) ->
|
||||||
@@ -23,6 +22,8 @@ public class TradingStationRegistrate {
|
|||||||
String modelFileName = "trading_station:block/trading_station";
|
String modelFileName = "trading_station:block/trading_station";
|
||||||
if(state.getValue(BlockStateProperties.POWERED))
|
if(state.getValue(BlockStateProperties.POWERED))
|
||||||
modelFileName += "_powered";
|
modelFileName += "_powered";
|
||||||
|
if(state.getValue(BlockStateProperties.LIT))
|
||||||
|
modelFileName += "_lit";
|
||||||
return ConfiguredModel.builder().modelFile(prov.models().getExistingFile(ResourceLocation.tryParse(modelFileName)))
|
return ConfiguredModel.builder().modelFile(prov.models().getExistingFile(ResourceLocation.tryParse(modelFileName)))
|
||||||
.rotationY(((int) state.getValue(BlockStateProperties.HORIZONTAL_FACING).toYRot() + 180) % 360).build();
|
.rotationY(((int) state.getValue(BlockStateProperties.HORIZONTAL_FACING).toYRot() + 180) % 360).build();
|
||||||
|
|
||||||
@@ -32,13 +33,13 @@ public class TradingStationRegistrate {
|
|||||||
.blockEntity(TradingStationBlockEntity::new)
|
.blockEntity(TradingStationBlockEntity::new)
|
||||||
.build()
|
.build()
|
||||||
.register();
|
.register();
|
||||||
public static final BlockEntityEntry<TradingStationBlockEntity> TRADING_STATION_BLOCK_ENTITY = REGISTRATE
|
public static final BlockEntityEntry<TradingStationBlockEntity> BLOCK_ENTITY = REGISTRATE
|
||||||
.blockEntity("trading_station", TradingStationBlockEntity::new)
|
.blockEntity("trading_station", TradingStationBlockEntity::new)
|
||||||
.validBlocks(TRADING_STATION_BLOCK)
|
.validBlocks(BLOCK)
|
||||||
.renderer(() -> TradingStationBlockRenderer::new)
|
.renderer(() -> TradingStationBlockRenderer::new)
|
||||||
.register();
|
.register();
|
||||||
|
|
||||||
public static final MenuEntry<TradingStationMenu> TRADING_STATION_MENU = REGISTRATE
|
public static final MenuEntry<TradingStationMenu> MENU = REGISTRATE
|
||||||
.menu("trading_station",TradingStationMenu::factory, () -> TradingStationScreen::new)
|
.menu("trading_station",TradingStationMenu::factory, () -> TradingStationScreen::new)
|
||||||
.register();
|
.register();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user