✨ 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.jozufozu.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}")
|
||||
}
|
||||
//}
|
||||
|
||||
if (ct_enabled.toBoolean()) {
|
||||
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_version = 11.4.0.290
|
||||
|
||||
create_enabled = false;
|
||||
create_enabled = true;
|
||||
create_minecraft_version = 1.19.2
|
||||
flywheel_minecraft_version = 1.19.2
|
||||
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)]
|
||||
ac427e21e7a0915809800ce83800780c045678c6 assets/trading_station/blockstates/powered_trading_station.json
|
||||
391b0f87f6c9bd80e20dfc8b949e7dd99cd16fe9 assets/trading_station/blockstates/trading_station.json
|
||||
2c8a8b7c6874dcb7e5474ba19b33fbb2d166c834 assets/trading_station/lang/en_ud.json
|
||||
efb3401e9c37c753973bf81e4da4bb0946061a19 assets/trading_station/lang/en_us.json
|
||||
// 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)]
|
||||
d529016ef556a0231f5da8dd90e7b84a30aad7f7 assets/trading_station/blockstates/powered_trading_station.json
|
||||
d529016ef556a0231f5da8dd90e7b84a30aad7f7 assets/trading_station/blockstates/trading_station.json
|
||||
72f9bf61c9db46a4fefece27497879b91d0290e3 assets/trading_station/lang/en_ud.json
|
||||
b39694f8daf13daba09feddb32de6f23e9bf20ad assets/trading_station/lang/en_us.json
|
||||
373be6ce42eee460888161c967f098e5943e3778 assets/trading_station/models/item/powered_trading_station.json
|
||||
7ddda578b6d6072db924599a9959579470354897 assets/trading_station/models/item/trading_station.json
|
||||
c3b4c04c1cecdc5001fcddda7b30b11b15f0b2b2 data/trading_station/loot_tables/blocks/powered_trading_station.json
|
||||
|
||||
@@ -1,33 +1,63 @@
|
||||
{
|
||||
"variants": {
|
||||
"facing=east,powered=false": {
|
||||
"model": "trading_station:block/powered_trading_station",
|
||||
"facing=east,lit=false,powered=false": {
|
||||
"model": "trading_station:block/trading_station",
|
||||
"y": 90
|
||||
},
|
||||
"facing=east,powered=true": {
|
||||
"model": "trading_station:block/powered_trading_station_powered",
|
||||
"facing=east,lit=false,powered=true": {
|
||||
"model": "trading_station:block/trading_station_powered",
|
||||
"y": 90
|
||||
},
|
||||
"facing=north,powered=false": {
|
||||
"model": "trading_station:block/powered_trading_station"
|
||||
"facing=east,lit=true,powered=false": {
|
||||
"model": "trading_station:block/trading_station_lit",
|
||||
"y": 90
|
||||
},
|
||||
"facing=north,powered=true": {
|
||||
"model": "trading_station:block/powered_trading_station_powered"
|
||||
"facing=east,lit=true,powered=true": {
|
||||
"model": "trading_station:block/trading_station_powered_lit",
|
||||
"y": 90
|
||||
},
|
||||
"facing=south,powered=false": {
|
||||
"model": "trading_station:block/powered_trading_station",
|
||||
"facing=north,lit=false,powered=false": {
|
||||
"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
|
||||
},
|
||||
"facing=south,powered=true": {
|
||||
"model": "trading_station:block/powered_trading_station_powered",
|
||||
"facing=south,lit=false,powered=true": {
|
||||
"model": "trading_station:block/trading_station_powered",
|
||||
"y": 180
|
||||
},
|
||||
"facing=west,powered=false": {
|
||||
"model": "trading_station:block/powered_trading_station",
|
||||
"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",
|
||||
"y": 270
|
||||
},
|
||||
"facing=west,powered=true": {
|
||||
"model": "trading_station:block/powered_trading_station_powered",
|
||||
"facing=west,lit=false,powered=true": {
|
||||
"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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,64 @@
|
||||
{
|
||||
"variants": {
|
||||
"facing=east,powered=false": {
|
||||
"facing=east,lit=false,powered=false": {
|
||||
"model": "trading_station:block/trading_station",
|
||||
"y": 90
|
||||
},
|
||||
"facing=east,powered=true": {
|
||||
"facing=east,lit=false,powered=true": {
|
||||
"model": "trading_station:block/trading_station_powered",
|
||||
"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"
|
||||
},
|
||||
"facing=north,powered=true": {
|
||||
"facing=north,lit=false,powered=true": {
|
||||
"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",
|
||||
"y": 180
|
||||
},
|
||||
"facing=south,powered=true": {
|
||||
"facing=south,lit=false,powered=true": {
|
||||
"model": "trading_station:block/trading_station_powered",
|
||||
"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",
|
||||
"y": 270
|
||||
},
|
||||
"facing=west,powered=true": {
|
||||
"facing=west,lit=false,powered=true": {
|
||||
"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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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(){
|
||||
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.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("select_target.title"), "Select an output target");
|
||||
registrate().addRawLang(ModLang.key("select_target.button"), "Select target");
|
||||
registrate().addRawLang(ModLang.key("select_target.clear"), "Clear");
|
||||
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() {
|
||||
return REGISTRATE.get();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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 net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -32,8 +33,8 @@ public class ProgressComponentProvider implements IBlockComponentProvider, ISer
|
||||
|
||||
@Override
|
||||
public void appendServerData(CompoundTag compoundTag, ServerPlayer serverPlayer, Level level, BlockEntity blockEntity, boolean b) {
|
||||
if(blockEntity instanceof TradingStationBlockEntity){
|
||||
TradingStationBlockEntity trading_station = (TradingStationBlockEntity) blockEntity;
|
||||
if(blockEntity instanceof ITradingStationBlockEntity){
|
||||
ITradingStationBlockEntity trading_station = (ITradingStationBlockEntity) blockEntity;
|
||||
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.content.trading_station.TradingStationBlock;
|
||||
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 snownee.jade.api.*;
|
||||
|
||||
@@ -13,10 +15,12 @@ public class TradingStationPlugin implements IWailaPlugin {
|
||||
@Override
|
||||
public void register(IWailaCommonRegistration registration) {
|
||||
registration.registerBlockDataProvider(new ProgressComponentProvider(), TradingStationBlockEntity.class);
|
||||
//registration.registerBlockDataProvider(new ProgressComponentProvider(), PoweredTradingStationBlockEntity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerClient(IWailaClientRegistration registration) {
|
||||
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.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.TradingStationRegistrate;
|
||||
import mezz.jei.api.IModPlugin;
|
||||
import mezz.jei.api.JeiPlugin;
|
||||
import mezz.jei.api.constants.RecipeTypes;
|
||||
import mezz.jei.api.recipe.RecipeType;
|
||||
import mezz.jei.api.registration.IRecipeCatalystRegistration;
|
||||
import mezz.jei.api.registration.IRecipeCategoryRegistration;
|
||||
import mezz.jei.api.registration.IRecipeRegistration;
|
||||
import mezz.jei.api.registration.IRecipeTransferRegistration;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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.crafting.RecipeManager;
|
||||
|
||||
@@ -21,6 +27,7 @@ import java.util.Objects;
|
||||
|
||||
@JeiPlugin
|
||||
public class JEIPlugin implements IModPlugin {
|
||||
static RecipeType<TradingRecipe> TRAING_RECIPE = new RecipeType<>(TradingRecipeCategory.UID, TradingRecipe.class);
|
||||
|
||||
@Override
|
||||
public ResourceLocation getPluginUid() {
|
||||
@@ -35,8 +42,8 @@ public class JEIPlugin implements IModPlugin {
|
||||
|
||||
@Override
|
||||
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
|
||||
registration.addRecipeCatalyst(new ItemStack(TradingStationRegistrate.TRADING_STATION_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(TradingStationRegistrate.BLOCK.get()),new RecipeType<>(TradingRecipeCategory.UID, TradingRecipe.class));
|
||||
registration.addRecipeCatalyst(new ItemStack(PoweredTradingStationRegistrate.BLOCK.get()),new RecipeType<>(TradingRecipeCategory.UID, TradingRecipe.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,7 +51,14 @@ public class JEIPlugin implements IModPlugin {
|
||||
RecipeManager rm = Objects.requireNonNull(Minecraft.getInstance().level).getRecipeManager();
|
||||
|
||||
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.mojang.blaze3d.vertex.PoseStack;
|
||||
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.foundation.util.ModLang;
|
||||
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.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
|
||||
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++) {
|
||||
Ingredient ing = ingredients.get(index);
|
||||
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()));
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
@@ -111,7 +117,8 @@ public class TradingRecipeCategory implements IRecipeCategory<TradingRecipe> {
|
||||
IRecipeCategory.super.draw(recipe, recipeSlotsView, stack, mouseX, mouseY);
|
||||
IDrawableAnimated arrow = getArrow();
|
||||
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);
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
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.JsonObject;
|
||||
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.component.ComponentRole;
|
||||
import dev.latvian.mods.kubejs.recipe.component.RecipeComponent;
|
||||
import dev.latvian.mods.rhino.NativeArray;
|
||||
import dev.latvian.mods.rhino.NativeObject;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
|
||||
public class ExclusiveToConditionComponent implements RecipeComponent<BiomeCondition> {
|
||||
public static final RecipeComponent<BiomeCondition> BIOME_CONDITION= new ExclusiveToConditionComponent();
|
||||
import java.util.List;
|
||||
|
||||
public class ExclusiveToConditionComponent implements RecipeComponent<ExclusiveToCondition> {
|
||||
public static final RecipeComponent<ExclusiveToCondition> EXCLUSIVE_CONDITION = new ExclusiveToConditionComponent();
|
||||
|
||||
|
||||
public ComponentRole role() {
|
||||
return ComponentRole.OTHER;
|
||||
@@ -18,33 +24,26 @@ public class ExclusiveToConditionComponent implements RecipeComponent<BiomeCondi
|
||||
|
||||
@Override
|
||||
public Class<?> componentClass() {
|
||||
return BiomeCondition.class;
|
||||
return ExclusiveToCondition.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement write(RecipeJS recipe, BiomeCondition value) {
|
||||
public JsonElement write(RecipeJS recipe, ExclusiveToCondition 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());
|
||||
}
|
||||
private ExclusiveToCondition fromNativeArray(NativeArray pNativeArray){
|
||||
return ExclusiveToCondition.fromList(pNativeArray.stream().toList());
|
||||
}
|
||||
@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);
|
||||
public ExclusiveToCondition read(RecipeJS recipe, Object from) {
|
||||
if (from instanceof ExclusiveToCondition ec) {
|
||||
return ec;
|
||||
} else if(from instanceof NativeArray nativeArray){
|
||||
return fromNativeArray(nativeArray);
|
||||
|
||||
} 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.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.OutputItem;
|
||||
import dev.latvian.mods.kubejs.recipe.RecipeJS;
|
||||
@@ -14,7 +16,11 @@ public interface TradingRecipeSchema {
|
||||
RecipeKey<InputItem[]> INGREDIENTS = ItemComponents.INPUT_ARRAY.key("ingredients");
|
||||
RecipeKey<OutputItem> RESULT = ItemComponents.OUTPUT.key("result");
|
||||
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
|
||||
public JsonElement writeInputItem(InputItem value) {
|
||||
JsonObject json = super.writeInputItem(value).getAsJsonObject();
|
||||
@@ -24,6 +30,6 @@ public interface TradingRecipeSchema {
|
||||
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.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.oierbravo.trading_station.foundation.util.ModLang;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
@@ -96,10 +98,9 @@ public class BiomeCondition {
|
||||
}
|
||||
protected boolean testInternal(Biome b, LevelAccessor pLevel){
|
||||
if(biome == null)
|
||||
return false;
|
||||
if (biome.toString() != b.toString())
|
||||
return false;
|
||||
return true;
|
||||
return true;
|
||||
ResourceKey<Biome> key = pLevel.registryAccess().registryOrThrow(ForgeRegistries.BIOMES.getRegistryKey()).getResourceKey(b).get();
|
||||
return Objects.equals(getKeyOrThrow(biome).toString(), key.location().toString());
|
||||
};
|
||||
|
||||
public void write(FriendlyByteBuf buffer) {
|
||||
@@ -113,12 +114,21 @@ public class BiomeCondition {
|
||||
biome.readInternal(buffer);
|
||||
return biome;
|
||||
}
|
||||
public JsonObject serialize() {
|
||||
public JsonObject toJson() {
|
||||
JsonObject json = new JsonObject();
|
||||
writeInternal(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) {
|
||||
if (je == null || je.isJsonNull())
|
||||
return false;
|
||||
@@ -131,20 +141,12 @@ public class BiomeCondition {
|
||||
return true;
|
||||
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(){
|
||||
return toStringInternal();
|
||||
}
|
||||
public Component toComponent(){
|
||||
return ModLang.translate("trading.recipe.biome", toString());
|
||||
}
|
||||
|
||||
protected String toStringInternal(){
|
||||
if(biome == null)
|
||||
@@ -152,6 +154,7 @@ public class BiomeCondition {
|
||||
return ForgeRegistries.BIOMES.getKey(biome).toString();
|
||||
}
|
||||
|
||||
|
||||
public static class BiomeTagCondition extends BiomeCondition {
|
||||
|
||||
protected TagKey<Biome> tag;
|
||||
@@ -159,9 +162,8 @@ public class BiomeCondition {
|
||||
|
||||
@Override
|
||||
protected boolean testInternal(Biome b, LevelAccessor pLevel) {
|
||||
Registry<Biome> biomeRegistry = pLevel.registryAccess().registryOrThrow(ForgeRegistries.BIOMES.getRegistryKey());
|
||||
ResourceKey<Biome> key = biomeRegistry.getResourceKey(b).get();
|
||||
boolean result = biomeRegistry.getOrCreateTag(tag).contains(biomeRegistry.getOrCreateHolderOrThrow(key));
|
||||
Registry<Biome> biomeRegistry = pLevel.registryAccess().registryOrThrow(ForgeRegistries.BIOMES.getRegistryKey());
|
||||
ResourceKey<Biome> key = biomeRegistry.getResourceKey(b).get();
|
||||
return biomeRegistry.getOrCreateTag(tag).contains(biomeRegistry.getOrCreateHolderOrThrow(key));
|
||||
}
|
||||
|
||||
@@ -194,4 +196,5 @@ public class BiomeCondition {
|
||||
return "#" + tag.location().toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,116 @@
|
||||
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.crafting.*;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class TradingRecipe implements Recipe<SimpleContainer> {
|
||||
private final ResourceLocation id;
|
||||
@@ -20,22 +23,41 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
||||
|
||||
private final int processingTime;
|
||||
|
||||
private BiomeCondition biomeCondition;
|
||||
private ExclusiveToCondition exclusiveToCondition;
|
||||
|
||||
|
||||
public TradingRecipe(TradingRecipeParams params) {
|
||||
this.id = params.id;
|
||||
this.result = params.result;
|
||||
this.itemIngredients = params.itemIngredients;
|
||||
this.processingTime = params.processingTime;
|
||||
this.biomeCondition = params.biome;
|
||||
this.exclusiveToCondition = params.exclusiveTo;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
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)
|
||||
return false;
|
||||
if(pContainer.getContainerSize() != itemIngredients.size())
|
||||
return false;
|
||||
|
||||
if(!getBiomeCondition().test(biome,pLevel))
|
||||
return false;
|
||||
|
||||
int matchedIngredients = 0;
|
||||
for (int i = 0; i < itemIngredients.size(); i++) {
|
||||
Ingredient ingredient = itemIngredients.get(i);
|
||||
@@ -76,8 +98,18 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
||||
public boolean canCraftInDimensions(int pWidth, int pHeight) {
|
||||
return true;
|
||||
}
|
||||
public int getProcessingTime() {
|
||||
return processingTime;
|
||||
}
|
||||
|
||||
|
||||
public BiomeCondition getBiomeCondition(){
|
||||
return biomeCondition;
|
||||
}
|
||||
public ExclusiveToCondition getExclusiveToCondition(){
|
||||
return exclusiveToCondition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getResultItem() {
|
||||
return result.copy();
|
||||
@@ -86,6 +118,7 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
||||
return result.copy();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return id;
|
||||
@@ -103,6 +136,7 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
||||
public static class Type implements RecipeType<TradingRecipe> {
|
||||
private 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 class Serializer implements RecipeSerializer<TradingRecipe> {
|
||||
@@ -115,6 +149,8 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
||||
TradingRecipeBuilder builder = new TradingRecipeBuilder(id);
|
||||
NonNullList<Ingredient> itemIngredients = NonNullList.create();
|
||||
int processingTime = 1;
|
||||
BiomeCondition biomeCondition = BiomeCondition.EMPTY;
|
||||
ExclusiveToCondition exclusiveToCondition = ExclusiveToCondition.EMPTY;
|
||||
|
||||
for (JsonElement je : GsonHelper.getAsJsonArray(json, "ingredients")) {
|
||||
JsonObject jsonObject = je.getAsJsonObject();
|
||||
@@ -133,9 +169,19 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
||||
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)
|
||||
.withSingleItemOutput(result)
|
||||
.processingTime(processingTime);
|
||||
.processingTime(processingTime)
|
||||
.withBiomeCondition(biomeCondition)
|
||||
.exclusiveTo(exclusiveToCondition);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
@@ -145,6 +191,8 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
||||
TradingRecipeBuilder builder = new TradingRecipeBuilder(id);
|
||||
NonNullList<Ingredient> itemIngredients = NonNullList.create();
|
||||
int processingTime = 1;
|
||||
BiomeCondition biomeCondition = BiomeCondition.EMPTY;
|
||||
ExclusiveToCondition exclusiveToCondition = ExclusiveToCondition.EMPTY;
|
||||
|
||||
int size = buffer.readVarInt();
|
||||
for (int i = 0; i < size; i++)
|
||||
@@ -152,11 +200,17 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
||||
|
||||
ItemStack result = buffer.readItem();
|
||||
processingTime = buffer.readInt();
|
||||
biomeCondition = BiomeCondition.read(buffer);
|
||||
exclusiveToCondition = exclusiveToCondition.read(buffer);
|
||||
|
||||
|
||||
builder.withItemIngredients(itemIngredients)
|
||||
.withSingleItemOutput(result)
|
||||
.processingTime(processingTime);
|
||||
.processingTime(processingTime)
|
||||
.withBiomeCondition(biomeCondition)
|
||||
.exclusiveTo(exclusiveToCondition);
|
||||
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@@ -164,18 +218,19 @@ public class TradingRecipe implements Recipe<SimpleContainer> {
|
||||
public void toNetwork(FriendlyByteBuf buffer, TradingRecipe recipe) {
|
||||
NonNullList<Ingredient> itemIngredients = recipe.itemIngredients;
|
||||
int processingTime = recipe.getProcessingTime();
|
||||
|
||||
BiomeCondition biomeCondition = recipe.getBiomeCondition();
|
||||
ExclusiveToCondition exclusiveToCondition = recipe.getExclusiveToCondition();
|
||||
|
||||
buffer.writeVarInt(itemIngredients.size());
|
||||
itemIngredients.forEach(i -> i.toNetwork(buffer));
|
||||
buffer.writeItem(recipe.getResultItem());
|
||||
buffer.writeInt(processingTime);
|
||||
biomeCondition.write(buffer);
|
||||
exclusiveToCondition.write(buffer);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int getProcessingTime() {
|
||||
return processingTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,6 +36,21 @@ public class TradingRecipeBuilder {
|
||||
params.processingTime = time;
|
||||
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(){
|
||||
@@ -53,6 +68,9 @@ public class TradingRecipeBuilder {
|
||||
protected ItemStack result;
|
||||
protected int fuelConsumed;
|
||||
protected int processingTime;
|
||||
protected BiomeCondition biome;
|
||||
public ExclusiveToCondition exclusiveTo;
|
||||
|
||||
|
||||
protected TradingRecipeParams(ResourceLocation id) {
|
||||
this.id = id;
|
||||
@@ -60,6 +78,8 @@ public class TradingRecipeBuilder {
|
||||
result = ItemStack.EMPTY;
|
||||
fuelConsumed = 0;
|
||||
processingTime = 1;
|
||||
biome = BiomeCondition.EMPTY;
|
||||
exclusiveTo = ExclusiveToCondition.EMPTY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
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.registrate.ModRecipes;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.SimpleContainer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
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.energy.IEnergyStorage;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ITradingStationBlockEntity {
|
||||
public int progress = 0;
|
||||
@@ -16,16 +25,99 @@ public interface ITradingStationBlockEntity {
|
||||
|
||||
IItemHandler getTargetItemHandler();
|
||||
|
||||
BlockPos getBlockPos();
|
||||
|
||||
ItemStack getTargetItemStack();
|
||||
|
||||
Level getLevel();
|
||||
|
||||
BlockPos getBlockPos();
|
||||
|
||||
void setPreferedItem(ItemStack itemStack);
|
||||
|
||||
void setItemStack(int slot, ItemStack itemStack, ItemStackSyncS2CPacket.SlotType slotType);
|
||||
|
||||
|
||||
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;
|
||||
|
||||
import com.oierbravo.trading_station.registrate.PoweredTradingStationRegistrate;
|
||||
import com.oierbravo.trading_station.registrate.TradingStationRegistrate;
|
||||
import net.minecraft.core.BlockPos;
|
||||
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 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;
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class TradingStationBlock extends BaseEntityBlock {
|
||||
|
||||
public TradingStationBlock(Properties 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 super.getStateForPlacement(context)
|
||||
.setValue(HORIZONTAL_FACING, context.getHorizontalDirection().getOpposite())
|
||||
.setValue(POWERED, context.getLevel().hasNeighborSignal(context.getClickedPos()));
|
||||
.setValue(POWERED, context.getLevel().hasNeighborSignal(context.getClickedPos()))
|
||||
.setValue(LIT,false);
|
||||
}
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||
builder.add(HORIZONTAL_FACING).add(POWERED);
|
||||
builder.add(HORIZONTAL_FACING).add(POWERED).add(LIT);
|
||||
}
|
||||
@Override
|
||||
public RenderShape getRenderShape(BlockState pState) {
|
||||
@@ -79,7 +80,7 @@ public class TradingStationBlock extends BaseEntityBlock {
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
|
||||
return TradingStationRegistrate.TRADING_STATION_BLOCK_ENTITY.create(pPos, pState);
|
||||
return TradingStationRegistrate.BLOCK_ENTITY.create(pPos, pState);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,7 +96,7 @@ public class TradingStationBlock extends BaseEntityBlock {
|
||||
if(pLevel.isClientSide()) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
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.BlockEntityType;
|
||||
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 maxProgress = 1;
|
||||
|
||||
private int lastProgress = 0;
|
||||
private boolean isWorking = false;
|
||||
private BlockState lastBlockState;
|
||||
|
||||
protected final ContainerData containerData;
|
||||
|
||||
byte currentRedstoneMode = 0;
|
||||
|
||||
public TradingStationBlockEntity(BlockEntityType<?> pType, BlockPos pWorldPosition, BlockState pBlockState) {
|
||||
super(pType, pWorldPosition, pBlockState);
|
||||
updateTag = getPersistentData();
|
||||
lastBlockState = this.getBlockState();
|
||||
containerData = TradingStationBlockEntity.createContainerData(this);
|
||||
containerData = createContainerData();
|
||||
}
|
||||
public static ContainerData createContainerData(TradingStationBlockEntity pBlockEntity){
|
||||
public ContainerData createContainerData(){
|
||||
return new ContainerData(){
|
||||
@Override
|
||||
public int get(int pIndex){
|
||||
return switch (pIndex) {
|
||||
case 0 -> pBlockEntity.progress;
|
||||
case 1 -> pBlockEntity.maxProgress;
|
||||
case 0 -> progress;
|
||||
case 1 -> maxProgress;
|
||||
case 2 -> (int) currentRedstoneMode;
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
@@ -79,14 +86,15 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
||||
@Override
|
||||
public void set(int pIndex, int pValue) {
|
||||
switch (pIndex) {
|
||||
case 0 -> pBlockEntity.progress = pValue;
|
||||
case 1 -> pBlockEntity.maxProgress = pValue;
|
||||
case 0 -> progress = pValue;
|
||||
case 1 -> maxProgress = pValue;
|
||||
case 2 -> currentRedstoneMode = (byte) pValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -169,9 +177,16 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
||||
}
|
||||
@Override
|
||||
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 super.getCapability(cap, side);
|
||||
}
|
||||
|
||||
@@ -207,6 +222,7 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
||||
tag.put("target", targetItemHandler.serializeNBT());
|
||||
tag.putInt("trading_station.progress", progress);
|
||||
tag.putInt("trading_station.maxProgress", maxProgress);
|
||||
tag.putByte("redstoneMode", currentRedstoneMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -217,6 +233,7 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
||||
targetItemHandler.deserializeNBT(tag.getCompound("target"));
|
||||
progress = tag.getInt("trading_station.progress");
|
||||
maxProgress = tag.getInt("trading_station.maxProgress");
|
||||
currentRedstoneMode = tag.getByte("redstoneMode");
|
||||
}
|
||||
|
||||
public void drops() {
|
||||
@@ -235,89 +252,75 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
||||
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) {
|
||||
|
||||
if(pLevel.isClientSide()) {
|
||||
return;
|
||||
}
|
||||
if(!isPowered(this))
|
||||
if(!isPowered()) {
|
||||
setWorking(false);
|
||||
return;
|
||||
if(!canCraftItem())
|
||||
}
|
||||
if(!canCraftItem()) {
|
||||
setWorking(false);
|
||||
return;
|
||||
}
|
||||
|
||||
this.updateProgress();
|
||||
BlockEntity.setChanged(pLevel, pPos, pState);
|
||||
this.maxProgress = this.getProcessingTime(this);
|
||||
if (this.progress > this.maxProgress) {
|
||||
updateProgress();
|
||||
setWorking(true);
|
||||
|
||||
maxProgress = getProcessingTime();
|
||||
if (progress > maxProgress) {
|
||||
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(){
|
||||
this.progress += TradingStationConfig.PROGRESS_PER_TICK.get();
|
||||
|
||||
}
|
||||
private static boolean isPowered(TradingStationBlockEntity pBlockEntity){
|
||||
return pBlockEntity.getLevel().getBlockState(pBlockEntity.getBlockPos())
|
||||
public boolean isPowered() {
|
||||
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);
|
||||
}
|
||||
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()) {
|
||||
return false;
|
||||
@@ -326,9 +329,9 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
||||
&& 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){
|
||||
int enough = 0;
|
||||
@@ -376,6 +379,27 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
||||
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) {
|
||||
if(slotType == ItemStackSyncS2CPacket.SlotType.INPUT)
|
||||
@@ -392,15 +416,20 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTraderType() {
|
||||
return "basic";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getDisplayName() {
|
||||
return ModLang.translate("block.display");
|
||||
return Component.translatable("block.trading_station.trading_station");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
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) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.oierbravo.trading_station.content.trading_station;
|
||||
|
||||
import com.oierbravo.trading_station.foundation.gui.AbstractTradingMenu;
|
||||
import com.oierbravo.trading_station.foundation.gui.Coords2D;
|
||||
import com.oierbravo.trading_station.registrate.TradingStationRegistrate;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
@@ -12,14 +13,13 @@ import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TradingStationMenu extends AbstractTradingMenu {
|
||||
protected final int[] outputSlotCoords = {131,38};
|
||||
|
||||
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) {
|
||||
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) {
|
||||
@@ -27,14 +27,22 @@ public class TradingStationMenu extends AbstractTradingMenu {
|
||||
}
|
||||
@Override
|
||||
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
|
||||
public int[][] getInputSlotCoords() {
|
||||
return new int[][]{{19,38},{42,38}};
|
||||
public Coords2D[] getInputSlotCoords() {
|
||||
return new Coords2D[]{
|
||||
Coords2D.of(19,49),
|
||||
Coords2D.of(42,49)
|
||||
};
|
||||
}
|
||||
@Override
|
||||
public int[] getOutputSlotCoords() {
|
||||
return new int[]{131,38};
|
||||
public Coords2D getOutputSlotCoords() {
|
||||
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.content.trading_recipe.TradingRecipe;
|
||||
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.util.ModLang;
|
||||
import com.oierbravo.trading_station.registrate.ModRecipes;
|
||||
@@ -21,8 +22,6 @@ import java.util.Optional;
|
||||
|
||||
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");
|
||||
|
||||
public TradingStationScreen(TradingStationMenu pMenu, Inventory pPlayerInventory, Component pTitle) {
|
||||
@@ -33,15 +32,17 @@ public class TradingStationScreen extends AbstractTradingScreen<TradingStationMe
|
||||
|
||||
|
||||
@Override
|
||||
public int[] getProgressArrowCoords() {
|
||||
return progressArrowCoords;
|
||||
public Coords2D getProgressArrowCoords() {
|
||||
return Coords2D.of(79, 47);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int[] getTargetSelectButtonCoords() {
|
||||
return targetSelectButtonCoords;
|
||||
protected Coords2D getTargetSelectButtonCoords() {
|
||||
return Coords2D.of(131, 31);
|
||||
}
|
||||
|
||||
protected Coords2D getRedstoneButtonCoords() { return Coords2D.of(151,31); }
|
||||
|
||||
|
||||
@Override
|
||||
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.registrate.ModMessages;
|
||||
import com.oierbravo.trading_station.registrate.ModRecipes;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
@@ -51,17 +53,23 @@ public class TradingStationTargetSelectScreen extends Screen {
|
||||
protected int leftPos;
|
||||
protected int topPos;
|
||||
|
||||
private BlockPos blockPos;
|
||||
protected TradingStationTargetSelectScreen(Component pTitle) {
|
||||
super(pTitle);
|
||||
}
|
||||
public TradingStationTargetSelectScreen(ITradingStationBlockEntity pBlockEntity) {
|
||||
public TradingStationTargetSelectScreen(ITradingStationBlockEntity pBlockEntity, BlockPos pBlockPos) {
|
||||
this(ModLang.translate("select_target.title"));
|
||||
this.blockEntity = pBlockEntity;
|
||||
this.allPossibleOutputs = ModRecipes.getAllOutputs(pBlockEntity.getLevel());
|
||||
this.blockPos = pBlockPos;
|
||||
this.allPossibleOutputs = ModRecipes.getAllOutputs(pBlockEntity.getLevel(),pBlockEntity.getBiome(),pBlockEntity.getTraderType());
|
||||
resetDisplayedTargets();
|
||||
|
||||
}
|
||||
|
||||
public BlockPos getBlockPos() {
|
||||
return blockPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
@@ -73,7 +81,7 @@ public class TradingStationTargetSelectScreen extends Screen {
|
||||
Minecraft.getInstance().popGuiLayer();
|
||||
}));
|
||||
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().popGuiLayer();
|
||||
}));
|
||||
@@ -119,7 +127,7 @@ public class TradingStationTargetSelectScreen extends Screen {
|
||||
ItemStack target = allPossibleOutputs.get(index);
|
||||
int xStart = getGuiLeft() + targetBoxLeftPosOffset + firstDisplayedIndex % COLUMNS * TARGET_BOX_SIZE + 1;
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -133,7 +141,7 @@ public class TradingStationTargetSelectScreen extends Screen {
|
||||
int xStart = getGuiLeft() + targetBoxLeftPosOffset + firstDisplayedIndex % COLUMNS * TARGET_BOX_SIZE + 1;
|
||||
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) {
|
||||
renderTooltip(pPoseStack, target, pMouseX, pMouseY);
|
||||
@@ -151,7 +159,7 @@ public class TradingStationTargetSelectScreen extends Screen {
|
||||
itemRenderer.blitOffset = 2000.0f;
|
||||
|
||||
itemRenderer.renderAndDecorateItem(pItemStack, pX, pY);
|
||||
itemRenderer.renderGuiItemDecorations(font, pItemStack, pX, pY, "");
|
||||
itemRenderer.renderGuiItemDecorations(font, pItemStack, pX, pY);
|
||||
|
||||
setBlitOffset(0);
|
||||
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)) {
|
||||
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().popGuiLayer();
|
||||
return true;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class PoweredTradingStationBlock extends TradingStationBlock {
|
||||
@Nullable
|
||||
@Override
|
||||
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
|
||||
@@ -36,7 +36,7 @@ public class PoweredTradingStationBlock extends TradingStationBlock {
|
||||
if(pLevel.isClientSide()) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,12 @@ public class PoweredTradingStationBlockEntity extends TradingStationBlockEntity
|
||||
public IEnergyStorage getEnergyStorage() {
|
||||
return this.energyStorage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTraderType() {
|
||||
return "powered";
|
||||
}
|
||||
|
||||
public void setRemoved() {
|
||||
super.setRemoved();
|
||||
}
|
||||
@@ -79,7 +85,7 @@ public class PoweredTradingStationBlockEntity extends TradingStationBlockEntity
|
||||
}
|
||||
|
||||
public Component getDisplayName() {
|
||||
return ModLang.translate("powered_trading_station.block.display");
|
||||
return Component.translatable("block.trading_station.powered_trading_station");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -103,7 +109,7 @@ public class PoweredTradingStationBlockEntity extends TradingStationBlockEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canCraftItem() {
|
||||
public boolean canCraftItem() {
|
||||
Level level = this.getLevel();
|
||||
if(level == null)
|
||||
return false;
|
||||
|
||||
@@ -12,7 +12,7 @@ public class PoweredTradingStationConfig {
|
||||
COMMON_BUILDER.comment("Settings for the Powered Trading Station").push("powered_trading_station");
|
||||
PROGRESS_PER_TICK = COMMON_BUILDER
|
||||
.comment("How much progress per tick")
|
||||
.defineInRange("progressPerTick", 1, 1, Integer.MAX_VALUE);
|
||||
.defineInRange("progressPerTick", 5, 1, Integer.MAX_VALUE);
|
||||
ENERGY_CAPACITY = COMMON_BUILDER
|
||||
.comment("How much energy capacity has")
|
||||
.defineInRange("energyCapacity", 64000, 1, Integer.MAX_VALUE);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.oierbravo.trading_station.content.trading_station.powered;
|
||||
|
||||
import com.oierbravo.trading_station.foundation.gui.AbstractTradingMenu;
|
||||
import com.oierbravo.trading_station.foundation.gui.Coords2D;
|
||||
import com.oierbravo.trading_station.registrate.PoweredTradingStationRegistrate;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
@@ -13,11 +14,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PoweredTradingStationMenu extends AbstractTradingMenu {
|
||||
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) {
|
||||
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) {
|
||||
@@ -25,14 +26,21 @@ public class PoweredTradingStationMenu extends AbstractTradingMenu {
|
||||
}
|
||||
@Override
|
||||
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
|
||||
public int[][] getInputSlotCoords() {
|
||||
return new int[][]{{28,38},{51,38}};
|
||||
public Coords2D[] getInputSlotCoords() {
|
||||
return new Coords2D[]{
|
||||
Coords2D.of(28,47),
|
||||
Coords2D.of(51,47)
|
||||
};
|
||||
}
|
||||
@Override
|
||||
public int[] getOutputSlotCoords() {
|
||||
return new int[]{131,38};
|
||||
public Coords2D getOutputSlotCoords() {
|
||||
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.TradingStationTargetSelectScreen;
|
||||
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.FakeItemRenderer;
|
||||
import com.oierbravo.trading_station.foundation.util.ModLang;
|
||||
@@ -24,9 +25,7 @@ import java.util.Optional;
|
||||
|
||||
public class PoweredTradingStationScreen extends AbstractTradingScreen<PoweredTradingStationMenu> {
|
||||
|
||||
protected static int[] progressArrowCoords = {79,47};
|
||||
protected static int[] targetSelectButtonCoords = {131,18};
|
||||
private static final ResourceLocation TEXTURE = TradingStation.asResource("textures/gui/powered_trading_station.png");
|
||||
private static final ResourceLocation TEXTURE = TradingStation.asResource("textures/gui/trading_station.png");
|
||||
private EnergyDisplayTooltipArea energyInfoArea;
|
||||
|
||||
|
||||
@@ -48,9 +47,17 @@ public class PoweredTradingStationScreen extends AbstractTradingScreen<PoweredTr
|
||||
protected void renderBg(PoseStack pPoseStack, float pPartialTick, int pMouseX, int pMouseY) {
|
||||
|
||||
super.renderBg(pPoseStack, pPartialTick, pMouseX, pMouseY);
|
||||
RenderSystem.setShaderTexture(0, getTexture());
|
||||
|
||||
renderSlotPlaceholder(pPoseStack,((width - imageWidth) / 2) + 7,((height - imageHeight) / 2) + 23);
|
||||
|
||||
energyInfoArea.render(pPoseStack);
|
||||
|
||||
|
||||
}
|
||||
private void renderSlotPlaceholder(PoseStack pPoseStack, int pX, int pY){
|
||||
this.blit(pPoseStack, pX , pY , 0, 182,11, 32);
|
||||
|
||||
}
|
||||
@Override
|
||||
protected void renderLabels(PoseStack pPoseStack, int pMouseX, int pMouseY) {
|
||||
@@ -73,13 +80,13 @@ public class PoweredTradingStationScreen extends AbstractTradingScreen<PoweredTr
|
||||
|
||||
|
||||
@Override
|
||||
protected int[] getProgressArrowCoords() {
|
||||
return progressArrowCoords;
|
||||
protected Coords2D getProgressArrowCoords() {
|
||||
return Coords2D.of(79, 47);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int[] getTargetSelectButtonCoords() {
|
||||
return targetSelectButtonCoords;
|
||||
protected Coords2D getTargetSelectButtonCoords() {
|
||||
return Coords2D.of(131, 29);
|
||||
}
|
||||
|
||||
protected Coords2D getRedstoneButtonCoords() { return Coords2D.of(151,28); }
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.oierbravo.trading_station.foundation.gui;
|
||||
|
||||
import com.oierbravo.trading_station.content.trading_station.ITradingStationBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
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){
|
||||
super(pMenuType, pContainerId);
|
||||
checkContainerSize(pInv, 3);
|
||||
checkContainerDataCount(pData,3);
|
||||
blockPos = pBlockEntity.getBlockPos();
|
||||
blockEntity = (ITradingStationBlockEntity) pBlockEntity;
|
||||
level = pInv.player.getLevel();
|
||||
containerData = pData;
|
||||
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.addSlot(new SlotItemHandler(itemHandler,0, getInputSlotCoords()[0][0],getInputSlotCoords()[0][1]));
|
||||
this.addSlot(new SlotItemHandler(itemHandler,1, getInputSlotCoords()[1][0],getInputSlotCoords()[1][1]));
|
||||
this.addSlot(new SlotItemHandler(itemHandler,0, getInputSlotCoords()[0].x,getInputSlotCoords()[0].y));
|
||||
this.addSlot(new SlotItemHandler(itemHandler,1, getInputSlotCoords()[1].x,getInputSlotCoords()[1].y));
|
||||
});
|
||||
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){
|
||||
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
|
||||
public abstract boolean stillValid(Player pPlayer);
|
||||
|
||||
private BlockPos blockPos;
|
||||
public byte getCurrentRedstoneMode(){
|
||||
return (byte) this.containerData.get(2);
|
||||
//return 0;
|
||||
}
|
||||
public int getScaledProgress() {
|
||||
int progress = this.containerData.get(0);
|
||||
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;
|
||||
}
|
||||
public BlockPos getBlockPos(){
|
||||
return blockPos;
|
||||
}
|
||||
public boolean isCrafting() {
|
||||
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) {
|
||||
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) {
|
||||
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.TradingStationTargetSelectScreen;
|
||||
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.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 net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.client.gui.widget.ExtendedButton;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
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) {
|
||||
super(pMenu, pPlayerInventory, pTitle);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
this.titleLabelX = 4;
|
||||
this.titleLabelY = 4;
|
||||
this.titleLabelY = 13;
|
||||
this.inventoryLabelY = 100000;
|
||||
this.addRenderableWidget(new ExtendedButton(leftPos + getTargetSelectButtonCoords()[0],topPos + getTargetSelectButtonCoords()[1],16,16, ModLang.translate("select_target.button"), btn ->{
|
||||
TradingStationTargetSelectScreen screen = new TradingStationTargetSelectScreen( this.menu.blockEntity);
|
||||
Minecraft.getInstance().pushGuiLayer(screen);
|
||||
this.imageWidth = 176;
|
||||
this.imageHeight = 146;
|
||||
|
||||
addTargetSelectButton();
|
||||
|
||||
currentRedstoneMode = menu.getCurrentRedstoneMode();
|
||||
addRedstoneButton();
|
||||
|
||||
for (Map.Entry<String, Button> button : buttons.entrySet()) {
|
||||
addRenderableWidget(button.getValue());
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
protected abstract ResourceLocation getTexture();
|
||||
|
||||
@Override
|
||||
protected void renderBg(PoseStack pPoseStack, float pPartialTick, int pMouseX, int pMouseY) {
|
||||
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);
|
||||
|
||||
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()){
|
||||
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){
|
||||
for(int index = 0; index < recipe.getIngredients().size(); index++){
|
||||
Ingredient ingredient = recipe.getIngredients().get(index);
|
||||
int[][] coords = this.menu.getInputSlotCoords();
|
||||
|
||||
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
|
||||
public void render(PoseStack pPoseStack, int pMouseX, int pMouseY, float 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) {
|
||||
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;
|
||||
|
||||
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.entity.ItemRenderer;
|
||||
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.resources.model.BakedModel;
|
||||
import net.minecraft.world.inventory.InventoryMenu;
|
||||
@@ -61,9 +62,9 @@ public class FakeItemRenderer {
|
||||
if (!model.usesBlockLight()) {
|
||||
Lighting.setupForFlatItems();
|
||||
}
|
||||
|
||||
MultiBufferSource.BufferSource bufferSource = MINECRAFT.renderBuffers().bufferSource();
|
||||
ITEM_RENDERER.render(pItemStack,
|
||||
|
||||
ITEM_RENDERER.render(pItemStack,
|
||||
ItemTransforms.TransformType.GUI,
|
||||
false,
|
||||
new PoseStack(),
|
||||
@@ -84,7 +85,7 @@ public class FakeItemRenderer {
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -92,6 +93,7 @@ public class FakeItemRenderer {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
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.ModelManager;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
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);
|
||||
RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_BLOCKS);
|
||||
RenderSystem.enableBlend();
|
||||
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.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.scale(1.0F, -1.0F, 1.0F);
|
||||
posestack.scale(scale, scale, scale);
|
||||
RenderSystem.applyModelViewMatrix();
|
||||
PoseStack posestack1 = new PoseStack();
|
||||
MultiBufferSource.BufferSource multibuffersource$buffersource = Minecraft.getInstance().renderBuffers().bufferSource();
|
||||
boolean flag = !p_115131_.usesBlockLight();
|
||||
boolean flag = !pBakedModel.usesBlockLight();
|
||||
if (flag) {
|
||||
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();
|
||||
RenderSystem.enableDepthTest();
|
||||
if (flag) {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.oierbravo.trading_station.foundation.util;
|
||||
|
||||
import com.oierbravo.trading_station.TradingStation;
|
||||
import com.simibubi.create.foundation.utility.LangBuilder;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -9,10 +11,17 @@ public class ModLang {
|
||||
public static String asId(String name) {
|
||||
return name.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
public static Component translate(String key){
|
||||
return Component.translatable(TradingStation.MODID + '.' + key);
|
||||
public static MutableComponent translate(String key, Object... args){
|
||||
return Component.translatable(TradingStation.MODID + '.' + key,resolveBuilders(args));
|
||||
}
|
||||
public static String key(String 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) {
|
||||
blockEntity.setRedstoneMode(message.mode);
|
||||
blockEntity.setChanged();
|
||||
|
||||
}
|
||||
});
|
||||
context.setPacketHandled(true);
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.oierbravo.trading_station.registrate;
|
||||
import com.oierbravo.trading_station.TradingStation;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
public class ModCreativeTab extends CreativeModeTab {
|
||||
public static ModCreativeTab MAIN;
|
||||
@@ -16,7 +15,7 @@ public class ModCreativeTab extends CreativeModeTab {
|
||||
|
||||
@Override
|
||||
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.network.packets.GhostItemSyncC2SPacket;
|
||||
import com.oierbravo.trading_station.network.packets.ItemStackSyncS2CPacket;
|
||||
import com.oierbravo.trading_station.network.packets.RedstoneModeSyncC2SPacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.network.NetworkDirection;
|
||||
@@ -41,6 +42,12 @@ public class ModMessages {
|
||||
.consumerMainThread(GhostItemSyncC2SPacket::handle)
|
||||
.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) {
|
||||
|
||||
@@ -7,11 +7,13 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -29,11 +31,25 @@ public class ModRecipes {
|
||||
public static Optional<TradingRecipe> find(SimpleContainer pInv, Level pLevel) {
|
||||
if(pLevel.isClientSide())
|
||||
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()
|
||||
.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){
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.oierbravo.trading_station.registrate;
|
||||
|
||||
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.powered.PoweredTradingStationBlock;
|
||||
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;
|
||||
|
||||
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)
|
||||
.lang("Powered Trading Station")
|
||||
.blockstate((ctx, prov) ->
|
||||
@@ -23,6 +22,8 @@ public class PoweredTradingStationRegistrate {
|
||||
String modelFileName = "trading_station:block/powered_trading_station";
|
||||
if(state.getValue(BlockStateProperties.POWERED))
|
||||
modelFileName += "_powered";
|
||||
if(state.getValue(BlockStateProperties.LIT))
|
||||
modelFileName += "_lit";
|
||||
return ConfiguredModel.builder().modelFile(prov.models().getExistingFile(ResourceLocation.tryParse(modelFileName)))
|
||||
.rotationY(((int) state.getValue(BlockStateProperties.HORIZONTAL_FACING).toYRot() + 180) % 360).build();
|
||||
|
||||
@@ -33,13 +34,13 @@ public class PoweredTradingStationRegistrate {
|
||||
.build()
|
||||
.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)
|
||||
.validBlocks(POWERED_TRADING_STATION_BLOCK)
|
||||
.validBlocks(BLOCK)
|
||||
.renderer(() -> TradingStationBlockRenderer::new)
|
||||
.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)
|
||||
.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.content.trading_station.*;
|
||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationBlockEntity;
|
||||
import com.tterrag.registrate.Registrate;
|
||||
import com.tterrag.registrate.util.entry.BlockEntityEntry;
|
||||
import com.tterrag.registrate.util.entry.BlockEntry;
|
||||
@@ -15,7 +14,7 @@ public class TradingStationRegistrate {
|
||||
private static final Registrate REGISTRATE = TradingStation.registrate()
|
||||
.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)
|
||||
.lang("Trading Station")
|
||||
.blockstate((ctx, prov) ->
|
||||
@@ -23,6 +22,8 @@ public class TradingStationRegistrate {
|
||||
String modelFileName = "trading_station:block/trading_station";
|
||||
if(state.getValue(BlockStateProperties.POWERED))
|
||||
modelFileName += "_powered";
|
||||
if(state.getValue(BlockStateProperties.LIT))
|
||||
modelFileName += "_lit";
|
||||
return ConfiguredModel.builder().modelFile(prov.models().getExistingFile(ResourceLocation.tryParse(modelFileName)))
|
||||
.rotationY(((int) state.getValue(BlockStateProperties.HORIZONTAL_FACING).toYRot() + 180) % 360).build();
|
||||
|
||||
@@ -32,13 +33,13 @@ public class TradingStationRegistrate {
|
||||
.blockEntity(TradingStationBlockEntity::new)
|
||||
.build()
|
||||
.register();
|
||||
public static final BlockEntityEntry<TradingStationBlockEntity> TRADING_STATION_BLOCK_ENTITY = REGISTRATE
|
||||
public static final BlockEntityEntry<TradingStationBlockEntity> BLOCK_ENTITY = REGISTRATE
|
||||
.blockEntity("trading_station", TradingStationBlockEntity::new)
|
||||
.validBlocks(TRADING_STATION_BLOCK)
|
||||
.validBlocks(BLOCK)
|
||||
.renderer(() -> TradingStationBlockRenderer::new)
|
||||
.register();
|
||||
|
||||
public static final MenuEntry<TradingStationMenu> TRADING_STATION_MENU = REGISTRATE
|
||||
public static final MenuEntry<TradingStationMenu> MENU = REGISTRATE
|
||||
.menu("trading_station",TradingStationMenu::factory, () -> TradingStationScreen::new)
|
||||
.register();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user