textures for the controller + basic code for directional blocks
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
package storagecraft.block;
|
||||
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import storagecraft.SC;
|
||||
import storagecraft.tile.TileController;
|
||||
|
||||
public class BlockController extends BlockSC implements ITileEntityProvider {
|
||||
private IIcon sideIcon;
|
||||
private IIcon[] icons = new IIcon[6];
|
||||
|
||||
public BlockController() {
|
||||
super("controller");
|
||||
}
|
||||
@@ -32,4 +38,33 @@ public class BlockController extends BlockSC implements ITileEntityProvider {
|
||||
|
||||
super.onBlockPreDestroy(world, x, y, z, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBlockIcons(IIconRegister register) {
|
||||
for (int i = 0; i <= 5; ++i) {
|
||||
icons[i] = register.registerIcon("storagecraft:controller" + i);
|
||||
}
|
||||
|
||||
sideIcon = register.registerIcon("storagecraft:generic");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
|
||||
if (side == 0 || side == 1) {
|
||||
return sideIcon;
|
||||
}
|
||||
|
||||
TileController controller = (TileController) world.getTileEntity(x, y, z);
|
||||
|
||||
return icons[(int) ((float) controller.getEnergyStored(null) / (float) controller.getMaxEnergyStored(null) * 5f)];
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(int side, int meta) {
|
||||
if (side == 0 || side == 1) {
|
||||
return sideIcon;
|
||||
}
|
||||
|
||||
return icons[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
package storagecraft.block;
|
||||
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import storagecraft.tile.TileGrid;
|
||||
import storagecraft.tile.TileSC;
|
||||
|
||||
public class BlockGrid extends BlockSC implements ITileEntityProvider {
|
||||
private IIcon sideIcon;
|
||||
private IIcon icon;
|
||||
|
||||
public BlockGrid() {
|
||||
super("grid");
|
||||
}
|
||||
@@ -14,4 +21,30 @@ public class BlockGrid extends BlockSC implements ITileEntityProvider {
|
||||
public TileEntity createNewTileEntity(World world, int meta) {
|
||||
return new TileGrid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBlockIcons(IIconRegister register) {
|
||||
icon = register.registerIcon("storagecraft:grid");
|
||||
sideIcon = register.registerIcon("storagecraft:generic");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
|
||||
TileSC tile = (TileSC) world.getTileEntity(x, y, z);
|
||||
|
||||
if (side == tile.getDirection().getOpposite().ordinal()) {
|
||||
return icon;
|
||||
}
|
||||
|
||||
return sideIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(int side, int meta) {
|
||||
if (side == 3) {
|
||||
return icon;
|
||||
}
|
||||
|
||||
return sideIcon;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,13 @@ package storagecraft.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import storagecraft.SC;
|
||||
import storagecraft.tile.TileSC;
|
||||
|
||||
public class BlockSC extends Block {
|
||||
private String name;
|
||||
@@ -12,11 +18,40 @@ public class BlockSC extends Block {
|
||||
|
||||
this.name = name;
|
||||
|
||||
this.setCreativeTab(SC.TAB);
|
||||
setCreativeTab(SC.TAB);
|
||||
setBlockTextureName("storagecraft:" + name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName() {
|
||||
return "block." + SC.ID + ":" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) {
|
||||
super.onBlockPlacedBy(world, x, y, z, entityLiving, itemStack);
|
||||
|
||||
if (world.getTileEntity(x, y, z) instanceof TileSC) {
|
||||
ForgeDirection direction = ForgeDirection.UNKNOWN;
|
||||
|
||||
int facing = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
|
||||
|
||||
switch (facing) {
|
||||
case 0:
|
||||
direction = ForgeDirection.SOUTH;
|
||||
break;
|
||||
case 1:
|
||||
direction = ForgeDirection.WEST;
|
||||
break;
|
||||
case 2:
|
||||
direction = ForgeDirection.NORTH;
|
||||
break;
|
||||
case 3:
|
||||
direction = ForgeDirection.EAST;
|
||||
break;
|
||||
}
|
||||
|
||||
((TileSC) world.getTileEntity(x, y, z)).setDirection(direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user