Make head recipe stateless, and use inventory-sensitive output method for all rune altar/apothecary recipes

This commit is contained in:
Vincent Lee committed 2020-04-05 11:59:33 -05:00
1 parent dc8b74f657
commit f9e960a907
7 files changed
+43 -40

No files matched your search

@@ -77,10 +77,16 @@ public class RecipePetals implements IRecipe<RecipeWrapper> {
@Nonnull
@Override
public ItemStack getRecipeOutput() {
public final ItemStack getRecipeOutput() {
return output;
}
@Nonnull
@Override
public ItemStack getCraftingResult(@Nonnull RecipeWrapper inv) {
return getRecipeOutput().copy();
}
@Nonnull
@Override
public NonNullList<Ingredient> getIngredients() {
@@ -111,13 +117,6 @@ public class RecipePetals implements IRecipe<RecipeWrapper> {
return ModRecipeTypes.PETAL_TYPE;
}
// Ignored IRecipe methods
@Nonnull
@Override
public ItemStack getCraftingResult(@Nonnull RecipeWrapper inv) {
return getRecipeOutput();
}
@Override
public boolean canFit(int width, int height) {
return false;
@@ -84,10 +84,16 @@ public class RecipeRuneAltar implements IRecipe<RecipeWrapper> {
@Nonnull
@Override
public ItemStack getRecipeOutput() {
public final ItemStack getRecipeOutput() {
return output;
}
@Nonnull
@Override
public ItemStack getCraftingResult(@Nonnull RecipeWrapper inv) {
return getRecipeOutput().copy();
}
@Nonnull
@Override
public NonNullList<Ingredient> getIngredients() {
@@ -122,13 +128,6 @@ public class RecipeRuneAltar implements IRecipe<RecipeWrapper> {
return mana;
}
// Ignored IRecipe methods
@Nonnull
@Override
public ItemStack getCraftingResult(@Nonnull RecipeWrapper inv) {
return getRecipeOutput();
}
@Override
public boolean canFit(int width, int height) {
return false;
@@ -147,7 +147,8 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
}
if (SEED_PATTERN.matcher(stack.getTranslationKey()).find()) {
Optional<RecipePetals> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.PETAL_TYPE, new RecipeWrapper(itemHandler), world);
RecipeWrapper inv = getRecipeWrapper();
Optional<RecipePetals> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.PETAL_TYPE, inv, world);
maybeRecipe.ifPresent(recipe -> {
saveLastRecipe();
@@ -157,7 +158,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
stack.shrink(1);
ItemStack output = recipe.getRecipeOutput().copy();
ItemStack output = recipe.getCraftingResult(inv);
ItemEntity outputItem = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, output);
outputItem.addTag(ITEM_TAG_APOTHECARY_SPAWNED);
world.addEntity(outputItem);
@@ -387,14 +388,15 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
if (amt > 0) {
float anglePer = 360F / amt;
RecipeWrapper inv = getRecipeWrapper();
Optional<RecipePetals> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.PETAL_TYPE, new RecipeWrapper(itemHandler), world);
Optional<RecipePetals> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.PETAL_TYPE, inv, world);
maybeRecipe.ifPresent(recipe -> {
RenderSystem.color4f(1F, 1F, 1F, 1F);
mc.textureManager.bindTexture(HUDHandler.manaBar);
RenderHelper.drawTexturedModalRect(xc + radius + 9, yc - 8, 0, 8, 22, 15);
ItemStack stack = recipe.getRecipeOutput();
ItemStack stack = recipe.getCraftingResult(inv);
mc.getItemRenderer().renderItemIntoGUI(stack, xc + radius + 32, yc - 8);
mc.getItemRenderer().renderItemIntoGUI(new ItemStack(Items.WHEAT_SEEDS), xc + radius + 16, yc + 6);
@@ -92,7 +92,7 @@ public class TileBrewery extends TileSimpleInventory implements IManaReceiver, I
}
private void findRecipe() {
Optional<RecipeBrew> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.BREW_TYPE, new RecipeWrapper(itemHandler), world);
Optional<RecipeBrew> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.BREW_TYPE, getRecipeWrapper(), world);
maybeRecipe.ifPresent(recipeBrew -> {
this.recipe = recipeBrew;
world.setBlockState(pos, ModBlocks.brewery.getDefaultState().with(BlockStateProperties.POWERED, true));
@@ -123,7 +123,7 @@ public class TileBrewery extends TileSimpleInventory implements IManaReceiver, I
}
if (recipe != null) {
if (!recipe.matches(new RecipeWrapper(itemHandler), world)) {
if (!recipe.matches(getRecipeWrapper(), world)) {
recipe = null;
world.setBlockState(pos, ModBlocks.brewery.getDefaultState());
}
@@ -208,7 +208,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
if (currentRecipe != null) {
this.manaToGet = currentRecipe.getManaUsage();
} else {
Optional<RecipeRuneAltar> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, new RecipeWrapper(itemHandler), world);
Optional<RecipeRuneAltar> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, getRecipeWrapper(), world);
if (maybeRecipe.isPresent()) {
this.manaToGet = maybeRecipe.get().getManaUsage();
break getMana;
@@ -243,10 +243,6 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
}
}
public boolean hasValidRecipe() {
return world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, new RecipeWrapper(itemHandler), world).isPresent();
}
public void onWanded(PlayerEntity player, ItemStack wand) {
if (world.isRemote) {
return;
@@ -257,7 +253,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
if (currentRecipe != null) {
recipe = currentRecipe;
} else {
Optional<RecipeRuneAltar> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, new RecipeWrapper(itemHandler), world);
Optional<RecipeRuneAltar> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, getRecipeWrapper(), world);
if (maybeRecipe.isPresent()) {
recipe = maybeRecipe.get();
}
@@ -276,7 +272,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
if (livingrock != null) {
int mana = recipe.getManaUsage();
receiveMana(-mana);
ItemStack output = recipe.getRecipeOutput().copy();
ItemStack output = recipe.getCraftingResult(getRecipeWrapper());
ItemEntity outputItem = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, output);
world.addEntity(outputItem);
currentRecipe = null;
@@ -384,7 +380,8 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
if (amt > 0) {
float anglePer = 360F / amt;
world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, new RecipeWrapper(itemHandler), world).ifPresent(recipe -> {
RecipeWrapper inv = getRecipeWrapper();
world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, inv, world).ifPresent(recipe -> {
RenderSystem.enableBlend();
RenderSystem.enableRescaleNormal();
RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
@@ -402,7 +399,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
RenderSystem.translatef(0F, 0F, -100F);
}
RenderHelper.renderProgressPie(xc + radius + 32, yc - 8, progress, recipe.getRecipeOutput());
RenderHelper.renderProgressPie(xc + radius + 32, yc - 8, progress, recipe.getCraftingResult(inv));
if (progress == 1F) {
mc.fontRenderer.drawStringWithShadow("+", xc + radius + 14, yc + 12, 0xFFFFFF);
@@ -18,6 +18,7 @@ import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemStackHandler;
import net.minecraftforge.items.wrapper.RecipeWrapper;
import javax.annotation.Nonnull;
@@ -47,10 +48,14 @@ public abstract class TileSimpleInventory extends TileMod {
return new SimpleItemStackHandler(this, true);
}
public IItemHandlerModifiable getItemHandler() {
public final IItemHandlerModifiable getItemHandler() {
return itemHandler;
}
public final RecipeWrapper getRecipeWrapper() {
return new RecipeWrapper(getItemHandler());
}
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, Direction side) {
@@ -38,8 +38,6 @@ import java.util.List;
public class HeadRecipe extends RecipeRuneAltar {
private String name = "";
public HeadRecipe(ResourceLocation id, ItemStack output, int mana, Ingredient... inputs) {
super(id, output, mana, inputs);
}
@@ -57,8 +55,7 @@ public class HeadRecipe extends RecipeRuneAltar {
if (stack.getItem() == Items.NAME_TAG) {
String defaultName = new TranslationTextComponent(Items.NAME_TAG.getTranslationKey()).getString();
name = stack.getDisplayName().getString();
if (name.equals(defaultName)) {
if (stack.getDisplayName().getString().equals(defaultName)) {
return false;
}
}
@@ -70,10 +67,14 @@ public class HeadRecipe extends RecipeRuneAltar {
@Nonnull
@Override
public ItemStack getRecipeOutput() {
ItemStack stack = new ItemStack(Items.PLAYER_HEAD);
if (!name.isEmpty()) {
ItemNBTHelper.setString(stack, "SkullOwner", name);
public ItemStack getCraftingResult(@Nonnull RecipeWrapper inv) {
ItemStack stack = getRecipeOutput().copy();
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack ingr = inv.getStackInSlot(i);
if (ingr.getItem() == Items.NAME_TAG) {
ItemNBTHelper.setString(stack, "SkullOwner", ingr.getDisplayName().getString());
break;
}
}
return stack;
}