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-05-23 00:37:10 +02:00
|
|
|
package techreborn.blocks;
|
|
|
|
|
2017-06-14 17:56:09 +02:00
|
|
|
import com.google.common.base.CaseFormat;
|
|
|
|
import com.google.common.collect.Lists;
|
2017-09-02 00:30:36 +02:00
|
|
|
|
2015-05-23 00:37:10 +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:37:39 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-05-23 00:37:10 +02:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2017-09-02 00:30:36 +02:00
|
|
|
import net.minecraft.entity.Entity;
|
2015-05-23 00:37:10 +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;
|
2017-09-02 00:30:36 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.Explosion;
|
|
|
|
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;
|
2015-11-24 23:58:18 +01:00
|
|
|
import reborncore.common.BaseBlock;
|
2017-06-14 17:56:09 +02:00
|
|
|
import reborncore.common.blocks.PropertyString;
|
|
|
|
import reborncore.common.util.ArrayUtils;
|
2015-05-23 00:37:10 +02:00
|
|
|
import techreborn.client.TechRebornCreativeTabMisc;
|
2017-06-15 12:35:08 +02:00
|
|
|
import techreborn.events.TRRecipeHandler;
|
2015-06-26 00:41:29 +02:00
|
|
|
import techreborn.init.ModBlocks;
|
2017-06-14 01:49:52 +02:00
|
|
|
import techreborn.lib.ModInfo;
|
2015-05-23 00:37:10 +02:00
|
|
|
|
2016-05-14 23:58:09 +02:00
|
|
|
import java.security.InvalidParameterException;
|
2017-06-14 17:56:09 +02:00
|
|
|
import java.util.List;
|
2016-05-14 23:58:09 +02:00
|
|
|
import java.util.Random;
|
|
|
|
|
2017-09-02 00:30:36 +02:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2017-06-14 01:49:52 +02:00
|
|
|
public class BlockStorage2 extends BaseBlock {
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2017-09-02 00:30:36 +02:00
|
|
|
public static final String[] types = new String[] { "tungstensteel", "iridium_reinforced_tungstensteel",
|
|
|
|
"iridium_reinforced_stone", "ruby", "sapphire", "peridot", "yellow_garnet", "red_garnet", "copper", "tin",
|
|
|
|
"refined_iron" };
|
2017-06-14 17:56:09 +02:00
|
|
|
public static final PropertyString TYPE = new PropertyString("type", types);
|
|
|
|
private static final List<String> typesList = Lists.newArrayList(ArrayUtils.arrayToLowercase(types));
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2017-06-14 01:49:52 +02:00
|
|
|
public BlockStorage2() {
|
|
|
|
super(Material.IRON);
|
2016-03-25 10:47:34 +01:00
|
|
|
setCreativeTab(TechRebornCreativeTabMisc.instance);
|
|
|
|
setHardness(2f);
|
2017-06-14 17:56:09 +02:00
|
|
|
this.setDefaultState(this.getDefaultState().withProperty(TYPE, "tungstensteel"));
|
2017-06-14 01:49:52 +02:00
|
|
|
for (int i = 0; i < types.length; i++) {
|
2017-09-02 00:30:36 +02:00
|
|
|
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, i).setInvVariant("type=" + types[i])
|
|
|
|
.setFileName("storage"));
|
2017-06-14 01:49:52 +02:00
|
|
|
}
|
2017-06-15 12:35:08 +02:00
|
|
|
TRRecipeHandler.hideEntry(this);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public static ItemStack getStorageBlockByName(String name, int count) {
|
2017-06-14 17:56:09 +02:00
|
|
|
name = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name);
|
2016-10-08 21:46:16 +02:00
|
|
|
for (int i = 0; i < types.length; i++) {
|
|
|
|
if (types[i].equals(name)) {
|
2017-01-01 08:29:32 +01:00
|
|
|
return new ItemStack(ModBlocks.STORAGE2, count, i);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new InvalidParameterException("The storage block " + name + " could not be found.");
|
|
|
|
}
|
2017-09-02 00:30:36 +02:00
|
|
|
|
2017-09-01 17:40:33 +02:00
|
|
|
public static ItemStack getStorageBlockByName(String name) {
|
|
|
|
return getStorageBlockByName(name, 1);
|
|
|
|
}
|
2016-03-25 10:47:34 +01:00
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return Item.getItemFromBlock(this);
|
|
|
|
}
|
|
|
|
|
2017-09-02 00:30:36 +02:00
|
|
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
2016-03-25 10:47:34 +01:00
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2017-06-11 22:22:07 +02:00
|
|
|
public void getSubBlocks(CreativeTabs creativeTabs, NonNullList list) {
|
2016-10-08 21:46:16 +02:00
|
|
|
for (int meta = 0; meta < types.length; meta++) {
|
2017-06-11 22:22:07 +02:00
|
|
|
list.add(new ItemStack(this, 1, meta));
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public int damageDropped(IBlockState state) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return getMetaFromState(state);
|
|
|
|
}
|
|
|
|
|
2016-07-01 16:55:37 +02:00
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public IBlockState getStateFromMeta(int meta) {
|
|
|
|
if (meta > types.length) {
|
2016-05-21 21:05:13 +02:00
|
|
|
meta = 0;
|
|
|
|
}
|
2017-06-14 17:56:09 +02:00
|
|
|
return getBlockState().getBaseState().withProperty(TYPE, typesList.get(meta));
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public int getMetaFromState(IBlockState state) {
|
2017-06-14 17:56:09 +02:00
|
|
|
return typesList.indexOf(state.getValue(TYPE));
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2017-09-02 00:30:36 +02:00
|
|
|
@Override
|
|
|
|
public float getExplosionResistance(World world, BlockPos pos, @Nullable Entity exploder, Explosion explosion) {
|
|
|
|
String blockType = world.getBlockState(pos).getValue(TYPE);
|
|
|
|
if (blockType == "tungstensteel" || blockType == "iridium_reinforced_stone") {
|
|
|
|
return 300F;
|
|
|
|
} else if (blockType == "iridium_reinforced_tungstensteel") {
|
|
|
|
return 400F;
|
|
|
|
}
|
|
|
|
return 30F;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
protected BlockStateContainer createBlockState() {
|
2017-06-14 17:56:09 +02:00
|
|
|
return new BlockStateContainer(this, TYPE);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2015-12-11 20:48:16 +01:00
|
|
|
|
2015-05-23 00:37:10 +02:00
|
|
|
}
|