From c6f226c2da5ddf07199fe57a5055ac04c5424dc7 Mon Sep 17 00:00:00 2001 From: Flanks255 <32142731+Flanks255@users.noreply.github.com> Date: Wed, 31 Aug 2022 12:07:18 -0500 Subject: [PATCH] mining lens part 2. --- .../api/ActuallyAdditionsAPI.java | 3 + .../data/MiningLensGenerator.java | 5 -- .../mod/crafting/MiningLensRecipe.java | 6 +- .../mod/items/lens/LensMining.java | 65 +++++++++---------- .../mod/items/lens/Lenses.java | 27 -------- .../mod/util/ResourceReloader.java | 3 + 6 files changed, 38 insertions(+), 71 deletions(-) delete mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/Lenses.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java index 2e0fba2c8..44d4e5608 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java @@ -47,6 +47,7 @@ public final class ActuallyAdditionsAPI { public static final List PRESSING_RECIPES = new ArrayList<>(); public static final List FERMENTING_RECIPES = new ArrayList<>(); public static final List CONVERSION_LASER_RECIPES = new ArrayList<>(); + public static final List MINING_LENS_RECIPES = new ArrayList<>(); /** * Farmer behaviors are sorted when first accessed, this will not be done until after loading, but do not add behaviors at runtime. @@ -59,7 +60,9 @@ public final class ActuallyAdditionsAPI { public static final List ALL_CHAPTERS = new ArrayList<>(); //This is added to automatically, you don't need to add anything to this list public static final List BOOKLET_PAGES_WITH_ITEM_OR_FLUID_DATA = new ArrayList<>(); + @Deprecated public static final List STONE_ORES = new ArrayList<>(); + @Deprecated public static final List NETHERRACK_ORES = new ArrayList<>(); /** diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/MiningLensGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/MiningLensGenerator.java index c5e1917db..42c6e1cac 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/MiningLensGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/MiningLensGenerator.java @@ -2,11 +2,7 @@ package de.ellpeck.actuallyadditions.data; import com.google.gson.JsonObject; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; -import de.ellpeck.actuallyadditions.mod.crafting.FermentingRecipe; import de.ellpeck.actuallyadditions.mod.crafting.MiningLensRecipe; -import de.ellpeck.actuallyadditions.mod.crafting.PressingRecipe; -import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; -import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; import net.minecraft.data.DataGenerator; import net.minecraft.data.DirectoryCache; import net.minecraft.data.IFinishedRecipe; @@ -17,7 +13,6 @@ import net.minecraft.tags.ITag; import net.minecraft.util.IItemProvider; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.Tags; -import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.registries.ForgeRegistries; import java.nio.file.Path; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/MiningLensRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/MiningLensRecipe.java index 24aaf0367..2fd69bb15 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/MiningLensRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/MiningLensRecipe.java @@ -24,13 +24,13 @@ public class MiningLensRecipe extends WeightedRandom.Item implements IRecipe= energyUse) { int adaptedUse = energyUse; - List ores = null; + List ores = new ArrayList<>(); + Block hitBlock = hitState.getBlock(); - if (hitBlock.is(Tags.Blocks.STONE)) { //TODO maybe? + ItemStack item = new ItemStack(hitBlock.asItem()); + + for(MiningLensRecipe r:ActuallyAdditionsAPI.MINING_LENS_RECIPES) { + if (r.matches(item)) + ores.add(r); + } + + +/* if (hitBlock.is(Tags.Blocks.STONE)) { //TODO maybe? ores = ActuallyAdditionsAPI.STONE_ORES; } else if (hitBlock instanceof NetherrackBlock) { ores = ActuallyAdditionsAPI.NETHERRACK_ORES; - adaptedUse += 10000; - } + adaptedUse += 10000; //TODO uh oh!? + }*/ - if (ores != null) { + if (!ores.isEmpty()) { int totalWeight = WeightedRandom.getTotalWeight(ores); - ItemStack stack = null; + MiningLensRecipe ore = WeightedRandom.getRandomItem(tile.getWorldObject().random, ores); - boolean found = false; - while (!found) { - WeightedOre ore = WeightedRandom.getRandomItem(tile.getWorldObject().random, ores, totalWeight); -/* if (ore != null) { - List stacks = OreDictionary.getOres(ore.name, false); - if (stacks != null && !stacks.isEmpty()) { - for (ItemStack aStack : stacks) { - if (StackUtil.isValid(aStack) && !CrusherRecipeRegistry.hasBlacklistedOutput(aStack, ConfigStringListValues.MINING_LENS_BLACKLIST.getValue()) && aStack.getItem() instanceof ItemBlock) { - if (ConfigBoolValues.MINING_LENS_ADAPTED_USE.isEnabled()) { - adaptedUse += (totalWeight - ore.weight) % 40000; - } + ItemStack stack = ore.getResultItem().copy(); - stack = aStack; - found = true; - break; - } - } - } - }*/ - } - - if (tile.getEnergy() >= adaptedUse) { - Block block = Block.byItem(stack.getItem()); -/* if (block != Blocks.AIR) { - BlockState state = block.getStateForPlacement(tile.getWorldObject(), hitPos, Direction.UP, 0, 0, 0, stack.getMetadata(), FakePlayerFactory.getMinecraft((WorldServer) tile.getWorldObject()), Hand.MAIN_HAND); - tile.getWorldObject().setBlock(hitPos, state, 2); - - tile.getWorldObject().levelEvent(2001, hitPos, Block.getId(state)); - - tile.extractEnergy(adaptedUse); - }*/ + if (stack.getItem() instanceof BlockItem) { + Block toPlace = Block.byItem(stack.getItem()); + BlockState state2Place = toPlace.defaultBlockState(); + tile.getWorldObject().setBlock(hitPos, state2Place, 2); + tile.getWorldObject().levelEvent(2001, hitPos, Block.getId(state2Place)); + tile.extractEnergy(adaptedUse); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/Lenses.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/Lenses.java deleted file mode 100644 index 6f8079ce8..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/Lenses.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This file ("Lenses.java") is part of the Actually Additions mod for Minecraft. - * It is created and owned by Ellpeck and distributed - * under the Actually Additions License to be found at - * http://ellpeck.de/actaddlicense - * View the source code at https://github.com/Ellpeck/ActuallyAdditions - * - * © 2015-2017 Ellpeck - */ - -package de.ellpeck.actuallyadditions.mod.items.lens; - -import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; -import de.ellpeck.actuallyadditions.api.lens.LensConversion; - -public final class Lenses { - - public static void init() { -// ActuallyAdditionsAPI.lensDefaultConversion = new LensConversion(); -// ActuallyAdditionsAPI.lensDetonation = new LensDetonation(); -// ActuallyAdditionsAPI.lensDeath = new LensDeath(); -// ActuallyAdditionsAPI.lensEvenMoarDeath = new LensKiller(); -// ActuallyAdditionsAPI.lensColor = new LensColor(); -// ActuallyAdditionsAPI.lensDisenchanting = new LensDisenchanting(); -// ActuallyAdditionsAPI.lensMining = new LensMining(); - } -} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/ResourceReloader.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/ResourceReloader.java index 858a02090..e96de6cb7 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/ResourceReloader.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/ResourceReloader.java @@ -41,5 +41,8 @@ public class ResourceReloader implements IResourceManagerReloadListener { ActuallyAdditionsAPI.COLOR_CHANGE_RECIPES.clear(); ActuallyAdditionsAPI.COLOR_CHANGE_RECIPES.addAll(recipeManager.getAllRecipesFor(ActuallyRecipes.Types.COLOR_CHANGE)); + + ActuallyAdditionsAPI.MINING_LENS_RECIPES.clear(); + ActuallyAdditionsAPI.MINING_LENS_RECIPES.addAll(recipeManager.getAllRecipesFor(ActuallyRecipes.Types.MINING_LENS)); } }