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;
|
|
|
|
|
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;
|
2016-11-23 17:46:08 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.recipe.CrusherRecipeRegistry;
|
2016-11-16 20:31:16 +01:00
|
|
|
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;
|
2017-08-17 07:06:09 +02:00
|
|
|
import net.minecraft.init.Blocks;
|
2016-10-31 16:36:22 +01:00
|
|
|
import net.minecraft.item.ItemBlock;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2017-08-17 07:06:09 +02:00
|
|
|
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;
|
2017-08-17 07:06:09 +02:00
|
|
|
import net.minecraft.world.WorldServer;
|
|
|
|
import net.minecraftforge.common.util.FakePlayerFactory;
|
2016-10-31 16:36:22 +01:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class LensMining extends Lens{
|
|
|
|
|
2016-10-31 16:56:04 +01:00
|
|
|
public static final int ENERGY_USE = 60000;
|
2016-10-31 16:36:22 +01:00
|
|
|
|
2016-11-23 17:46:08 +01: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);
|
2016-11-01 18:40:26 +01:00
|
|
|
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);
|
2016-11-20 00:09:37 +01:00
|
|
|
ActuallyAdditionsAPI.addMiningLensStoneOre("oreDraconium", 5);
|
2016-11-01 18:40:26 +01:00
|
|
|
|
|
|
|
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);
|
2016-11-23 17:46:08 +01: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];
|
|
|
|
|
|
|
|
if("n".equals(dim)){
|
|
|
|
ActuallyAdditionsAPI.addMiningLensNetherOre(ore, weight);
|
|
|
|
}
|
|
|
|
else if("s".equals(dim)){
|
|
|
|
ActuallyAdditionsAPI.addMiningLensStoneOre(ore, weight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception e){
|
2018-05-10 11:38:58 +02:00
|
|
|
ActuallyAdditions.LOGGER.warn("A config option appears to be incorrect: The entry "+conf+" can't be parsed!");
|
2016-11-23 17:46:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-31 19:05:29 +01:00
|
|
|
}
|
|
|
|
|
2016-10-31 16:36:22 +01:00
|
|
|
@Override
|
|
|
|
public boolean invoke(IBlockState hitState, BlockPos hitPos, IAtomicReconstructor tile){
|
|
|
|
if(!tile.getWorldObject().isAirBlock(hitPos)){
|
|
|
|
if(tile.getEnergy() >= ENERGY_USE){
|
|
|
|
int adaptedUse = ENERGY_USE;
|
|
|
|
|
|
|
|
List<WeightedOre> ores = null;
|
|
|
|
Block hitBlock = hitState.getBlock();
|
|
|
|
if(hitBlock instanceof BlockStone){
|
2016-10-31 19:20:29 +01:00
|
|
|
ores = ActuallyAdditionsAPI.STONE_ORES;
|
2016-10-31 16:36:22 +01: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ores != null){
|
|
|
|
int totalWeight = WeightedRandom.getTotalWeight(ores);
|
|
|
|
ItemStack stack = null;
|
|
|
|
|
|
|
|
boolean found = false;
|
|
|
|
while(!found){
|
|
|
|
WeightedOre ore = WeightedRandom.getRandomItem(tile.getWorldObject().rand, ores, totalWeight);
|
|
|
|
if(ore != null){
|
|
|
|
List<ItemStack> stacks = OreDictionary.getOres(ore.name, false);
|
|
|
|
if(stacks != null && !stacks.isEmpty()){
|
|
|
|
for(ItemStack aStack : stacks){
|
2016-11-23 17:46:08 +01:00
|
|
|
if(StackUtil.isValid(aStack) && !CrusherRecipeRegistry.hasBlacklistedOutput(aStack, ConfigStringListValues.MINING_LENS_BLACKLIST.getValue()) && aStack.getItem() instanceof ItemBlock){
|
2016-10-31 16:56:04 +01:00
|
|
|
adaptedUse += (totalWeight-ore.itemWeight)%40000;
|
2016-10-31 16:36:22 +01:00
|
|
|
|
|
|
|
stack = aStack;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tile.getEnergy() >= adaptedUse){
|
|
|
|
Block block = Block.getBlockFromItem(stack.getItem());
|
2017-08-17 07:06:09 +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);
|
|
|
|
|
2016-11-07 19:58:34 +01:00
|
|
|
tile.getWorldObject().playEvent(2001, hitPos, Block.getStateId(state));
|
2016-10-31 16:36:22 +01:00
|
|
|
|
|
|
|
tile.extractEnergy(adaptedUse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float[] getColor(){
|
|
|
|
return new float[]{76F/255F, 76F/255F, 76F/255F};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getDistance(){
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
}
|