Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加rei支持 #984

Merged
merged 11 commits into from
Jun 29, 2024
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.dubhe.anvilcraft.api;

import com.mojang.logging.LogUtils;
import dev.dubhe.anvilcraft.AnvilCraft;
import dev.dubhe.anvilcraft.block.InductionLightBlock;
import dev.dubhe.anvilcraft.block.state.LightColor;
Expand All @@ -16,7 +15,6 @@
import net.minecraft.world.level.block.NyliumBlock;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;

import java.util.Collections;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import dev.dubhe.anvilcraft.data.recipe.anvil.AnvilRecipe;
import dev.dubhe.anvilcraft.init.ModRecipeTypes;
import lombok.Getter;
import net.minecraft.server.MinecraftServer;
import lombok.Setter;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.BlastingRecipe;
import net.minecraft.world.item.crafting.CampfireCookingRecipe;
Expand All @@ -22,44 +23,42 @@
import java.util.List;

public class AnvilRecipeManager {
@Setter
@Getter
private static List<AnvilRecipe> anvilRecipeList = List.of();
public static List<AnvilRecipe> externalRecipeList = new ArrayList<>();

/**
* 更新配方
*
* @param server 服务器实例
*/
public static void updateRecipes(@NotNull MinecraftServer server) {
RecipeManager manager = server.getRecipeManager();
public static void updateRecipes(@NotNull RecipeManager manager, @NotNull RegistryAccess registryAccess) {
ArrayList<AnvilRecipe> anvilRecipes = new ArrayList<>(manager.getAllRecipesFor(ModRecipeTypes.ANVIL_RECIPE));
AnvilCraft.EVENT_BUS.post(new RecipeReloadEvent());
anvilRecipes.addAll(externalRecipeList);
externalRecipeList = new ArrayList<>();
List<ItemStack> needFilter = new ArrayList<>();
for (CampfireCookingRecipe recipe : manager.getAllRecipesFor(RecipeType.CAMPFIRE_COOKING)) {
AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, server.registryAccess());
AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, registryAccess);
if (anvilRecipe != null) anvilRecipes.add(anvilRecipe);
}
for (SmokingRecipe recipe : manager.getAllRecipesFor(RecipeType.SMOKING)) {
needFilter.add(recipe.getResultItem(server.registryAccess()));
AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, server.registryAccess());
needFilter.add(recipe.getResultItem(registryAccess));
AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, registryAccess);
if (anvilRecipe != null) anvilRecipes.add(anvilRecipe);
}
for (BlastingRecipe recipe : manager.getAllRecipesFor(RecipeType.BLASTING)) {
needFilter.add(recipe.getResultItem(server.registryAccess()));
AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, server.registryAccess());
needFilter.add(recipe.getResultItem(registryAccess));
AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, registryAccess);
if (anvilRecipe != null) anvilRecipes.add(anvilRecipe);
}
for (SmeltingRecipe recipe : manager.getAllRecipesFor(RecipeType.SMELTING)) {
ItemStack item = recipe.getResultItem(server.registryAccess());
ItemStack item = recipe.getResultItem(registryAccess);
if (needFilter.stream().anyMatch(stack -> item.is(stack.getItem()))) continue;
AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, server.registryAccess());
AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, registryAccess);
if (anvilRecipe != null) anvilRecipes.add(anvilRecipe);
}
for (CraftingRecipe recipe : manager.getAllRecipesFor(RecipeType.CRAFTING)) {
AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, server.registryAccess());
AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, registryAccess);
if (anvilRecipe != null) anvilRecipes.add(anvilRecipe);
}
anvilRecipeList = Collections.synchronizedList(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package dev.dubhe.anvilcraft.api.tooltip.impl;

import dev.dubhe.anvilcraft.api.power.IPowerComponent;
import dev.dubhe.anvilcraft.api.power.IPowerConsumer;
import dev.dubhe.anvilcraft.api.power.IPowerProducer;
import dev.dubhe.anvilcraft.api.power.PowerComponentInfo;
import dev.dubhe.anvilcraft.api.power.PowerComponentType;
import dev.dubhe.anvilcraft.api.power.SimplePowerGrid;
Expand All @@ -13,7 +11,6 @@
import net.minecraft.network.chat.Style;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@
import dev.dubhe.anvilcraft.data.recipe.transform.MobTransformContainer;
import dev.dubhe.anvilcraft.init.ModBlockEntities;
import dev.dubhe.anvilcraft.init.ModRecipeTypes;

import java.util.Objects;

import lombok.Getter;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.server.commands.data.EntityDataAccessor;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
Expand All @@ -27,7 +23,6 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BeaconBeamBlock;
Expand All @@ -42,7 +37,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.Objects;

public class CorruptedBeaconBlockEntity extends BlockEntity {
List<BeaconBeamSection> beamSections = Lists.newArrayList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public static void init(@NotNull RegistrateLangProvider provider) {
(item, s) -> provider.add(TooltipEventListener.getTranslationKey(item), s)
);
provider.add("tooltip.anvilcraft.item.reinforced_concrete", "Creeper proof");
provider.add("tooltip.anvilcraft.item.recipe.processing.chance", "%1$s%% Chance");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,15 @@

import static dev.dubhe.anvilcraft.api.power.IPowerComponent.OVERLOAD;


@Getter
@SuppressWarnings("unused")
public class AnvilRecipe implements Recipe<AnvilCraftingContainer> {
private final ResourceLocation id;
@Getter
private final List<RecipePredicate> predicates = new ArrayList<>();
@Getter
private final List<RecipeOutcome> outcomes = new ArrayList<>();
private final ItemStack icon;
private final Map<String, CompoundTag> data = new HashMap<>();
@Getter
private AnvilRecipeType anvilRecipeType = AnvilRecipeType.GENERIC;

public AnvilRecipe(ResourceLocation id, ItemStack icon) {
Expand Down Expand Up @@ -937,7 +936,7 @@ public static void init() {
if (recipe.getIngredients().isEmpty()) return null;
return new AnvilRecipe(
AnvilCraft.of(recipe.getId().getPath() + "_translate_from_smelting_recipe"),
recipe.getResultItem(registryAccess)
recipe.getResultItem(registryAccess).copy()
)
.setAnvilRecipeType(AnvilRecipeType.SUPER_HEATING)
.addPredicates(
Expand All @@ -947,7 +946,7 @@ public static void init() {
),
new HasBlock(new Vec3(0, -1, 0), new HasBlock.ModBlockPredicate().block(Blocks.CAULDRON))
)
.addOutcomes(new SpawnItem(new Vec3(0, -1, 0), 1, recipe.getResultItem(registryAccess)))
.addOutcomes(new SpawnItem(new Vec3(0, -1, 0), 1, recipe.getResultItem(registryAccess).copy().copy()))
.addPredicates(HasItemIngredient.of(new Vec3(0, -1, 0), recipe.getIngredients().get(0)));
}

Expand All @@ -960,7 +959,7 @@ public static void init() {
Ingredient ingredient = recipe.getIngredients().get(0);
AnvilRecipe anvilRecipe = new AnvilRecipe(
AnvilCraft.of(recipe.getId().getPath() + "_translate_from_blasting_recipe"),
recipe.getResultItem(registryAccess)
recipe.getResultItem(registryAccess).copy()
)
.setAnvilRecipeType(AnvilRecipeType.SUPER_HEATING)
.addPredicates(
Expand All @@ -971,7 +970,7 @@ public static void init() {
new HasBlock(new Vec3(0, -1, 0), new HasBlock.ModBlockPredicate().block(Blocks.CAULDRON))
)
.addPredicates(HasItemIngredient.of(new Vec3(0, -1, 0), ingredient));
ItemStack resultItem = recipe.getResultItem(registryAccess);
ItemStack resultItem = recipe.getResultItem(registryAccess).copy();
for (ItemStack item : ingredient.getItems()) {
if (item.is(ModItemTags.RAW_ORES)
|| item.is(ModItemTags.RAW_ORES_FORGE)
Expand All @@ -992,7 +991,7 @@ public static void init() {
if (recipe.getIngredients().isEmpty()) return null;
return new AnvilRecipe(
AnvilCraft.of(recipe.getId().getPath() + "_translate_from_smoking_recipe"),
recipe.getResultItem(registryAccess)
recipe.getResultItem(registryAccess).copy()
)
.setAnvilRecipeType(AnvilRecipeType.COOKING)
.addPredicates(
Expand All @@ -1002,7 +1001,7 @@ public static void init() {
),
new HasBlock(new Vec3(0, -1, 0), new HasBlock.ModBlockPredicate().block(Blocks.CAULDRON))
)
.addOutcomes(new SpawnItem(new Vec3(0, -1, 0), 1, recipe.getResultItem(registryAccess)))
.addOutcomes(new SpawnItem(new Vec3(0, -1, 0), 1, recipe.getResultItem(registryAccess).copy()))
.addPredicates(HasItemIngredient.of(new Vec3(0, -1, 0), recipe.getIngredients().get(0)));
}

Expand All @@ -1014,7 +1013,7 @@ public static void init() {
if (recipe.getIngredients().isEmpty()) return null;
return new AnvilRecipe(
AnvilCraft.of(recipe.getId().getPath() + "_translate_from_campfire_recipe"),
recipe.getResultItem(registryAccess)
recipe.getResultItem(registryAccess).copy()
)
.setAnvilRecipeType(AnvilRecipeType.COOKING)
.addPredicates(
Expand All @@ -1026,7 +1025,7 @@ public static void init() {
new Vec3(0, -1, 0),
new HasBlock.ModBlockPredicate().block(Blocks.CAULDRON))
)
.addOutcomes(new SpawnItem(new Vec3(0, -1, 0), 1, recipe.getResultItem(registryAccess)))
.addOutcomes(new SpawnItem(new Vec3(0, -1, 0), 1, recipe.getResultItem(registryAccess).copy()))
.addPredicates(HasItemIngredient.of(new Vec3(0, -1, 0), recipe.getIngredients().get(0)));
}

Expand All @@ -1035,10 +1034,10 @@ public static void init() {
*/
public static @Nullable AnvilRecipe of(@NotNull CraftingRecipe recipe, RegistryAccess registryAccess) {
if (recipe.getIngredients().isEmpty()) return null;
ItemStack resultItem = recipe.getResultItem(registryAccess);
ItemStack resultItem = recipe.getResultItem(registryAccess).copy();
AnvilRecipe anvilRecipe = new AnvilRecipe(
AnvilCraft.of(recipe.getId().getPath() + "_translate_from_crafting_recipe"),
recipe.getResultItem(registryAccess)
recipe.getResultItem(registryAccess).copy()
).addOutcomes(new SpawnItem(new Vec3(0.0, -1.0, 0.0), 1.0, resultItem));
if (recipe instanceof ShapedRecipe shapedRecipe) {
NonNullList<Ingredient> ingredients = shapedRecipe.getIngredients();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.commands.data.EntityDataAccessor;
Expand All @@ -28,7 +27,6 @@
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;

import javax.swing.text.html.Option;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public class ServerEventListener {
public void onServerStarted(@NotNull ServerStartedEvent event) {
ModHammerInits.init();
HammerManager.register();
AnvilRecipeManager.updateRecipes(event.getServer());
AnvilRecipeManager.updateRecipes(event.getServer().getRecipeManager(), event.getServer().registryAccess());
LevelLoadManager.notifyServerStarted();
ModLootContextParamSet.register();
}

@SubscribeEvent
public void onServerEndDataPackReload(@NotNull ServerEndDataPackReloadEvent event) {
AnvilRecipeManager.updateRecipes(event.getServer());
AnvilRecipeManager.updateRecipes(event.getServer().getRecipeManager(), event.getServer().registryAccess());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.dubhe.anvilcraft.AnvilCraft;
import dev.dubhe.anvilcraft.api.network.Network;
import dev.dubhe.anvilcraft.network.ClientRecipeManagerSyncPack;
import dev.dubhe.anvilcraft.network.ClientboundMutedSoundSyncPacket;
import dev.dubhe.anvilcraft.network.HammerUsePack;
import dev.dubhe.anvilcraft.network.HeliostatsIrradiationPack;
Expand Down Expand Up @@ -91,6 +92,11 @@ public class ModNetworks {
HeliostatsIrradiationPack.class, HeliostatsIrradiationPack::new
);

public static final ResourceLocation CLIENT_RECIPE_MANAGER_SYNC = Network.register(
AnvilCraft.of("client_recipe_manager_sync"),
ClientRecipeManagerSyncPack.class, ClientRecipeManagerSyncPack::new
);

public static void register() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private DoubleBlockIcon(@Nullable BlockWidget widget1, @Nullable BlockWidget wid
}

/**
* REI
* EMI
*/
public static @NotNull DoubleBlockIcon of(@Nullable BlockState state1, @Nullable BlockState state2) {
return new DoubleBlockIcon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class BlockWidget extends Widget implements DrawableWidgetConsumer {
private int size = 25;

/**
* REI
* EMI
*/
public BlockWidget(BlockState blockState, int posY, int offsetX, int offsetY) {
this.blockState = blockState;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package dev.dubhe.anvilcraft.integration.rei;

import dev.dubhe.anvilcraft.integration.rei.client.AnvilRecipeDisplay;
import lombok.Getter;
import me.shedaniel.rei.api.client.gui.Renderer;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.NotNull;

@Getter
public class AnvilCraftCategoryIdentifier {
private CategoryIdentifier<AnvilRecipeDisplay> categoryIdentifier = null;
private Component title = null;
private Renderer icon = null;

public static @NotNull AnvilCraftCategoryIdentifier creat() {
return new AnvilCraftCategoryIdentifier();
}

public AnvilCraftCategoryIdentifier setCategoryIdentifier(
CategoryIdentifier<AnvilRecipeDisplay> categoryIdentifier
) {
this.categoryIdentifier = categoryIdentifier;
return this;
}

public AnvilCraftCategoryIdentifier setTitle(Component title) {
this.title = title;
return this;
}

public AnvilCraftCategoryIdentifier setIcon(Renderer icon) {
this.icon = icon;
return this;
}
}
Loading