textures for the controller + basic code for directional blocks

This commit is contained in:
Raoul Van den Berge
2015-12-10 00:47:40 +01:00
parent b9c91141f7
commit 330b68fb3a
16 changed files with 150 additions and 2 deletions

View File

@@ -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];
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}
}

View File

@@ -34,7 +34,7 @@ public class GuiController extends GuiContainer {
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
int barWidth = 16;
int barHeight = 59;
int barHeight = 58;
int barX = x + 17;
int barY = y + 25;

View File

@@ -61,6 +61,8 @@ public class TileController extends TileSC implements IEnergyHandler, INetworkTi
}
storage.extractEnergy(energyUsage, false);
} else {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}

View File

@@ -1,13 +1,20 @@
package storagecraft.tile;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import storagecraft.SC;
import storagecraft.network.MessageTileUpdate;
public class TileSC extends TileEntity {
public static final int UPDATE_RANGE = 64;
private ForgeDirection direction;
@Override
public void updateEntity() {
super.updateEntity();
@@ -20,4 +27,40 @@ public class TileSC extends TileEntity {
}
}
}
public void setDirection(ForgeDirection direction) {
this.direction = direction;
}
public ForgeDirection getDirection() {
return direction;
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
direction = ForgeDirection.getOrientation(nbt.getInteger("Direction"));
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setInteger("Direction", direction.ordinal());
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("Direction", direction.ordinal());
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbt);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
direction = ForgeDirection.getOrientation(packet.func_148857_g().getInteger("Direction"));
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 B

After

Width:  |  Height:  |  Size: 169 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB