Skip to content

Commit 5d90508

Browse files
committed
Add charcoal, coke storage blocks.
Signed-off-by: King Lemming <kinglemming@gmail.com>
1 parent 87e1838 commit 5d90508

File tree

9 files changed

+324
-18
lines changed

9 files changed

+324
-18
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ dependencies {
5252
compile "cofh:CoFHCore:${config.mc_version}-${config.cofh_core_version}:deobf"
5353
}
5454

55-
version = "${project.config.mod_version}." + (System.getenv("BUILD_NUMBER") ?: "22")
55+
version = "${project.config.mod_version}." + (System.getenv("BUILD_NUMBER") ?: "1")
5656

5757
println config.mc_version + "-" + config.forge_version
5858
// Setup the Forge/Minecraft plugin data. Specify the preferred Forge/Minecraft version here.
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
package cofh.thermalfoundation.block;
2+
3+
import cofh.core.block.BlockCore;
4+
import cofh.core.render.IModelRegister;
5+
import cofh.core.util.core.IInitializer;
6+
import cofh.thermalfoundation.ThermalFoundation;
7+
import net.minecraft.block.SoundType;
8+
import net.minecraft.block.material.MapColor;
9+
import net.minecraft.block.material.Material;
10+
import net.minecraft.block.properties.PropertyEnum;
11+
import net.minecraft.block.state.BlockStateContainer;
12+
import net.minecraft.block.state.IBlockState;
13+
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
14+
import net.minecraft.creativetab.CreativeTabs;
15+
import net.minecraft.entity.Entity;
16+
import net.minecraft.init.Items;
17+
import net.minecraft.item.EnumRarity;
18+
import net.minecraft.item.Item;
19+
import net.minecraft.item.ItemStack;
20+
import net.minecraft.util.IStringSerializable;
21+
import net.minecraft.util.NonNullList;
22+
import net.minecraft.util.math.BlockPos;
23+
import net.minecraft.world.Explosion;
24+
import net.minecraft.world.IBlockAccess;
25+
import net.minecraft.world.World;
26+
import net.minecraftforge.client.model.ModelLoader;
27+
import net.minecraftforge.fml.common.registry.ForgeRegistries;
28+
import net.minecraftforge.fml.relauncher.Side;
29+
import net.minecraftforge.fml.relauncher.SideOnly;
30+
31+
import static cofh.core.util.helpers.ItemHelper.registerWithHandlers;
32+
import static cofh.core.util.helpers.RecipeHelper.addStorageRecipe;
33+
34+
public class BlockStorageResource extends BlockCore implements IInitializer, IModelRegister {
35+
36+
public static final PropertyEnum<Type> VARIANT = PropertyEnum.create("type", Type.class);
37+
38+
public BlockStorageResource() {
39+
40+
super(Material.ROCK, MapColor.BLACK, "thermalfoundation");
41+
42+
setUnlocalizedName("storage");
43+
setCreativeTab(ThermalFoundation.tabCommon);
44+
45+
setHardness(5.0F);
46+
setResistance(10.0F);
47+
setSoundType(SoundType.STONE);
48+
setDefaultState(getBlockState().getBaseState().withProperty(VARIANT, Type.CHARCOAL));
49+
50+
setHarvestLevel("pickaxe", 0);
51+
}
52+
53+
@Override
54+
protected BlockStateContainer createBlockState() {
55+
56+
return new BlockStateContainer(this, VARIANT);
57+
}
58+
59+
@Override
60+
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> items) {
61+
62+
for (int i = 0; i < Type.METADATA_LOOKUP.length; i++) {
63+
items.add(new ItemStack(this, 1, i));
64+
}
65+
}
66+
67+
/* TYPE METHODS */
68+
@Override
69+
public IBlockState getStateFromMeta(int meta) {
70+
71+
return this.getDefaultState().withProperty(VARIANT, Type.byMetadata(meta));
72+
}
73+
74+
@Override
75+
public int getMetaFromState(IBlockState state) {
76+
77+
return state.getValue(VARIANT).getMetadata();
78+
}
79+
80+
@Override
81+
public int damageDropped(IBlockState state) {
82+
83+
return state.getValue(VARIANT).getMetadata();
84+
}
85+
86+
/* BLOCK METHODS */
87+
@Override
88+
public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) {
89+
90+
return true;
91+
}
92+
93+
@Override
94+
public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos) {
95+
96+
return state.getValue(VARIANT).getLight();
97+
}
98+
99+
@Override
100+
public float getBlockHardness(IBlockState state, World world, BlockPos pos) {
101+
102+
return state.getValue(VARIANT).getHardness();
103+
}
104+
105+
@Override
106+
public float getExplosionResistance(World world, BlockPos pos, Entity exploder, Explosion explosion) {
107+
108+
IBlockState state = world.getBlockState(pos);
109+
return state.getValue(VARIANT).getResistance();
110+
}
111+
112+
/* IModelRegister */
113+
@Override
114+
@SideOnly (Side.CLIENT)
115+
public void registerModels() {
116+
117+
for (int i = 0; i < Type.values().length; i++) {
118+
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), i, new ModelResourceLocation(modName + ":" + name + "_resource", "type=" + Type.byMetadata(i).getName()));
119+
}
120+
}
121+
122+
/* IInitializer */
123+
@Override
124+
public boolean initialize() {
125+
126+
this.setRegistryName("storage_resource");
127+
ForgeRegistries.BLOCKS.register(this);
128+
129+
ItemBlockStorageResource itemBlock = new ItemBlockStorageResource(this);
130+
itemBlock.setRegistryName(this.getRegistryName());
131+
ForgeRegistries.ITEMS.register(itemBlock);
132+
133+
blockCharcoal = new ItemStack(this, 1, Type.CHARCOAL.getMetadata());
134+
blockCoke = new ItemStack(this, 1, Type.COKE.getMetadata());
135+
136+
registerWithHandlers("blockCharcoal", blockCharcoal);
137+
registerWithHandlers("blockCoke", blockCoke);
138+
139+
ThermalFoundation.proxy.addIModelRegister(this);
140+
141+
return true;
142+
}
143+
144+
@Override
145+
public boolean register() {
146+
147+
addStorageRecipe(blockCharcoal, new ItemStack(Items.COAL, 1, 1));
148+
addStorageRecipe(blockCoke, "fuelCoke");
149+
150+
return true;
151+
}
152+
153+
/* TYPE */
154+
public enum Type implements IStringSerializable {
155+
156+
// @formatter:off
157+
CHARCOAL(0, "charcoal"),
158+
COKE(1, "coke");
159+
// @formatter: on
160+
161+
private static final Type[] METADATA_LOOKUP = new Type[values().length];
162+
private final int metadata;
163+
private final String name;
164+
private final int light;
165+
private final float hardness;
166+
private final float resistance;
167+
private final EnumRarity rarity;
168+
169+
Type(int metadata, String name, int light, float hardness, float resistance, EnumRarity rarity) {
170+
171+
this.metadata = metadata;
172+
this.name = name;
173+
this.light = light;
174+
this.hardness = hardness;
175+
this.resistance = resistance;
176+
this.rarity = rarity;
177+
}
178+
179+
Type(int metadata, String name, int light, float hardness, float resistance) {
180+
181+
this(metadata, name, light, hardness, resistance, EnumRarity.COMMON);
182+
}
183+
184+
Type(int metadata, String name, float hardness, float resistance) {
185+
this(metadata, name, 0, hardness, resistance, EnumRarity.COMMON);
186+
}
187+
188+
Type(int metadata, String name, int light) {
189+
190+
this(metadata, name, light, 5.0F, 6.0F, EnumRarity.COMMON);
191+
}
192+
193+
Type(int metadata, String name) {
194+
195+
this(metadata, name, 0, 5.0F, 6.0F, EnumRarity.COMMON);
196+
}
197+
198+
public int getMetadata() {
199+
return this.metadata;
200+
}
201+
202+
@Override
203+
public String getName() {
204+
205+
return this.name;
206+
}
207+
208+
public int getLight() {
209+
210+
return this.light;
211+
}
212+
213+
public float getHardness() {
214+
215+
return this.hardness;
216+
}
217+
218+
public float getResistance() {
219+
220+
return this.resistance;
221+
}
222+
223+
public EnumRarity getRarity() {
224+
225+
return this.rarity;
226+
}
227+
228+
public static Type byMetadata(int metadata) {
229+
230+
if (metadata < 0 || metadata >= METADATA_LOOKUP.length) {
231+
metadata = 0;
232+
}
233+
return METADATA_LOOKUP[metadata];
234+
}
235+
236+
static {
237+
for (Type type : values()) {
238+
METADATA_LOOKUP[type.getMetadata()] = type;
239+
}
240+
}
241+
}
242+
243+
/* REFERENCES */
244+
public static ItemStack blockCharcoal;
245+
public static ItemStack blockCoke;
246+
// TODO: Rosin/Tar?
247+
// TODO: Slags?
248+
249+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package cofh.thermalfoundation.block;
2+
3+
import cofh.core.block.ItemBlockCore;
4+
import cofh.core.util.helpers.ItemHelper;
5+
import cofh.thermalfoundation.block.BlockStorageResource.Type;
6+
import net.minecraft.block.Block;
7+
import net.minecraft.item.EnumRarity;
8+
import net.minecraft.item.ItemStack;
9+
10+
public class ItemBlockStorageResource extends ItemBlockCore {
11+
12+
public ItemBlockStorageResource(Block block) {
13+
14+
super(block);
15+
setHasSubtypes(true);
16+
setMaxDamage(0);
17+
}
18+
19+
@Override
20+
public String getUnlocalizedName(ItemStack stack) {
21+
22+
return "tile.thermalfoundation.storage." + Type.byMetadata(ItemHelper.getItemDamage(stack)).getName() + ".name";
23+
}
24+
25+
@Override
26+
public EnumRarity getRarity(ItemStack stack) {
27+
28+
return Type.byMetadata(ItemHelper.getItemDamage(stack)).getRarity();
29+
}
30+
31+
}

src/main/java/cofh/thermalfoundation/init/TFBlocks.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public static void preInit() {
2323
blockOreFluid = new BlockOreFluid();
2424
blockStorage = new BlockStorage();
2525
blockStorageAlloy = new BlockStorageAlloy();
26+
blockStorageResource = new BlockStorageResource();
2627
blockGlass = new BlockGlass();
2728
blockGlassAlloy = new BlockGlassAlloy();
2829
blockRockwool = new BlockRockwool();
@@ -31,6 +32,7 @@ public static void preInit() {
3132
initList.add(blockOreFluid);
3233
initList.add(blockStorage);
3334
initList.add(blockStorageAlloy);
35+
initList.add(blockStorageResource);
3436
initList.add(blockGlass);
3537
initList.add(blockGlassAlloy);
3638
initList.add(blockRockwool);
@@ -57,6 +59,7 @@ public void registerRecipes(RegistryEvent.Register<IRecipe> event) {
5759
public static BlockOreFluid blockOreFluid;
5860
public static BlockStorage blockStorage;
5961
public static BlockStorageAlloy blockStorageAlloy;
62+
public static BlockStorageResource blockStorageResource;
6063
public static BlockGlass blockGlass;
6164
public static BlockGlassAlloy blockGlassAlloy;
6265
public static BlockRockwool blockRockwool;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"forge_marker": 1,
3+
"defaults": {
4+
"model": "cube_all",
5+
"transform": "forge:default-block"
6+
},
7+
"variants": {
8+
"type": {
9+
"charcoal": {
10+
"textures": {
11+
"all": "thermalfoundation:blocks/storage/block_charcoal"
12+
}
13+
},
14+
"coke": {
15+
"textures": {
16+
"all": "thermalfoundation:blocks/storage/block_coke"
17+
}
18+
}
19+
}
20+
}
21+
}

src/main/resources/assets/thermalfoundation/lang/en_US.lang

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -591,20 +591,22 @@ tile.thermalfoundation.rockwool.silver.name=Light Gray Rockwool
591591
tile.thermalfoundation.rockwool.white.name=White Rockwool
592592
tile.thermalfoundation.rockwool.yellow.name=Yellow Rockwool
593593

594-
tile.thermalfoundation.storage.aluminum.name=Aluminum Block
595-
tile.thermalfoundation.storage.bronze.name=Bronze Block
596-
tile.thermalfoundation.storage.constantan.name=Constantan Block
597-
tile.thermalfoundation.storage.copper.name=Copper Block
598-
tile.thermalfoundation.storage.electrum.name=Electrum Block
599-
tile.thermalfoundation.storage.enderium.name=Enderium Block
600-
tile.thermalfoundation.storage.invar.name=Invar Block
601-
tile.thermalfoundation.storage.iridium.name=Iridium Block
602-
tile.thermalfoundation.storage.lead.name=Lead Block
603-
tile.thermalfoundation.storage.lumium.name=Lumium Block
604-
tile.thermalfoundation.storage.mithril.name=Mana Infused Block
605-
tile.thermalfoundation.storage.nickel.name=Nickel Block
606-
tile.thermalfoundation.storage.platinum.name=Platinum Block
607-
tile.thermalfoundation.storage.signalum.name=Signalum Block
608-
tile.thermalfoundation.storage.silver.name=Silver Block
609-
tile.thermalfoundation.storage.steel.name=Steel Block
610-
tile.thermalfoundation.storage.tin.name=Tin Block
594+
tile.thermalfoundation.storage.aluminum.name=Block of Aluminum
595+
tile.thermalfoundation.storage.bronze.name=Block of Bronze
596+
tile.thermalfoundation.storage.charcoal.name=Block of Charcoal
597+
tile.thermalfoundation.storage.coke.name=Block of Coal Coke
598+
tile.thermalfoundation.storage.constantan.name=Block of Constantan
599+
tile.thermalfoundation.storage.copper.name=Block of Copper
600+
tile.thermalfoundation.storage.electrum.name=Block of Electrum
601+
tile.thermalfoundation.storage.enderium.name=Block of Enderium
602+
tile.thermalfoundation.storage.invar.name=Block of Invar
603+
tile.thermalfoundation.storage.iridium.name=Block of Iridium
604+
tile.thermalfoundation.storage.lead.name=Block of Lead
605+
tile.thermalfoundation.storage.lumium.name=Block of Lumium
606+
tile.thermalfoundation.storage.mithril.name=Block of Mana Infused Metal
607+
tile.thermalfoundation.storage.nickel.name=Block of Nickel
608+
tile.thermalfoundation.storage.platinum.name=Block of Platinum
609+
tile.thermalfoundation.storage.signalum.name=Block of Signalum
610+
tile.thermalfoundation.storage.silver.name=Block of Silver
611+
tile.thermalfoundation.storage.steel.name=Block of Steel
612+
tile.thermalfoundation.storage.tin.name=Block of Tin
354 Bytes
Loading
330 Bytes
Loading
3 Bytes
Loading

0 commit comments

Comments
 (0)