TechReborn/src/main/java/techreborn/blocks/BlockStorage2.java

111 lines
3.8 KiB
Java
Raw Normal View History

/*
* 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;
import net.minecraft.block.material.Material;
2015-11-24 23:58:18 +01:00
import net.minecraft.block.properties.PropertyInteger;
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;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
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;
2015-05-23 00:37:10 +02:00
import techreborn.client.TechRebornCreativeTabMisc;
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;
import java.util.Random;
2017-06-14 01:49:52 +02:00
public class BlockStorage2 extends BaseBlock {
2016-03-25 10:47:34 +01:00
2016-05-14 23:58:09 +02:00
public static final String[] types = new String[] { "tungstensteel",
2016-10-08 21:46:16 +02:00
"iridium_reinforced_tungstensteel", "iridium_reinforced_stone", "ruby", "sapphire", "peridot",
"yellowGarnet", "redGarnet", "copper", "tin", "refinedIron" };
public PropertyInteger METADATA;
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);
this.setDefaultState(this.getDefaultState().withProperty(METADATA, 0));
2017-06-14 01:49:52 +02:00
for (int i = 0; i < types.length; i++) {
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, i, "storage").setInvVariant("type=" + types[i]).setFileName("storage"));
}
2016-03-25 10:47:34 +01:00
}
2016-10-08 21:46:16 +02:00
public static ItemStack getStorageBlockByName(String name, int count) {
for (int i = 0; i < types.length; i++) {
if (types[i].equals(name)) {
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.");
}
@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);
}
@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);
}
@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;
}
return this.getDefaultState().withProperty(METADATA, meta);
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
public int getMetaFromState(IBlockState state) {
return state.getValue(METADATA);
2016-03-25 10:47:34 +01:00
}
2016-10-08 21:46:16 +02:00
protected BlockStateContainer createBlockState() {
METADATA = PropertyInteger.create("type", 0, types.length - 1);
return new BlockStateContainer(this, METADATA);
2016-03-25 10:47:34 +01:00
}
2015-12-11 20:48:16 +01:00
2015-05-23 00:37:10 +02:00
}