Skip to content
This repository was archived by the owner on Mar 9, 2024. It is now read-only.

Commit 534c098

Browse files
committed
Got walls working, simplified the code by looking @ botania's implementation.
Still some missing textures here and there, mostly with wall break particles and waila tooltips. Might be worth shipping a Beta on this build. #29
1 parent 5e4245b commit 534c098

File tree

7 files changed

+99
-144
lines changed

7 files changed

+99
-144
lines changed

src/main/java/com/renevo/nethercore/blocks/BlockStoneWall.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
11
package com.renevo.nethercore.blocks;
22

33
import com.renevo.nethercore.NetherCoreRegistry;
4-
import net.minecraft.block.material.Material;
4+
import net.minecraft.block.Block;
55
import net.minecraft.block.properties.PropertyEnum;
66
import net.minecraft.block.state.IBlockState;
77
import net.minecraft.util.IStringSerializable;
88

99
import java.util.Locale;
1010

1111
public class BlockStoneWall extends EnumBlockWall<BlockStoneWall.WallType> {
12-
public static final PropertyEnum<WallType> VARIANT = PropertyEnum.create("variant", WallType.class);
12+
public static final PropertyEnum<WallType> VARIANT = PropertyEnum.create("stone_variant", WallType.class);
1313

14-
public BlockStoneWall() {
15-
this(Material.rock);
16-
}
17-
18-
public BlockStoneWall(Material material) {
19-
super(material, VARIANT, WallType.class);
14+
public BlockStoneWall(Block block) {
15+
super(block, VARIANT, WallType.class);
2016

2117
IBlockState blockState = this.blockState.getBaseState();
22-
this.setDefaultState(blockState.withProperty(VARIANT, WallType.STONE).withProperty(UP, true).withProperty(NORTH, true).withProperty(EAST, false).withProperty(SOUTH, true).withProperty(WEST, false));
18+
this.setDefaultState(blockState.withProperty(VARIANT, WallType.STONE).withProperty(UP, false).withProperty(NORTH, false).withProperty(EAST, false).withProperty(SOUTH, false).withProperty(WEST, false));
2319
this.setCreativeTab(NetherCoreRegistry.tabNetherCore);
24-
this.setHardness(3F);
25-
this.setResistance(20F);
2620
this.setHarvestLevel("pickaxe", 1); // 1 is stone required (0 wood, 1 stone, 2 iron)
27-
this.setStepSound(NetherCoreBlocks.soundTypeNetherStone);
2821
}
2922

3023
public enum WallType implements IStringSerializable, EnumBlockWall.IEnumMeta {

src/main/java/com/renevo/nethercore/blocks/EnumBlockSlab.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Locale;
2020
import java.util.Random;
2121

22+
// TODO: switch to mantle version
2223
public abstract class EnumBlockSlab<E extends Enum<E> & EnumBlockSlab.IEnumMeta & IStringSerializable> extends BlockSlab {
2324
private final E[] values;
2425
public static final PropertyBool SEAMLESS = PropertyBool.create("seamless");

src/main/java/com/renevo/nethercore/blocks/EnumBlockWall.java

Lines changed: 8 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,35 @@
11
package com.renevo.nethercore.blocks;
22

33
import net.minecraft.block.Block;
4-
import net.minecraft.block.BlockFenceGate;
5-
import net.minecraft.block.material.Material;
6-
import net.minecraft.block.properties.PropertyBool;
4+
import net.minecraft.block.BlockWall;
75
import net.minecraft.block.properties.PropertyEnum;
86
import net.minecraft.block.state.BlockStateContainer;
97
import net.minecraft.block.state.IBlockState;
108
import net.minecraft.creativetab.CreativeTabs;
11-
import net.minecraft.init.Blocks;
129
import net.minecraft.item.Item;
1310
import net.minecraft.item.ItemStack;
14-
import net.minecraft.util.EnumFacing;
1511
import net.minecraft.util.IStringSerializable;
16-
import net.minecraft.util.math.AxisAlignedBB;
1712
import net.minecraft.util.math.BlockPos;
1813
import net.minecraft.world.IBlockAccess;
19-
import net.minecraft.world.World;
2014
import net.minecraftforge.fml.relauncher.Side;
2115
import net.minecraftforge.fml.relauncher.SideOnly;
2216

2317
import java.util.List;
2418

25-
public class EnumBlockWall<E extends Enum<E> & EnumBlockWall.IEnumMeta & IStringSerializable> extends Block {
26-
public static final PropertyBool UP = PropertyBool.create("up");
27-
public static final PropertyBool NORTH = PropertyBool.create("north");
28-
public static final PropertyBool EAST = PropertyBool.create("east");
29-
public static final PropertyBool SOUTH = PropertyBool.create("south");
30-
public static final PropertyBool WEST = PropertyBool.create("west");
31-
protected static final AxisAlignedBB[] BASE_BBS = new AxisAlignedBB[]{new AxisAlignedBB(0.25D, 0.0D, 0.25D, 0.75D, 1.0D, 0.75D), new AxisAlignedBB(0.25D, 0.0D, 0.25D, 0.75D, 1.0D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.25D, 0.75D, 1.0D, 0.75D), new AxisAlignedBB(0.0D, 0.0D, 0.25D, 0.75D, 1.0D, 1.0D), new AxisAlignedBB(0.25D, 0.0D, 0.0D, 0.75D, 1.0D, 0.75D), new AxisAlignedBB(0.3125D, 0.0D, 0.0D, 0.6875D, 0.875D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.75D, 1.0D, 0.75D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.75D, 1.0D, 1.0D), new AxisAlignedBB(0.25D, 0.0D, 0.25D, 1.0D, 1.0D, 0.75D), new AxisAlignedBB(0.25D, 0.0D, 0.25D, 1.0D, 1.0D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.3125D, 1.0D, 0.875D, 0.6875D), new AxisAlignedBB(0.0D, 0.0D, 0.25D, 1.0D, 1.0D, 1.0D), new AxisAlignedBB(0.25D, 0.0D, 0.0D, 1.0D, 1.0D, 0.75D), new AxisAlignedBB(0.25D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.75D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D)};
32-
protected static final AxisAlignedBB[] ACTUAL_BBS;
33-
19+
public class EnumBlockWall<E extends Enum<E> & EnumBlockWall.IEnumMeta & IStringSerializable> extends BlockWall {
3420
private final E[] values;
3521
public final PropertyEnum<E> prop;
3622
private static PropertyEnum<?> tmp;
3723

38-
public EnumBlockWall(Material material, PropertyEnum<E> prop, Class<E> clazz) {
39-
super(preInit(material, prop));
24+
public EnumBlockWall(Block block, PropertyEnum<E> prop, Class<E> clazz) {
25+
super(preInit(block, prop));
4026
this.prop = prop;
4127
values = clazz.getEnumConstants();
4228
}
4329

44-
@SuppressWarnings("unchecked")
45-
private static Material preInit(Material material, PropertyEnum<?> property) {
30+
private static Block preInit(Block block, PropertyEnum<?> property) {
4631
tmp = property;
47-
return material;
48-
}
49-
50-
@Override
51-
public boolean isFullCube(IBlockState blockState) {
52-
return false;
53-
}
54-
55-
@Override
56-
public boolean isPassable(IBlockAccess blockAccess, BlockPos blockPos) {
57-
return false;
58-
}
59-
60-
@Override
61-
public boolean isOpaqueCube(IBlockState blockState) {
62-
return false;
63-
}
64-
65-
@Override
66-
public AxisAlignedBB getBoundingBox(IBlockState p_getBoundingBox_1_, IBlockAccess p_getBoundingBox_2_, BlockPos p_getBoundingBox_3_) {
67-
p_getBoundingBox_1_ = this.getActualState(p_getBoundingBox_1_, p_getBoundingBox_2_, p_getBoundingBox_3_);
68-
return BASE_BBS[getFacingFlags(p_getBoundingBox_1_)];
69-
}
70-
71-
@Override
72-
public AxisAlignedBB getSelectedBoundingBox(IBlockState p_getSelectedBoundingBox_1_, World p_getSelectedBoundingBox_2_, BlockPos p_getSelectedBoundingBox_3_) {
73-
p_getSelectedBoundingBox_1_ = this.getActualState(p_getSelectedBoundingBox_1_, p_getSelectedBoundingBox_2_, p_getSelectedBoundingBox_3_);
74-
return ACTUAL_BBS[getFacingFlags(p_getSelectedBoundingBox_1_)];
75-
}
76-
77-
// face flags... GET YO FACE... not sure what better to call this
78-
// basically, this selects the Bounding Box based on the sides that are connected.
79-
private static int getFacingFlags(IBlockState blockState) {
80-
int faceFlags = 0;
81-
if(blockState.getValue(NORTH)) {
82-
faceFlags |= 1 << EnumFacing.NORTH.getHorizontalIndex();
83-
}
84-
85-
if(blockState.getValue(EAST)) {
86-
faceFlags |= 1 << EnumFacing.EAST.getHorizontalIndex();
87-
}
88-
89-
if(blockState.getValue(SOUTH)) {
90-
faceFlags |= 1 << EnumFacing.SOUTH.getHorizontalIndex();
91-
}
92-
93-
if(blockState.getValue(WEST)) {
94-
faceFlags |= 1 << EnumFacing.WEST.getHorizontalIndex();
95-
}
96-
97-
return faceFlags;
98-
}
99-
100-
@SuppressWarnings("SimplifiableConditionalExpression") // more readable this way
101-
protected boolean canConnectTo(IBlockAccess blockAccess, BlockPos blockPos) {
102-
IBlockState block = blockAccess.getBlockState(blockPos);
103-
return block.getBlock() == Blocks.barrier
104-
? false
105-
: (block.getBlock() != this && !(block.getBlock() instanceof BlockFenceGate)
106-
? (block.getMaterial().isOpaque() && block.isFullCube()
107-
? block.getMaterial() != Material.gourd
108-
: false)
109-
: true);
32+
return block;
11033
}
11134

11235
@Override
@@ -127,12 +50,6 @@ public int damageDropped(IBlockState state) {
12750
return getMetaFromState(state);
12851
}
12952

130-
@SideOnly(Side.CLIENT)
131-
@Override
132-
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos blockPos, EnumFacing enumFacing) {
133-
return enumFacing != EnumFacing.DOWN || super.shouldSideBeRendered(blockState, blockAccess, blockPos, enumFacing);
134-
}
135-
13653
@Override
13754
public IBlockState getStateFromMeta(int meta) {
13855
return this.getDefaultState().withProperty(prop, fromMeta(meta));
@@ -145,12 +62,12 @@ public int getMetaFromState(IBlockState state) {
14562

14663
@Override
14764
public IBlockState getActualState(IBlockState blockState, IBlockAccess blockAccess, BlockPos blockPos) {
148-
return blockState.withProperty(UP, !blockAccess.isAirBlock(blockPos.up())).withProperty(NORTH, this.canConnectTo(blockAccess, blockPos.north())).withProperty(EAST, this.canConnectTo(blockAccess, blockPos.east())).withProperty(SOUTH, this.canConnectTo(blockAccess, blockPos.south())).withProperty(WEST, this.canConnectTo(blockAccess, blockPos.west()));
65+
return super.getActualState(blockState, blockAccess, blockPos).withProperty(prop, fromMeta(getMetaFromState(blockState)));
14966
}
15067

15168
@Override
15269
protected BlockStateContainer createBlockState() {
153-
return new BlockStateContainer(this, UP, NORTH, EAST, WEST, SOUTH, prop == null ? tmp : prop);
70+
return new BlockStateContainer(this, VARIANT, UP, NORTH, EAST, WEST, SOUTH, prop == null ? tmp : prop);
15471
}
15572

15673
protected E fromMeta(int meta) {
@@ -161,10 +78,6 @@ protected E fromMeta(int meta) {
16178
return values[meta];
16279
}
16380

164-
static {
165-
ACTUAL_BBS = new AxisAlignedBB[]{BASE_BBS[0].setMaxY(1.5D), BASE_BBS[1].setMaxY(1.5D), BASE_BBS[2].setMaxY(1.5D), BASE_BBS[3].setMaxY(1.5D), BASE_BBS[4].setMaxY(1.5D), BASE_BBS[5].setMaxY(1.5D), BASE_BBS[6].setMaxY(1.5D), BASE_BBS[7].setMaxY(1.5D), BASE_BBS[8].setMaxY(1.5D), BASE_BBS[9].setMaxY(1.5D), BASE_BBS[10].setMaxY(1.5D), BASE_BBS[11].setMaxY(1.5D), BASE_BBS[12].setMaxY(1.5D), BASE_BBS[13].setMaxY(1.5D), BASE_BBS[14].setMaxY(1.5D), BASE_BBS[15].setMaxY(1.5D)};
166-
}
167-
16881
public interface IEnumMeta {
16982
int getMeta();
17083
}

src/main/java/com/renevo/nethercore/blocks/NetherCoreBlocks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static void init() {
6363
blockNetherHalfSlab = registerEnumBlock(halfStoneSlab, halfStoneSlab, doubleStoneSlab, "slab_half_stone");
6464
blockNetherDoubleSlab = registerEnumBlock(doubleStoneSlab, halfStoneSlab, doubleStoneSlab, "slab_double_stone");
6565

66-
blockNetherStoneWall = registerEnumBlock(new BlockStoneWall(), "wall_stone");
66+
blockNetherStoneWall = registerEnumBlock(new BlockStoneWall(blockNetherStone), "wall_stone");
6767

6868
blockNetherGrass = registerBlock(new BlockNetherGrass(), "nether_grass");
6969

src/main/java/com/renevo/nethercore/common/ClientProxy.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.renevo.nethercore.common;
22

33
import com.renevo.nethercore.Util;
4-
import com.renevo.nethercore.blocks.BlockCompressedNetherrack;
54
import com.renevo.nethercore.blocks.BlockStoneSlab;
5+
import com.renevo.nethercore.blocks.BlockStoneWall;
66
import com.renevo.nethercore.blocks.NetherCoreBlocks;
77
import com.renevo.nethercore.item.NetherCoreItems;
88
import net.minecraft.block.Block;
@@ -42,7 +42,6 @@ public void registerModels() {
4242
registerItemBlockMeta(NetherCoreBlocks.blockCompressedNetherrack);
4343
registerItemBlockMeta(NetherCoreBlocks.blockNetherOre);
4444
registerItemBlockMeta(NetherCoreBlocks.blockNetherStone);
45-
registerItemBlockMeta(NetherCoreBlocks.blockNetherStoneWall);
4645

4746
// stairs
4847
itemToAdd = Item.getItemFromBlock(NetherCoreBlocks.blockNetherStoneStairs);
@@ -58,6 +57,13 @@ public void registerModels() {
5857
ModelLoader.setCustomModelResourceLocation(itemToAdd, t.getMeta(), new ModelResourceLocation(Util.getResource("slab_half_stone"), "half=bottom,variant=" + t.getName().toLowerCase(Locale.US)));
5958
}
6059

60+
// walls
61+
itemToAdd = Item.getItemFromBlock(NetherCoreBlocks.blockNetherStoneWall);
62+
for (BlockStoneWall.WallType wall : BlockStoneWall.WallType.values()) {
63+
String variantName = "inventory_" + wall.getName();
64+
ModelLoader.setCustomModelResourceLocation(itemToAdd, wall.getMeta(), new ModelResourceLocation(itemToAdd.getRegistryName(), variantName));
65+
}
66+
6167
// grass
6268
itemToAdd = Item.getItemFromBlock(NetherCoreBlocks.blockNetherGrass);
6369
ModelLoader.setCustomModelResourceLocation(itemToAdd, 0, new ModelResourceLocation(Util.getResource("nether_grass"), "inventory"));
Lines changed: 64 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,69 @@
11
{
22
"forge_marker": 1,
33
"defaults": {
4-
"transform": "forge:default-block",
5-
"model": "minecraft:wall_post",
4+
"model": "nethercore:dummy",
65
"textures": {
7-
"wall": "nethercore:blocks/nether_stone_cobble"
8-
}
6+
"texture": "nethercore:blocks/nether_stone"
7+
},
8+
"uvlock": true,
9+
"transform": "forge:default-block"
910
},
1011
"variants": {
11-
"inventory": [{}],
12-
"normal": [{}],
13-
"east": {"true": {}, "false": {}},
14-
"north": {"true": {}, "false": {}},
15-
"south": {"true": {}, "false": {}},
16-
"up": {"true": {}, "false": {}},
17-
"west": {"true": {}, "false": {}},
18-
"variant": {
12+
"inventory_stone": [{
13+
"model": "minecraft:wall_inventory",
14+
"y": 180,
15+
"textures": {
16+
"wall": "nethercore:blocks/nether_stone"
17+
}
18+
}],
19+
"inventory_cobblestone": [{
20+
"model": "minecraft:wall_inventory",
21+
"y": 180,
22+
"textures": {
23+
"wall": "nethercore:blocks/nether_stone_cobble"
24+
}
25+
}],
26+
"inventory_brick": [{
27+
"model": "minecraft:wall_inventory",
28+
"y": 180,
29+
"textures": {
30+
"wall": "minecraft:blocks/nether_brick"
31+
}
32+
}],
33+
"north": {
34+
"true": {
35+
"submodel": "minecraft:wall_side"
36+
},
37+
"false": {}
38+
},
39+
"south": {
40+
"true": {
41+
"submodel": "minecraft:wall_side",
42+
"y": 180
43+
},
44+
"false": {}
45+
},
46+
"west": {
47+
"true": {
48+
"submodel": "minecraft:wall_side",
49+
"y": 270
50+
},
51+
"false": {}
52+
},
53+
"east": {
54+
"true": {
55+
"submodel": "minecraft:wall_side",
56+
"y": 90
57+
},
58+
"false": {}
59+
},
60+
"up": {
61+
"true": {
62+
"submodel": "minecraft:wall_post"
63+
},
64+
"false": {}
65+
},
66+
"stone_variant": {
1967
"stone": {
2068
"textures": {
2169
"wall": "nethercore:blocks/nether_stone"
@@ -31,28 +79,10 @@
3179
"wall": "minecraft:blocks/nether_brick"
3280
}
3381
}
34-
}
35-
},
36-
"multipart": [
37-
{
38-
"when": { "up": "true" },
39-
"apply": { "model": "minecraft:wall_post" }
40-
},
41-
{
42-
"when": { "north": "true" },
43-
"apply": { "model": "minecraft:wall_side", "uvlock": true }
44-
},
45-
{
46-
"when": { "east": "true" },
47-
"apply": { "model": "minecraft:wall_side", "y": 90, "uvlock": true }
4882
},
49-
{
50-
"when": { "south": "true" },
51-
"apply": { "model": "minecraft:wall_side", "y": 180, "uvlock": true }
52-
},
53-
{
54-
"when": { "west": "true" },
55-
"apply": { "model": "minecraft:wall_side", "y": 270, "uvlock": true }
83+
"variant": {
84+
"cobblestone": {},
85+
"mossy_cobblestone": {}
5686
}
57-
]
87+
}
5888
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"__comment": "Dummy for TESRS that still want to set their block break particle without using code",
3+
"elements": [
4+
{
5+
"from": [0, 0, 0],
6+
"to": [0, 0, 0],
7+
"faces": {
8+
"up": { "uv": [ 0, 0, 0, 0 ], "texture": "#texture" }
9+
}
10+
}
11+
]
12+
}

0 commit comments

Comments
 (0)