-
Notifications
You must be signed in to change notification settings - Fork 79
/
ModBlocks.java
164 lines (138 loc) · 4.62 KB
/
ModBlocks.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package mod.chiselsandbits.registry;
import java.util.HashMap;
import java.util.Map;
import mod.chiselsandbits.bittank.BlockBitTank;
import mod.chiselsandbits.bittank.ItemBlockBitTank;
import mod.chiselsandbits.bittank.TileEntityBitTank;
import mod.chiselsandbits.chiseledblock.BlockBitInfo;
import mod.chiselsandbits.chiseledblock.BlockChiseled;
import mod.chiselsandbits.chiseledblock.ItemBlockChiseled;
import mod.chiselsandbits.chiseledblock.MaterialType;
import mod.chiselsandbits.chiseledblock.TileEntityBlockChiseled;
import mod.chiselsandbits.chiseledblock.TileEntityBlockChiseled.TileEntityBlockChiseledDummy;
import mod.chiselsandbits.chiseledblock.TileEntityBlockChiseledTESR;
import mod.chiselsandbits.config.ModConfig;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
public class ModBlocks extends ModRegistry
{
// TE Registration names.
private static String TE_BIT_TANK = "mod.chiselsandbits.TileEntityBitTank";
private static String TE_CHISELEDBLOCK = "mod.chiselsandbits.TileEntityChiseled";
private static String TE_CHISELEDBLOCK_TESR = "mod.chiselsandbits.TileEntityChiseled.tesr";
private final HashMap<Material, BlockChiseled> conversions = new HashMap<Material, BlockChiseled>();
public final BlockBitTank blockBitTank;
public static final MaterialType[] validMaterials = new MaterialType[] {
new MaterialType( "wood", Material.WOOD ),
new MaterialType( "rock", Material.ROCK ),
new MaterialType( "iron", Material.IRON ),
new MaterialType( "cloth", Material.CLOTH ),
new MaterialType( "ice", Material.ICE ),
new MaterialType( "packedIce", Material.PACKED_ICE ),
new MaterialType( "clay", Material.CLAY ),
new MaterialType( "glass", Material.GLASS ),
new MaterialType( "sand", Material.SAND ),
new MaterialType( "ground", Material.GROUND ),
new MaterialType( "grass", Material.GRASS ),
new MaterialType( "snow", Material.CRAFTED_SNOW ),
new MaterialType( "fluid", Material.WATER ),
new MaterialType( "leaves", Material.LEAVES ),
};
public ModBlocks(
final ModConfig config,
final Side side )
{
// register tile entities.
GameRegistry.registerTileEntity( TileEntityBlockChiseled.class, TE_CHISELEDBLOCK );
/**
* register the TESR name either way, but if its a dedicated server
* register the normal class under the same name.
*/
if ( side == Side.CLIENT )
{
GameRegistry.registerTileEntity( TileEntityBlockChiseledTESR.class, TE_CHISELEDBLOCK_TESR );
}
else
{
GameRegistry.registerTileEntity( TileEntityBlockChiseledDummy.class, TE_CHISELEDBLOCK_TESR );
}
if ( config.enableBitTank )
{
blockBitTank = new BlockBitTank();
registerBlock( blockBitTank, ItemBlockBitTank.class, "bittank" );
GameRegistry.registerTileEntity( TileEntityBitTank.class, TE_BIT_TANK );
}
else
{
blockBitTank = null;
}
// register blocks...
for ( final MaterialType mat : validMaterials )
{
final BlockChiseled blk = new BlockChiseled( mat.type, "chiseled_" + mat.name );
getConversions().put( mat.type, blk );
registerBlock( blk, ItemBlockChiseled.class, blk.name );
}
}
public void addRecipes()
{
ShapedOreRecipe( blockBitTank, " G ", "GOG", " I ", 'G', "blockGlass", 'O', "logWood", 'I', "ingotIron" );
}
public IBlockState getChiseledDefaultState()
{
for ( final BlockChiseled bc : getConversions().values() )
{
return bc.getDefaultState();
}
return null;
}
public BlockChiseled getConversion(
final IBlockState material )
{
final Fluid f = BlockBitInfo.getFluidFromBlock( material.getBlock() );
if ( f != null )
{
return getConversions().get( Material.WATER );
}
BlockChiseled out = getConversions().get( material.getMaterial() );
if ( out == null )
{
// unknown material? just use stone.
out = getConversions().get( Material.ROCK );
}
return out;
}
public BlockChiseled getConversionWithDefault(
final IBlockState material )
{
final BlockChiseled bcX = getConversion( material );
if ( bcX == null )
{
for ( final BlockChiseled bc : getConversions().values() )
{
return bc;
}
}
return bcX;
}
public Map<Material, BlockChiseled> getConversions()
{
return conversions;
}
public boolean addConversion(
final Material newMaterial,
final Material target )
{
final BlockChiseled targ = conversions.get( target );
if ( targ != null && !conversions.containsKey( newMaterial ) )
{
BlockBitInfo.reset();
conversions.put( newMaterial, targ );
return true;
}
return false;
}
}