Skip to content

Commit

Permalink
Switch to new Mantle JEI entity ingredient
Browse files Browse the repository at this point in the history
Means its all integrated in the entity ingredient now
  • Loading branch information
KnightMiner committed Apr 8, 2024
1 parent 0e94fee commit 556e155
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 269 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package slimeknights.tconstruct.library.recipe.entitymelting;

import com.google.common.collect.ImmutableList;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.ForgeSpawnEggItem;
import net.minecraftforge.fluids.FluidStack;
import slimeknights.mantle.data.loadable.common.FluidStackLoadable;
import slimeknights.mantle.data.loadable.field.ContextKey;
Expand All @@ -24,8 +20,6 @@
import slimeknights.tconstruct.smeltery.TinkerSmeltery;

import java.util.Collection;
import java.util.List;
import java.util.Objects;

/**
* Recipe to melt an entity into a fluid
Expand All @@ -41,16 +35,13 @@ public class EntityMeltingRecipe implements ICustomOutputRecipe<IEmptyContainer>

@Getter
private final ResourceLocation id;
@Getter
private final EntityIngredient ingredient;
@Getter
private final FluidStack output;
@Getter
private final int damage;

@SuppressWarnings("rawtypes")
private List<EntityType> entityInputs;
private List<ItemStack> itemInputs;

/**
* Checks if the recipe matches the given type
* @param type Type
Expand All @@ -69,29 +60,6 @@ public FluidStack getOutput(LivingEntity entity) {
return output.copy();
}

/**
* Gets a list of inputs for display in JEI
* @return Entity type inputs
*/
@SuppressWarnings("rawtypes")
public List<EntityType> getEntityInputs() {
if (entityInputs == null) {
entityInputs = ImmutableList.copyOf(ingredient.getTypes());
}
return entityInputs;
}

/**
* Gets a list of item inputs for recipe lookup in JEI
* @return Item inputs
*/
public List<ItemStack> getItemInputs() {
if (itemInputs == null) {
itemInputs = getEntityInputs().stream().map(type -> new ItemStack(Objects.requireNonNullElse(ForgeSpawnEggItem.fromEntityType(type), Items.AIR))).toList();
}
return itemInputs;
}

/**
* Gets a collection of inputs for filtering in JEI
* @return Collection of types
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package slimeknights.tconstruct.library.recipe.modifiers.severing;

import com.google.common.collect.ImmutableList;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.ForgeSpawnEggItem;
import slimeknights.mantle.data.loadable.field.ContextKey;
import slimeknights.mantle.data.loadable.field.LoadableField;
import slimeknights.mantle.data.loadable.record.RecordLoadable;
Expand All @@ -22,9 +19,6 @@
import slimeknights.tconstruct.library.recipe.TinkerRecipeTypes;
import slimeknights.tconstruct.tools.TinkerModifiers;

import java.util.List;
import java.util.Objects;

/**
* Recipe to convert an entity into a head or other item for the severing modifier
*/
Expand All @@ -39,13 +33,10 @@ public class SeveringRecipe implements ICustomOutputRecipe<IEmptyContainer> {

@Getter
private final ResourceLocation id;
@Getter
protected final EntityIngredient ingredient;
protected final ItemOutput output;

@SuppressWarnings("rawtypes")
private List<EntityType> entityInputs;
private List<ItemStack> itemInputs;

/**
* Checks if the recipe matches the given type
* @param type Type
Expand All @@ -72,29 +63,6 @@ public ItemStack getOutput(Entity entity) {
return getOutput().copy();
}

/**
* Gets a list of inputs for display in JEI
* @return Entity type inputs
*/
@SuppressWarnings("rawtypes")
public List<EntityType> getEntityInputs() {
if (entityInputs == null) {
entityInputs = ImmutableList.copyOf(ingredient.getTypes());
}
return entityInputs;
}

/**
* Gets a list of item inputs for recipe lookup in JEI
* @return Item inputs
*/
public List<ItemStack> getItemInputs() {
if (itemInputs == null) {
itemInputs = getEntityInputs().stream().map(type -> new ItemStack(Objects.requireNonNullElse(ForgeSpawnEggItem.fromEntityType(type), Items.AIR))).toList();
}
return itemInputs;
}

@Override
public RecipeSerializer<?> getSerializer() {
return TinkerModifiers.severingSerializer.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@
import slimeknights.tconstruct.plugin.jei.casting.CastingBasinCategory;
import slimeknights.tconstruct.plugin.jei.casting.CastingTableCategory;
import slimeknights.tconstruct.plugin.jei.entity.DefaultEntityMeltingRecipe;
import slimeknights.tconstruct.plugin.jei.entity.EntityIngredientHelper;
import slimeknights.tconstruct.plugin.jei.entity.EntityIngredientRenderer;
import slimeknights.tconstruct.plugin.jei.entity.EntityMeltingRecipeCategory;
import slimeknights.tconstruct.plugin.jei.entity.SeveringCategory;
import slimeknights.tconstruct.plugin.jei.melting.FoundryCategory;
Expand Down Expand Up @@ -151,7 +149,6 @@ public void registerIngredients(IModIngredientRegistration registration) {
if (Config.CLIENT.showModifiersInJEI.get()) {
modifiers = ModifierRecipeLookup.getRecipeModifierList();
}
registration.register(TConstructJEIConstants.ENTITY_TYPE, Collections.emptyList(), new EntityIngredientHelper(), new EntityIngredientRenderer(16));
registration.register(TConstructJEIConstants.MODIFIER_TYPE, modifiers, new ModifierIngredientHelper(), ModifierBookmarkIngredientRenderer.INSTANCE);
registration.register(TConstructJEIConstants.PATTERN_TYPE, Collections.emptyList(), new PatternIngredientHelper(), PatternIngredientRenderer.INSTANCE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
import slimeknights.tconstruct.library.recipe.partbuilder.IDisplayPartBuilderRecipe;
import slimeknights.tconstruct.library.recipe.partbuilder.Pattern;
import slimeknights.tconstruct.library.recipe.worktable.IModifierWorktableRecipe;
import slimeknights.tconstruct.plugin.jei.entity.EntityInput;

public class TConstructJEIConstants {
public static final ResourceLocation PLUGIN = TConstruct.getResource("jei_plugin");

// ingredient types
public static final IIngredientType<EntityInput> ENTITY_TYPE = () -> EntityInput.class;
public static final IIngredientTypeWithSubtypes<Modifier,ModifierEntry> MODIFIER_TYPE = new IIngredientTypeWithSubtypes<>() {
@Override
public Class<? extends ModifierEntry> getIngredientClass() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package slimeknights.tconstruct.plugin.jei.entity;

import com.google.common.collect.ImmutableList;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraftforge.common.util.Lazy;
Expand All @@ -11,21 +10,21 @@
import slimeknights.tconstruct.library.recipe.entitymelting.EntityMeltingRecipe;
import slimeknights.tconstruct.smeltery.block.entity.module.EntityMeltingModule;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
* Extension of entity melting recipe for the sake of displaying entities in the default "recipe"
*/
@SuppressWarnings("rawtypes")
public class DefaultEntityMeltingRecipe extends EntityMeltingRecipe {
/**
* Gets a list of entity types, filtered by the recipe list
* @param recipes Recipe list
* @return List of entity types
*/
private static List<EntityType> getEntityList(List<EntityMeltingRecipe> recipes) {
List<EntityType> unusedTypes = new ArrayList<>();
private static EntityIngredient getEntityList(List<EntityMeltingRecipe> recipes) {
Set<EntityType<?>> unusedTypes = new LinkedHashSet<>();
typeLoop:
for (EntityType<?> type : ForgeRegistries.ENTITY_TYPES) {
// use tag overrides for default recipe
Expand All @@ -38,17 +37,17 @@ private static List<EntityType> getEntityList(List<EntityMeltingRecipe> recipes)
}
unusedTypes.add(type);
}
return ImmutableList.copyOf(unusedTypes);
return EntityIngredient.of(unusedTypes);
}

private final Lazy<List<EntityType>> entityList;
private final Lazy<EntityIngredient> entities;
public DefaultEntityMeltingRecipe(List<EntityMeltingRecipe> recipes) {
super(TConstruct.getResource("__default"), EntityIngredient.EMPTY, EntityMeltingModule.getDefaultFluid(), 2);
entityList = Lazy.of(() -> getEntityList(recipes));
entities = Lazy.of(() -> getEntityList(recipes));
}

@Override
public List<EntityType> getEntityInputs() {
return entityList.get();
public EntityIngredient getIngredient() {
return entities.get();
}
}

This file was deleted.

This file was deleted.

0 comments on commit 556e155

Please sign in to comment.