2017-02-23 13:29:43 +01:00
|
|
|
/*
|
|
|
|
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 TechReborn
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2015-04-11 17:21:49 +02:00
|
|
|
package techreborn.blocks;
|
|
|
|
|
2016-05-16 16:48:48 +02:00
|
|
|
import com.google.common.collect.Lists;
|
2016-12-12 03:05:03 +01:00
|
|
|
import net.minecraft.block.Block;
|
2015-04-11 17:21:49 +02:00
|
|
|
import net.minecraft.block.material.Material;
|
2016-03-13 17:08:30 +01:00
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
2015-11-23 20:51:40 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-04-11 17:21:49 +02:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2015-07-12 17:51:14 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-06-08 07:41:44 +02:00
|
|
|
import net.minecraft.init.Items;
|
2015-04-11 17:21:49 +02:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-11-19 15:41:00 +01:00
|
|
|
import net.minecraft.util.NonNullList;
|
2016-03-15 09:13:05 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-03-13 17:08:30 +01:00
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
2015-11-23 20:51:40 +01:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
2015-05-31 02:59:43 +02:00
|
|
|
import net.minecraft.world.World;
|
2015-11-23 20:19:18 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2017-06-14 01:49:52 +02:00
|
|
|
import prospector.shootingstar.ShootingStar;
|
|
|
|
import prospector.shootingstar.model.ModelCompound;
|
2016-05-16 16:48:48 +02:00
|
|
|
import reborncore.common.blocks.PropertyString;
|
2017-06-12 21:33:30 +02:00
|
|
|
import reborncore.common.registration.RebornRegistry;
|
|
|
|
import reborncore.common.registration.impl.ConfigRegistry;
|
2016-05-16 16:48:48 +02:00
|
|
|
import reborncore.common.util.ArrayUtils;
|
2015-11-08 13:15:45 +01:00
|
|
|
import reborncore.common.util.OreDrop;
|
|
|
|
import reborncore.common.util.OreDropSet;
|
2016-05-16 16:48:48 +02:00
|
|
|
import reborncore.common.util.StringUtils;
|
2015-04-18 12:47:09 +02:00
|
|
|
import techreborn.client.TechRebornCreativeTabMisc;
|
2017-06-15 12:35:08 +02:00
|
|
|
import techreborn.events.TRRecipeHandler;
|
2015-06-07 06:13:41 +02:00
|
|
|
import techreborn.init.ModBlocks;
|
2015-06-08 06:31:28 +02:00
|
|
|
import techreborn.items.ItemDusts;
|
|
|
|
import techreborn.items.ItemGems;
|
2017-06-12 21:33:30 +02:00
|
|
|
import techreborn.lib.ModInfo;
|
2016-03-11 21:24:05 +01:00
|
|
|
import techreborn.world.config.IOreNameProvider;
|
2015-04-15 17:23:12 +02:00
|
|
|
|
2016-04-30 06:21:28 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
|
|
|
|
2017-06-12 21:33:30 +02:00
|
|
|
@RebornRegistry(modID = ModInfo.MOD_ID)
|
2016-12-12 03:05:03 +01:00
|
|
|
public class BlockOre extends Block implements IOreNameProvider {
|
2016-07-31 20:12:55 +02:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public static final String[] ores = new String[] {
|
|
|
|
"galena", "iridium", "ruby", "sapphire", "bauxite", "pyrite",
|
|
|
|
"cinnabar", "sphalerite", "tungsten", "sheldonite", "peridot", "sodalite",
|
|
|
|
"lead", "silver" };
|
|
|
|
private static final List<String> oreNamesList = Lists.newArrayList(ArrayUtils.arrayToLowercase(ores));
|
|
|
|
public static final PropertyString VARIANTS = new PropertyString("type", oreNamesList);
|
2017-06-14 01:49:52 +02:00
|
|
|
@ConfigRegistry(category = "blocks", key = "secondaryDropChance", comment = "Secondary Gem drop chance")
|
|
|
|
public static double secondaryDropChance = 0.5;
|
2016-10-08 21:46:16 +02:00
|
|
|
|
2017-06-14 01:49:52 +02:00
|
|
|
public BlockOre() {
|
|
|
|
super(Material.ROCK);
|
2016-10-08 21:46:16 +02:00
|
|
|
setCreativeTab(TechRebornCreativeTabMisc.instance);
|
|
|
|
setHardness(2.0f);
|
|
|
|
setHarvestLevel("pickaxe", 2);
|
|
|
|
this.setDefaultState(this.getStateFromMeta(0));
|
2017-06-14 01:49:52 +02:00
|
|
|
for (int i = 0; i < ores.length; i++) {
|
2017-06-14 17:56:09 +02:00
|
|
|
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, i).setInvVariant("type=" + ores[i]).setFileName("ores"));
|
2017-06-14 01:49:52 +02:00
|
|
|
}
|
2017-06-15 12:35:08 +02:00
|
|
|
TRRecipeHandler.hideEntry(this);
|
2016-10-08 21:46:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static ItemStack getOreByName(String name, int count) {
|
|
|
|
for (int i = 0; i < ores.length; i++) {
|
|
|
|
if (ores[i].equalsIgnoreCase(name)) {
|
2017-01-01 08:29:32 +01:00
|
|
|
return new ItemStack(ModBlocks.ORE, count, i);
|
2016-10-08 21:46:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return BlockOre2.getOreByName(name, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ItemStack getOreByName(String name) {
|
|
|
|
return getOreByName(name, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public IBlockState getBlockStateFromName(String name) {
|
|
|
|
int index = -1;
|
|
|
|
for (int i = 0; i < ores.length; i++) {
|
|
|
|
if (ores[i].equalsIgnoreCase(name)) {
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (index == -1) {
|
2017-01-01 08:29:32 +01:00
|
|
|
return ModBlocks.ORE2.getBlockStateFromName(name);
|
2016-10-08 21:46:16 +02:00
|
|
|
}
|
|
|
|
return getStateFromMeta(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
public ArrayList<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
|
|
|
|
String variant = state.getValue(VARIANTS);
|
|
|
|
int meta = getMetaFromState(state);
|
|
|
|
Random random = new Random();
|
|
|
|
// Ruby
|
|
|
|
if (variant.equalsIgnoreCase("Ruby")) {
|
|
|
|
OreDrop ruby = new OreDrop(ItemGems.getGemByName("ruby"),
|
2017-06-12 21:33:30 +02:00
|
|
|
secondaryDropChance);
|
2016-12-20 15:00:58 +01:00
|
|
|
OreDrop redGarnet = new OreDrop(ItemGems.getGemByName("red_garnet"), 0.02);
|
2017-10-01 02:15:58 +02:00
|
|
|
OreDropSet set = new OreDropSet(ruby, redGarnet);
|
2016-10-08 21:46:16 +02:00
|
|
|
return set.drop(fortune, random);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sapphire
|
|
|
|
if (variant.equalsIgnoreCase("Sapphire")) {
|
|
|
|
OreDrop sapphire = new OreDrop(ItemGems.getGemByName("sapphire"),
|
2017-06-12 21:33:30 +02:00
|
|
|
secondaryDropChance);
|
2016-10-08 21:46:16 +02:00
|
|
|
OreDrop peridot = new OreDrop(ItemGems.getGemByName("peridot"), 0.03);
|
|
|
|
OreDropSet set = new OreDropSet(sapphire, peridot);
|
|
|
|
return set.drop(fortune, random);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pyrite
|
|
|
|
if (variant.equalsIgnoreCase("Pyrite")) {
|
|
|
|
OreDrop pyriteDust = new OreDrop(ItemDusts.getDustByName("pyrite"),
|
2017-06-12 21:33:30 +02:00
|
|
|
secondaryDropChance);
|
2016-10-08 21:46:16 +02:00
|
|
|
OreDropSet set = new OreDropSet(pyriteDust);
|
|
|
|
return set.drop(fortune, random);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sodalite
|
|
|
|
if (variant.equalsIgnoreCase("Sodalite")) {
|
|
|
|
OreDrop sodalite = new OreDrop(ItemDusts.getDustByName("sodalite", 6),
|
2017-06-12 21:33:30 +02:00
|
|
|
secondaryDropChance);
|
2016-10-08 21:46:16 +02:00
|
|
|
OreDrop aluminum = new OreDrop(ItemDusts.getDustByName("aluminum"), 0.50);
|
|
|
|
OreDropSet set = new OreDropSet(sodalite, aluminum);
|
|
|
|
return set.drop(fortune, random);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cinnabar
|
|
|
|
if (variant.equalsIgnoreCase("Cinnabar")) {
|
|
|
|
OreDrop cinnabar = new OreDrop(ItemDusts.getDustByName("cinnabar"),
|
2017-06-12 21:33:30 +02:00
|
|
|
secondaryDropChance);
|
2016-10-08 21:46:16 +02:00
|
|
|
OreDrop redstone = new OreDrop(new ItemStack(Items.REDSTONE), 0.25);
|
|
|
|
OreDropSet set = new OreDropSet(cinnabar, redstone);
|
|
|
|
return set.drop(fortune, random);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sphalerite 1, 1/8 yellow garnet
|
|
|
|
if (variant.equalsIgnoreCase("Sphalerite")) {
|
|
|
|
OreDrop sphalerite = new OreDrop(ItemDusts.getDustByName("sphalerite"),
|
2017-06-12 21:33:30 +02:00
|
|
|
secondaryDropChance);
|
2016-10-08 21:46:16 +02:00
|
|
|
OreDrop yellowGarnet = new OreDrop(ItemGems.getGemByName("yellowGarnet"), 0.125);
|
|
|
|
OreDropSet set = new OreDropSet(sphalerite, yellowGarnet);
|
|
|
|
return set.drop(fortune, random);
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayList<ItemStack> block = new ArrayList<>();
|
|
|
|
block.add(new ItemStack(Item.getItemFromBlock(this), 1, meta));
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean canSilkHarvest() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2017-06-11 22:22:07 +02:00
|
|
|
public void getSubBlocks(CreativeTabs creativeTabs, NonNullList<ItemStack> list) {
|
2016-10-08 21:46:16 +02:00
|
|
|
for (int meta = 0; meta < ores.length; meta++) {
|
2017-06-11 22:22:07 +02:00
|
|
|
list.add(new ItemStack(this, 1, meta));
|
2016-10-08 21:46:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos,
|
|
|
|
EntityPlayer player) {
|
|
|
|
return new ItemStack(this, 1, getMetaFromState(state));
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
// public int damageDropped(IBlockState state)
|
|
|
|
// {
|
|
|
|
// int meta = getMetaFromState(state);
|
|
|
|
// if (meta == 2)
|
|
|
|
// {
|
|
|
|
// return 0;
|
|
|
|
// } else if (meta == 3)
|
|
|
|
// {
|
|
|
|
// return 1;
|
|
|
|
// } else if (meta == 5)
|
|
|
|
// {
|
|
|
|
// return 60;
|
|
|
|
// }
|
|
|
|
// return meta;
|
|
|
|
// }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int damageDropped(IBlockState state) {
|
|
|
|
return getMetaFromState(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IBlockState getStateFromMeta(int meta) {
|
|
|
|
if (meta > ores.length) {
|
|
|
|
meta = 0;
|
|
|
|
}
|
|
|
|
return getBlockState().getBaseState().withProperty(VARIANTS, oreNamesList.get(meta));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMetaFromState(IBlockState state) {
|
|
|
|
return oreNamesList.indexOf(state.getValue(VARIANTS));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected BlockStateContainer createBlockState() {
|
|
|
|
return new BlockStateContainer(this, VARIANTS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUserLoclisedName(IBlockState state) {
|
|
|
|
return StringUtils.toFirstCapital(oreNamesList.get(getMetaFromState(state)));
|
|
|
|
}
|
2016-07-31 20:12:55 +02:00
|
|
|
|
2015-04-11 17:21:49 +02:00
|
|
|
}
|