Cable work.

This commit is contained in:
Raoul Van den Berge
2016-03-19 16:16:22 +01:00
parent 4d7aa2d93a
commit ce3b7207d7
14 changed files with 354 additions and 183 deletions

View File

@@ -1,13 +1,24 @@
package storagecraft.block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import storagecraft.tile.TileCable;
public class BlockCable extends BlockBase
{
public static final PropertyBool NORTH = PropertyBool.create("north");
public static final PropertyBool EAST = PropertyBool.create("east");
public static final PropertyBool SOUTH = PropertyBool.create("south");
public static final PropertyBool WEST = PropertyBool.create("west");
public static final PropertyBool UP = PropertyBool.create("up");
public static final PropertyBool DOWN = PropertyBool.create("down");
public BlockCable()
{
super("cable");
@@ -16,6 +27,33 @@ public class BlockCable extends BlockBase
// @TODO: setBlockBounds(4 * pixel, 4 * pixel, 4 * pixel, 1 - 4 * pixel, 1 - 4 * pixel, 1 - 4 * pixel);
}
@Override
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[]
{
DIRECTION,
NORTH,
EAST,
SOUTH,
WEST,
UP,
DOWN,
});
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
{
return super.getActualState(state, world, pos)
.withProperty(NORTH, TileCable.isCable(world, pos.north()))
.withProperty(EAST, TileCable.isCable(world, pos.east()))
.withProperty(SOUTH, TileCable.isCable(world, pos.south()))
.withProperty(WEST, TileCable.isCable(world, pos.west()))
.withProperty(UP, TileCable.isCable(world, pos.up()))
.withProperty(DOWN, TileCable.isCable(world, pos.down()));
}
@Override
public boolean hasTileEntity(IBlockState state)
{
@@ -27,34 +65,4 @@ public class BlockCable extends BlockBase
{
return new TileCable();
}
@Override
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
}
@Override
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
@Override
public boolean isFullCube(IBlockState state)
{
return false;
}
@Override
public boolean isNormalCube(IBlockState state)
{
return false;
}
@Override
public boolean isVisuallyOpaque()
{
return false;
}
}

View File

@@ -7,10 +7,7 @@ import net.minecraft.client.renderer.block.statemap.StateMap;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import storagecraft.StorageCraftBlocks;
import storagecraft.StorageCraftItems;
@@ -18,8 +15,6 @@ import storagecraft.block.EnumControllerType;
import storagecraft.block.EnumGridType;
import storagecraft.block.EnumStorageType;
import storagecraft.item.*;
import storagecraft.render.BlockCableRenderer;
import storagecraft.tile.TileCable;
public class ClientProxy extends CommonProxy
{
@@ -28,11 +23,6 @@ public class ClientProxy extends CommonProxy
{
super.preInit(e);
// TESRs
ForgeHooksClient.registerTESRItemStack(Item.getItemFromBlock(StorageCraftBlocks.CABLE), 0, TileCable.class);
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(StorageCraftBlocks.CABLE), 0, new ModelResourceLocation("storagecraft:cable", "inventory"));
// Item Variants
ModelBakery.registerItemVariants(StorageCraftItems.STORAGE_CELL,
new ResourceLocation("storagecraft:1k_storage_cell"),
@@ -136,6 +126,7 @@ public class ClientProxy extends CommonProxy
});
// Blocks
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(StorageCraftBlocks.CABLE), 0, new ModelResourceLocation("storagecraft:cable", "inventory"));
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(StorageCraftBlocks.GRID), EnumGridType.NORMAL.getId(), new ModelResourceLocation("storagecraft:grid", "inventory"));
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(StorageCraftBlocks.GRID), EnumGridType.CRAFTING.getId(), new ModelResourceLocation("storagecraft:grid", "inventory"));
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(StorageCraftBlocks.GRID), EnumGridType.PATTERN.getId(), new ModelResourceLocation("storagecraft:grid", "inventory"));
@@ -164,12 +155,4 @@ public class ClientProxy extends CommonProxy
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(StorageCraftBlocks.STORAGE), EnumStorageType.TYPE_64K.getId(), new ModelResourceLocation("storagecraft:storage", "type=64k"));
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(StorageCraftBlocks.STORAGE), EnumStorageType.TYPE_CREATIVE.getId(), new ModelResourceLocation("storagecraft:storage", "type=creative"));
}
@Override
public void init(FMLInitializationEvent e)
{
super.init(e);
ClientRegistry.bindTileEntitySpecialRenderer(TileCable.class, BlockCableRenderer.INSTANCE);
}
}

View File

@@ -1,29 +0,0 @@
package storagecraft.render;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import org.lwjgl.opengl.GL11;
import storagecraft.render.model.CableModel;
import storagecraft.tile.TileCable;
public class BlockCableRenderer extends TileEntitySpecialRenderer<TileCable>
{
public static final BlockCableRenderer INSTANCE = new BlockCableRenderer(new CableModel());
private CableModel model;
public BlockCableRenderer(CableModel model)
{
this.model = model;
}
@Override
public void renderTileEntityAt(TileCable tile, double x, double y, double z, float scale, int a)
{
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
model.render(tile);
GL11.glPopMatrix();
}
}

View File

@@ -1,100 +0,0 @@
package storagecraft.render.model;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import storagecraft.tile.TileCable;
public class CableModel extends ModelBase
{
public static final ResourceLocation CABLE_RESOURCE = new ResourceLocation("storagecraft:textures/blocks/cable.png");
private ModelRenderer core;
private ModelRenderer up;
private ModelRenderer down;
private ModelRenderer north;
private ModelRenderer east;
private ModelRenderer south;
private ModelRenderer west;
public CableModel()
{
core = new ModelRenderer(this, 0, 0);
core.addBox(6F, 6F, 6F, 4, 4, 4);
core.setTextureSize(16, 16);
up = new ModelRenderer(this, 0, 0);
up.addBox(6F, 10F, 6F, 4, 6, 4);
up.setTextureSize(16, 16);
down = new ModelRenderer(this, 0, 0);
down.addBox(6F, 0F, 6F, 4, 6, 4);
down.setTextureSize(16, 16);
north = new ModelRenderer(this, 0, 0);
north.addBox(6F, 6F, 0F, 4, 4, 6);
north.setTextureSize(16, 16);
east = new ModelRenderer(this, 0, 0);
east.addBox(10F, 6F, 6F, 6, 4, 4);
east.setTextureSize(16, 16);
south = new ModelRenderer(this, 0, 0);
south.addBox(6F, 6F, 10F, 4, 4, 6);
south.setTextureSize(16, 16);
west = new ModelRenderer(this, 0, 0);
west.addBox(0F, 6F, 6F, 6, 4, 4);
west.setTextureSize(16, 16);
}
public void render(TileEntity tile)
{
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_RESOURCE);
core.render(0.0625F);
if (tile != null)
{
TileCable cable = (TileCable) tile;
if (cable.hasConnection(EnumFacing.UP))
{
up.render(0.0625F);
}
if (cable.hasConnection(EnumFacing.DOWN))
{
down.render(0.0625F);
}
if (cable.hasConnection(EnumFacing.NORTH))
{
north.render(0.0625F);
}
if (cable.hasConnection(EnumFacing.EAST))
{
east.render(0.0625F);
}
if (cable.hasConnection(EnumFacing.SOUTH))
{
south.render(0.0625F);
}
if (cable.hasConnection(EnumFacing.WEST))
{
west.render(0.0625F);
}
}
else
{
east.render(0.0625F);
west.render(0.0625F);
}
}
}

View File

@@ -4,12 +4,12 @@ import java.util.List;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.IBlockAccess;
import storagecraft.block.BlockCable;
public class TileCable extends TileBase
{
public static boolean isCable(World world, BlockPos pos)
public static boolean isCable(IBlockAccess world, BlockPos pos)
{
return world.getBlockState(pos).getBlock() instanceof BlockCable;
}

View File

@@ -0,0 +1,67 @@
{
"forge_marker": 1,
"defaults": {
"textures": {
"all": "storagecraft:blocks/cable"
},
"model": "storagecraft:cable_core"
},
"variants": {
"north": {
"true": {
"submodel": "storagecraft:cable_north"
},
"false": {
}
},
"east": {
"true": {
"submodel": "storagecraft:cable_east"
},
"false": {
}
},
"south": {
"true": {
"submodel": "storagecraft:cable_south"
},
"false": {
}
},
"west": {
"true": {
"submodel": "storagecraft:cable_west"
},
"false": {
}
},
"up": {
"true": {
"submodel": "storagecraft:cable_up"
},
"false": {
}
},
"down": {
"true": {
"submodel": "storagecraft:cable_down"
},
"false": {
}
},
"direction": {
"north": {
},
"east": {
},
"south": {
},
"west": {
},
"up": {
},
"down": {
}
}
}
}

View File

@@ -0,0 +1,35 @@
{
"elements": [
{
"__comment": "core",
"from": [-2, 14, 14],
"to": [2, 18, 18],
"faces": {
"down": {
"uv": [12, 0, 8, 4],
"texture": "#all"
},
"up": {
"uv": [8, 4, 4, 0],
"texture": "#all"
},
"north": {
"uv": [4, 4, 8, 8],
"texture": "#all"
},
"south": {
"uv": [12, 4, 16, 8],
"texture": "#all"
},
"west": {
"uv": [8, 4, 12, 8],
"texture": "#all"
},
"east": {
"uv": [0, 4, 4, 8],
"texture": "#all"
}
}
}
]
}

View File

@@ -0,0 +1,35 @@
{
"elements": [
{
"__comment": "down",
"from": [-2, 18, 14],
"to": [2, 24, 18],
"faces": {
"down": {
"uv": [12, 0, 8, 4],
"texture": "#all"
},
"up": {
"uv": [8, 4, 4, 0],
"texture": "#all"
},
"north": {
"uv": [4, 4, 8, 10],
"texture": "#all"
},
"south": {
"uv": [12, 4, 16, 10],
"texture": "#all"
},
"west": {
"uv": [8, 4, 12, 10],
"texture": "#all"
},
"east": {
"uv": [0, 4, 4, 10],
"texture": "#all"
}
}
}
]
}

View File

@@ -0,0 +1,35 @@
{
"elements": [
{
"__comment": "east",
"from": [-8, 14, 14],
"to": [-2, 18, 18],
"faces": {
"down": {
"uv": [16, 0, 10, 4],
"texture": "#all"
},
"up": {
"uv": [10, 4, 4, 0],
"texture": "#all"
},
"north": {
"uv": [4, 4, 10, 8],
"texture": "#all"
},
"south": {
"uv": [14, 4, 20, 8],
"texture": "#all"
},
"west": {
"uv": [10, 4, 14, 8],
"texture": "#all"
},
"east": {
"uv": [0, 4, 4, 8],
"texture": "#all"
}
}
}
]
}

View File

@@ -0,0 +1,35 @@
{
"elements": [
{
"__comment": "north",
"from": [-2, 14, 8],
"to": [2, 18, 14],
"faces": {
"down": {
"uv": [14, 0, 10, 6],
"texture": "#all"
},
"up": {
"uv": [10, 6, 6, 0],
"texture": "#all"
},
"north": {
"uv": [6, 6, 10, 10],
"texture": "#all"
},
"south": {
"uv": [16, 6, 20, 10],
"texture": "#all"
},
"west": {
"uv": [10, 6, 16, 10],
"texture": "#all"
},
"east": {
"uv": [0, 6, 6, 10],
"texture": "#all"
}
}
}
]
}

View File

@@ -0,0 +1,35 @@
{
"elements": [
{
"__comment": "south",
"from": [-2, 14, 18],
"to": [2, 18, 24],
"faces": {
"down": {
"uv": [14, 0, 10, 6],
"texture": "#all"
},
"up": {
"uv": [10, 6, 6, 0],
"texture": "#all"
},
"north": {
"uv": [6, 6, 10, 10],
"texture": "#all"
},
"south": {
"uv": [16, 6, 20, 10],
"texture": "#all"
},
"west": {
"uv": [10, 6, 16, 10],
"texture": "#all"
},
"east": {
"uv": [0, 6, 6, 10],
"texture": "#all"
}
}
}
]
}

View File

@@ -0,0 +1,35 @@
{
"elements": [
{
"__comment": "up",
"from": [-2, 8, 14],
"to": [2, 14, 18],
"faces": {
"down": {
"uv": [12, 0, 8, 4],
"texture": "#all"
},
"up": {
"uv": [8, 4, 4, 0],
"texture": "#all"
},
"north": {
"uv": [4, 4, 8, 10],
"texture": "#all"
},
"south": {
"uv": [12, 4, 16, 10],
"texture": "#all"
},
"west": {
"uv": [8, 4, 12, 10],
"texture": "#all"
},
"east": {
"uv": [0, 4, 4, 10],
"texture": "#all"
}
}
}
]
}

View File

@@ -0,0 +1,35 @@
{
"elements": [
{
"__comment": "west",
"from": [2, 14, 14],
"to": [8, 18, 18],
"faces": {
"down": {
"uv": [16, 0, 10, 4],
"texture": "#all"
},
"up": {
"uv": [10, 4, 4, 0],
"texture": "#all"
},
"north": {
"uv": [4, 4, 10, 8],
"texture": "#all"
},
"south": {
"uv": [14, 4, 20, 8],
"texture": "#all"
},
"west": {
"uv": [10, 4, 14, 8],
"texture": "#all"
},
"east": {
"uv": [0, 4, 4, 8],
"texture": "#all"
}
}
}
]
}

View File

@@ -1,3 +0,0 @@
{
"parent": "builtin/entity"
}