-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_CobbleFence.java
232 lines (189 loc) · 9.37 KB
/
mod_CobbleFence.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package net.minecraft.src;
import java.util.Map;
import org.lwjgl.opengl.GL11;
public class mod_CobbleFence extends BaseMod
{
public static final Block cobbleFence;
public static final Block mossyCobbleFence;
public static final Block smoothStoneFence;
public static final Block brickFence;
public static final Block stoneFence;
public static final Block sandStoneFence;
public static int COBBLESTONE_FENCE_ID = 234;
public static int MOSSYCOBBLESTONE_FENCE_ID = 235;
public static int SMOOTHSTONE_FENCE_ID = 236;
public static int BRICK_FENCE_ID = 237;
public static int STONE_FENCE_ID = 238;
public static int SANDSTONE_FENCE_ID = 239;
private static int cobbleTexture = 16;
private static int mossyTexture = 36;
private static int smoothTexture = 1;
private static int brickTexture = 7;
private static int stoneTexture = 54;
private static int sandstoneTexture = 192;
static
{
cobbleFence = new BlockCobbleFence(COBBLESTONE_FENCE_ID, cobbleTexture)
.setBlockName("cobbleFence");
mossyCobbleFence = new BlockCobbleFence(MOSSYCOBBLESTONE_FENCE_ID, mossyTexture)
.setBlockName("mossyCobbleFence");
smoothStoneFence = new BlockCobbleFence(SMOOTHSTONE_FENCE_ID, smoothTexture)
.setBlockName("smoothStoneFence");
brickFence = new BlockCobbleFence(BRICK_FENCE_ID, brickTexture)
.setBlockName("brickFence");
stoneFence = new BlockCobbleFence(STONE_FENCE_ID, stoneTexture)
.setBlockName("stoneFence");
sandStoneFence = new BlockCobbleFence(SANDSTONE_FENCE_ID, sandstoneTexture)
.setBlockName("mossyStoneFence");
}
public mod_CobbleFence()
{
ModLoader.RegisterBlock(cobbleFence);
ModLoader.AddName(cobbleFence, "Cobblestone Wall");
ModLoader.RegisterBlock(mossyCobbleFence);
ModLoader.AddName(mossyCobbleFence, "Mossy Cobblestone Wall");
ModLoader.RegisterBlock(smoothStoneFence);
ModLoader.AddName(smoothStoneFence, "Smoothstone Wall");
ModLoader.RegisterBlock(brickFence);
ModLoader.AddName(brickFence, "Brick Wall");
ModLoader.RegisterBlock(stoneFence);
ModLoader.AddName(stoneFence, "Stone Wall");
ModLoader.RegisterBlock(sandStoneFence);
ModLoader.AddName(sandStoneFence, "Sandstone Wall");
//Set up custom render ID
int temp = ModLoader.getUniqueBlockModelID(this, true);
((BlockCobbleFence)cobbleFence).setRenderType(temp);
ModLoader.RenderBlockIsItemFull3D(COBBLESTONE_FENCE_ID);
((BlockCobbleFence)mossyCobbleFence).setRenderType(temp);
ModLoader.RenderBlockIsItemFull3D(MOSSYCOBBLESTONE_FENCE_ID);
((BlockCobbleFence)smoothStoneFence).setRenderType(temp);
ModLoader.RenderBlockIsItemFull3D(SMOOTHSTONE_FENCE_ID);
((BlockCobbleFence)brickFence).setRenderType(temp);
ModLoader.RenderBlockIsItemFull3D(BRICK_FENCE_ID);
((BlockCobbleFence)stoneFence).setRenderType(temp);
ModLoader.RenderBlockIsItemFull3D(STONE_FENCE_ID);
((BlockCobbleFence)sandStoneFence).setRenderType(temp);
ModLoader.RenderBlockIsItemFull3D(SANDSTONE_FENCE_ID);
// Setting up recipes
ModLoader.AddRecipe(new ItemStack(cobbleFence,6), new Object[]{
"###", "###", Character.valueOf('#'), Block.cobblestone
});
ModLoader.AddRecipe(new ItemStack(mossyCobbleFence,6), new Object[]{
"###", "###", Character.valueOf('#'), Block.cobblestoneMossy
});
ModLoader.AddRecipe(new ItemStack(smoothStoneFence,6), new Object[]{
"###", "###", Character.valueOf('#'), Block.stone
});
ModLoader.AddRecipe(new ItemStack(brickFence,6), new Object[]{
"###", "###", Character.valueOf('#'), Block.brick
});
ModLoader.AddRecipe(new ItemStack(stoneFence,6), new Object[]{
"###", "###", Character.valueOf('#'), Block.stoneBrick
});
ModLoader.AddRecipe(new ItemStack(sandStoneFence,6), new Object[]{
"###", "###", Character.valueOf('#'), Block.sandStone
});
}
@Override
public String Version()
{
return "1.8.1";
}
//Renders the look of the fence in Inventory
public void RenderInvBlock(RenderBlocks renderblocks, Block block, int i, int j)
{
Tessellator tessellator = Tessellator.instance;
//(0.0F, wallBottom, wallOffset, 1.0F, wallHeight, wallWidth);
block.setBlockBounds(0.0F, 0.0F, 0.3F, 1.0F, 0.8F, 0.7F);
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, -1F, 0.0F);
renderblocks.renderBottomFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSide(0));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 1.0F, 0.0F);
renderblocks.renderTopFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSide(1));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, -1F);
renderblocks.renderEastFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSide(2));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, 1.0F);
renderblocks.renderWestFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSide(3));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(-1F, 0.0F, 0.0F);
renderblocks.renderNorthFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSide(4));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(1.0F, 0.0F, 0.0F);
renderblocks.renderSouthFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSide(5));
tessellator.draw();
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
//Renders the look of the wall in the world
public boolean RenderWorldBlock(RenderBlocks renderblocks, IBlockAccess iblockaccess, int i, int j, int k, Block block, int l)
{
BlockCobbleFence blockCobbleFence = (BlockCobbleFence)block;
boolean flag = false;
//Wall Constants
float wallOffset = 0.3F;
float wallWidth = 0.7F;
float wallBottom = 0.0F;
float wallHeight = 0.8F;
float postOffset = 0.2F; //0.375F;
float postWidth = 0.8F;//0.625F;
float postHeight = 1.0F;
//NSWE Flags for rendering additional fence pieces
boolean west = blockCobbleFence.isWallOrGateAt(iblockaccess, i - 1, j, k);
boolean east = blockCobbleFence.isWallOrGateAt(iblockaccess, i + 1, j, k);
boolean south = blockCobbleFence.isWallOrGateAt(iblockaccess, i, j, k - 1);
boolean north = blockCobbleFence.isWallOrGateAt(iblockaccess, i, j, k + 1);
/* Couldn't make this look pretty :(
//Render Interaction with wooden objects
boolean otherWest = blockCobbleFence.isWoodenFenceAt(iblockaccess, i - 1, j, k);
boolean otherEast = blockCobbleFence.isWoodenFenceAt(iblockaccess, i + 1, j, k);
boolean otherSouth = blockCobbleFence.isWoodenFenceAt(iblockaccess, i, j, k - 1);
boolean otherNorth = blockCobbleFence.isWoodenFenceAt(iblockaccess, i, j, k + 1);
*/
if(north && south && !(east || west)){
//Render full length wall North/South
blockCobbleFence.setBlockBounds(wallOffset, wallBottom, 0.0F, wallWidth, wallHeight, 1.0F);
renderblocks.renderStandardBlock(blockCobbleFence, i, j, k);
}else if(east && west && !(north || south)){
//Render Full length wall East/west
blockCobbleFence.setBlockBounds(0.0F, wallBottom, wallOffset, 1.0F, wallHeight, wallWidth);
renderblocks.renderStandardBlock(blockCobbleFence, i, j, k);
}else{
//Render Center Post
blockCobbleFence.setBlockBounds(postOffset, 0.0F, postOffset, postWidth, postHeight, postWidth);
renderblocks.renderStandardBlock(blockCobbleFence, i, j, k);
//render West
if(west){
blockCobbleFence.setBlockBounds(0.0F, wallBottom, wallOffset, wallWidth, wallHeight, wallWidth);
renderblocks.renderStandardBlock(blockCobbleFence, i, j, k);
}
//Render East
if(east){
blockCobbleFence.setBlockBounds(wallOffset, wallBottom, wallOffset, 1.0F, wallHeight, wallWidth);
renderblocks.renderStandardBlock(blockCobbleFence, i, j, k);
}
//Render North
if(north)
{
blockCobbleFence.setBlockBounds(wallOffset, wallBottom, wallOffset, wallWidth, wallHeight, 1.0F);
renderblocks.renderStandardBlock(blockCobbleFence, i, j, k);
}
//Render South
if(south)
{
blockCobbleFence.setBlockBounds(wallOffset, wallBottom, 0.0F, wallWidth, wallHeight, wallWidth);
renderblocks.renderStandardBlock(blockCobbleFence, i, j, k);
}
}
blockCobbleFence.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
return true;
}
}