ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensMining.java

192 lines
9.5 KiB
Java
Raw Normal View History

2016-10-31 16:36:22 +01:00
/*
* This file ("LensMining.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
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2016-10-31 16:36:22 +01:00
*/
package de.ellpeck.actuallyadditions.mod.items.lens;
2019-05-02 09:10:29 +02:00
import java.util.List;
2016-10-31 19:20:29 +01:00
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
2016-10-31 16:36:22 +01:00
import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor;
import de.ellpeck.actuallyadditions.api.lens.Lens;
2016-10-31 19:20:29 +01:00
import de.ellpeck.actuallyadditions.api.recipe.WeightedOre;
2018-05-10 11:38:58 +02:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
2019-07-26 01:11:49 +02:00
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
2019-07-09 04:51:10 +02:00
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
import de.ellpeck.actuallyadditions.mod.recipe.CrusherRecipeRegistry;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
2016-10-31 16:36:22 +01:00
import net.minecraft.block.Block;
import net.minecraft.block.BlockNetherrack;
import net.minecraft.block.BlockStone;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
2016-10-31 16:36:22 +01:00
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
2016-10-31 16:36:22 +01:00
import net.minecraft.util.WeightedRandom;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.FakePlayerFactory;
2016-10-31 16:36:22 +01:00
import net.minecraftforge.oredict.OreDictionary;
2019-05-02 09:10:29 +02:00
public class LensMining extends Lens {
2016-10-31 16:36:22 +01:00
2019-05-02 09:10:29 +02:00
public static void init() {
2016-10-31 19:20:29 +01:00
ActuallyAdditionsAPI.addMiningLensStoneOre("oreCoal", 5000);
ActuallyAdditionsAPI.addMiningLensNetherOre("oreNetherCoal", 5000);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreIron", 3000);
ActuallyAdditionsAPI.addMiningLensNetherOre("oreNetherIron", 3000);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreGold", 500);
ActuallyAdditionsAPI.addMiningLensNetherOre("oreNetherGold", 500);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreDiamond", 50);
ActuallyAdditionsAPI.addMiningLensNetherOre("oreNetherDiamond", 50);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreLapis", 250);
ActuallyAdditionsAPI.addMiningLensNetherOre("oreNetherLapis", 250);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreRedstone", 200);
ActuallyAdditionsAPI.addMiningLensNetherOre("oreNetherRedstone", 200);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreEmerald", 30);
2016-11-01 22:03:27 +01:00
ActuallyAdditionsAPI.addMiningLensNetherOre("oreQuartz", 3000);
2016-10-31 19:20:29 +01:00
ActuallyAdditionsAPI.addMiningLensStoneOre("oreCopper", 2000);
ActuallyAdditionsAPI.addMiningLensNetherOre("oreNetherCopper", 2000);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreTin", 1800);
ActuallyAdditionsAPI.addMiningLensNetherOre("oreNetherTin", 1800);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreLead", 1500);
ActuallyAdditionsAPI.addMiningLensNetherOre("oreNetherLead", 1500);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreSilver", 1000);
ActuallyAdditionsAPI.addMiningLensNetherOre("oreNetherSilver", 1000);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreNickel", 100);
ActuallyAdditionsAPI.addMiningLensNetherOre("oreNetherNickel", 100);
ActuallyAdditionsAPI.addMiningLensStoneOre("orePlatinum", 20);
ActuallyAdditionsAPI.addMiningLensNetherOre("oreNetherPlatinum", 20);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreAluminum", 1200);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreAluminium", 1200);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreOsmium", 1500);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreZinc", 1000);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreYellorite", 1200);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreUranium", 400);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreCertusQuartz", 800);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreApatite", 700);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreQuartzBlack", 3000);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreRuby", 40);
ActuallyAdditionsAPI.addMiningLensStoneOre("orePeridot", 40);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreTopaz", 40);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreTanzanite", 40);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreMalachite", 40);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreSapphire", 40);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreAmber", 150);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreResonating", 50);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreSulfur", 3000);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreSaltpeter", 250);
ActuallyAdditionsAPI.addMiningLensNetherOre("oreFirestone", 30);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreSalt", 2900);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreDraconium", 5);
ActuallyAdditionsAPI.addMiningLensStoneOre("orePoorIron", 3000);
ActuallyAdditionsAPI.addMiningLensStoneOre("orePoorGold", 500);
ActuallyAdditionsAPI.addMiningLensStoneOre("orePoorCopper", 2000);
ActuallyAdditionsAPI.addMiningLensStoneOre("orePoorTin", 1800);
ActuallyAdditionsAPI.addMiningLensStoneOre("orePoorLead", 1500);
ActuallyAdditionsAPI.addMiningLensStoneOre("orePoorSilver", 1000);
2016-10-31 19:20:29 +01:00
ActuallyAdditionsAPI.addMiningLensNetherOre("oreCobalt", 50);
ActuallyAdditionsAPI.addMiningLensNetherOre("oreArdite", 50);
2019-05-02 09:10:29 +02:00
for (String conf : ConfigStringListValues.MINING_LENS_EXTRA_WHITELIST.getValue()) {
if (conf.contains("@")) {
try {
String[] split = conf.split("@");
String ore = split[0];
int weight = Integer.parseInt(split[1]);
String dim = split[2];
2019-05-02 09:10:29 +02:00
if ("n".equals(dim)) {
ActuallyAdditionsAPI.addMiningLensNetherOre(ore, weight);
2019-05-02 09:10:29 +02:00
} else if ("s".equals(dim)) {
ActuallyAdditionsAPI.addMiningLensStoneOre(ore, weight);
}
2019-05-02 09:10:29 +02:00
} catch (Exception e) {
ActuallyAdditions.LOGGER.warn("A config option appears to be incorrect: The entry " + conf + " can't be parsed!");
}
}
}
2016-10-31 19:05:29 +01:00
}
2016-10-31 16:36:22 +01:00
@Override
2019-05-02 09:10:29 +02:00
public boolean invoke(IBlockState hitState, BlockPos hitPos, IAtomicReconstructor tile) {
if (!tile.getWorldObject().isAirBlock(hitPos)) {
2019-07-09 04:51:10 +02:00
if (tile.getEnergy() >= ConfigIntValues.MINING_LENS_USE.getValue()) {
int adaptedUse = ConfigIntValues.MINING_LENS_USE.getValue();
2016-10-31 16:36:22 +01:00
List<WeightedOre> ores = null;
Block hitBlock = hitState.getBlock();
2019-05-02 09:10:29 +02:00
if (hitBlock instanceof BlockStone) {
2016-10-31 19:20:29 +01:00
ores = ActuallyAdditionsAPI.STONE_ORES;
2019-05-02 09:10:29 +02:00
} else if (hitBlock instanceof BlockNetherrack) {
2016-10-31 19:20:29 +01:00
ores = ActuallyAdditionsAPI.NETHERRACK_ORES;
2016-10-31 16:36:22 +01:00
adaptedUse += 10000;
}
2019-05-02 09:10:29 +02:00
if (ores != null) {
2016-10-31 16:36:22 +01:00
int totalWeight = WeightedRandom.getTotalWeight(ores);
ItemStack stack = null;
boolean found = false;
2019-05-02 09:10:29 +02:00
while (!found) {
2016-10-31 16:36:22 +01:00
WeightedOre ore = WeightedRandom.getRandomItem(tile.getWorldObject().rand, ores, totalWeight);
2019-05-02 09:10:29 +02:00
if (ore != null) {
2016-10-31 16:36:22 +01:00
List<ItemStack> stacks = OreDictionary.getOres(ore.name, false);
2019-05-02 09:10:29 +02:00
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) {
2019-07-26 01:11:49 +02:00
if (ConfigBoolValues.MINING_LENS_ADAPTED_USE.isEnabled()) adaptedUse += (totalWeight - ore.itemWeight) % 40000;
2016-10-31 16:36:22 +01:00
stack = aStack;
found = true;
break;
}
}
}
}
}
2019-05-02 09:10:29 +02:00
if (tile.getEnergy() >= adaptedUse) {
2016-10-31 16:36:22 +01:00
Block block = Block.getBlockFromItem(stack.getItem());
2019-05-02 09:10:29 +02:00
if (block != Blocks.AIR) {
2019-02-27 19:53:05 +01:00
IBlockState state = block.getStateForPlacement(tile.getWorldObject(), hitPos, EnumFacing.UP, 0, 0, 0, stack.getMetadata(), FakePlayerFactory.getMinecraft((WorldServer) tile.getWorldObject()), EnumHand.MAIN_HAND);
2016-10-31 16:36:22 +01:00
tile.getWorldObject().setBlockState(hitPos, state, 2);
tile.getWorldObject().playEvent(2001, hitPos, Block.getStateId(state));
2016-10-31 16:36:22 +01:00
tile.extractEnergy(adaptedUse);
}
}
}
}
return true;
2019-05-02 09:10:29 +02:00
} else {
2016-10-31 16:36:22 +01:00
return false;
}
}
@Override
2019-05-02 09:10:29 +02:00
public float[] getColor() {
return new float[] { 76F / 255F, 76F / 255F, 76F / 255F };
2016-10-31 16:36:22 +01:00
}
@Override
2019-05-02 09:10:29 +02:00
public int getDistance() {
2016-10-31 16:36:22 +01:00
return 10;
}
}