Skip to content

Commit

Permalink
Finish 37-render-fibre-wire
Browse files Browse the repository at this point in the history
* refs/heads/feature/37-render-fibre-wire:
  register, stuff, it works, who cares. @LordFokas. Tanks for le kode. FIxes #37
  that's never used
  go away comment
  -.- @LordFokas, why did you not see that? :( I feel stupid
  work?
  Fiber not tube
  moar wark
  a lawt of work
  • Loading branch information
hunterboerner committed Nov 9, 2013
2 parents d5e90c4 + eacfd73 commit 93d1020
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 7 deletions.
91 changes: 89 additions & 2 deletions qc_common/quantumcraft/blocks/BlockQuantumFiberWire.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package quantumcraft.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import quantumcraft.blocks.abstractblocks.BlockEnergyComponent;
import quantumcraft.net.IQEnergyComponent;
import quantumcraft.render.RenderFiberWire;
import quantumcraft.util.BasicUtils;

public class BlockQuantumFiberWire extends BlockEnergyComponent {
public static Icon iconTexture;

public BlockQuantumFiberWire(int id) {
super(id, Material.circuits);
}
Expand All @@ -16,9 +25,87 @@ public TileEntity createNewTileEntity(World world) {
return null;
}

@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
float[] min = {0.25F, 0.25F, 0.25F};
float[] max = {0.75F, 0.75F, 0.75F};
if (Block.blocksList[world.getBlockId(x - 1, y, z)] instanceof IQEnergyComponent) {
if (((IQEnergyComponent) BasicUtils.getBlockInstance(world, x - 1, y, z))
.canFiberConnectOnSide(world, x - 1, y, z, BasicUtils.dirXPos))
min[0] = 0.0F;
}
if (Block.blocksList[world.getBlockId(x + 1, y, z)] instanceof IQEnergyComponent) {
if (((IQEnergyComponent) BasicUtils.getBlockInstance(world, x + 1, y, z))
.canFiberConnectOnSide(world, x + 1, y, z, BasicUtils.dirXNeg))
max[0] = 1.0F;
}
if (Block.blocksList[world.getBlockId(x, y - 1, z)] instanceof IQEnergyComponent) {
if (((IQEnergyComponent) BasicUtils.getBlockInstance(world, x, y - 1, z))
.canFiberConnectOnSide(world, x, y - 1, z, BasicUtils.dirYPos))
min[1] = 0.0F;
}
if (Block.blocksList[world.getBlockId(x, y + 1, z)] instanceof IQEnergyComponent) {
if (((IQEnergyComponent) BasicUtils.getBlockInstance(world, x, y + 1, z))
.canFiberConnectOnSide(world, x, y + 1, z, BasicUtils.dirYNeg))
max[1] = 1.0F;
}
if (Block.blocksList[world.getBlockId(x, y, z - 1)] instanceof IQEnergyComponent) {
if (((IQEnergyComponent) BasicUtils.getBlockInstance(world, x, y, z - 1))
.canFiberConnectOnSide(world, x, y, z - 1, BasicUtils.dirZPos))
min[2] = 0.0F;
}
if (Block.blocksList[world.getBlockId(x, y, z + 1)] instanceof IQEnergyComponent) {
if (((IQEnergyComponent) BasicUtils.getBlockInstance(world, x, y, z + 1))
.canFiberConnectOnSide(world, x, y, z + 1, BasicUtils.dirZNeg))
max[2] = 1.0F;
}
this.setBlockBounds(min[0], min[1], min[2], max[0], max[1], max[2]);
}

@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World w, int x, int y, int z) {
this.setBlockBoundsBasedOnState(w, x, y, z);
return AxisAlignedBB.getAABBPool()
.getAABB((double) x + this.minX, (double) y + this.minY, (double) z + this.minZ, (double) x + this.maxX,
(double) y + this.maxY, (double) z + this.maxZ);
}

@Override
public boolean isOpaqueCube() {
return false;
}

@Override
public boolean renderAsNormalBlock() {
return false;
}

@Override
public Icon getIcon(int side, int meta) {
return iconTexture;
}

@Override
public Icon getBlockTexture(IBlockAccess iblockaccess, int x, int y, int z,
int side) {
return iconTexture;
}

@Override
public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) {
return true;
}

@Override
public int getRenderType() {
return RenderFiberWire.instance().getRenderId();
}

@Override
public void registerIcons(IconRegister iconRegister) {
iconFront = iconTop = iconTopR =
iconSide = iconBottom = iconBack = iconRegister.registerIcon("QuantumCraft:FibreWireFullBlock");
iconFront =
iconTexture =
iconSide = iconBack =
iconTop = iconBottom = iconRegister.registerIcon("QuantumCraft:FibreWireFullBlock");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import quantumcraft.net.IQEnergyComponent;
import quantumcraft.net.Location;
Expand Down Expand Up @@ -42,4 +43,9 @@ public Location[] getallsides(Location l) {
public Location[] getPossibleConnections(World w, Location l) {
return getallsides(l);
}

@Override
public boolean canFiberConnectOnSide(IBlockAccess w, int x, int y, int z, int side) {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer e
return true;
}

public Icon getIconFromSide(int side) {
return getIconFromSide(side, false);
}

protected Icon iconFront;
protected Icon iconSide;
protected Icon iconBack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public void onBlockPlacedBy(World world, int x, int y, int z,
return;
}
TileEntity te = world.getBlockTileEntity(x, y, z);
//WTF? -sammko
if (stack.getTagCompound() != null) {
stack.getTagCompound().setInteger("x", x);
stack.getTagCompound().setInteger("y", y);
Expand Down
2 changes: 2 additions & 0 deletions qc_common/quantumcraft/core/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import quantumcraft.items.tools.ItemQuantumPick;
import quantumcraft.items.tools.ItemQuantumShovel;
import quantumcraft.items.tools.ItemQuantumSword;
import quantumcraft.render.RenderFiberWire;
import quantumcraft.render.RenderOre;
import quantumcraft.tile.*;

Expand Down Expand Up @@ -250,6 +251,7 @@ public static void initBlocks() {

public static void initRenderers() {
RenderingRegistry.registerBlockHandler(RenderOre.instance().getRenderId(), RenderOre.instance());
RenderingRegistry.registerBlockHandler(RenderFiberWire.instance().getRenderId(), RenderFiberWire.instance());
}

public static void initWGen() {
Expand Down
3 changes: 3 additions & 0 deletions qc_common/quantumcraft/net/IQEnergyComponent.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package quantumcraft.net;

import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public interface IQEnergyComponent {
public Location[] getPossibleConnections(World w, Location l);

public boolean canFiberConnectOnSide(IBlockAccess w, int x, int y, int z, int side);
}
111 changes: 111 additions & 0 deletions qc_common/quantumcraft/render/RenderFiberWire.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package quantumcraft.render;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import quantumcraft.blocks.BlockQuantumFiberWire;
import quantumcraft.net.IQEnergyComponent;
import quantumcraft.util.BasicUtils;

public class RenderFiberWire extends BaseBlockRenderer {

private static RenderFiberWire INSTANCE = new RenderFiberWire();

public static RenderFiberWire instance(){
return INSTANCE;
}

@Override
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer){
float min = 0.5F - 0.1875F;
float max = 0.5F + 0.1875F;
block.setBlockBounds(min, 0.0F, min, max, 1.0F, max);
renderer.setRenderBoundsFromBlock(block);
renderAsItem(block, renderer);
}

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId,
RenderBlocks renderer) {
float coremin = 0.5F - 0.1875F;
float coremax = 0.5F + 0.1875F;
float bordermin = 0.0F;
float bordermax = 1.0F;
int joints = 0;

if (BasicUtils.getBlockInstance(world, x - 1, y, z) instanceof IQEnergyComponent) {
if (((IQEnergyComponent) BasicUtils.getBlockInstance(world, x - 1, y, z))
.canFiberConnectOnSide(world, x - 1, y, z, BasicUtils.dirXPos)) {
block.setBlockBounds(bordermin, coremin, coremin, coremin, coremax, coremax);
renderer.setRenderBoundsFromBlock(block);
renderer.renderStandardBlockWithColorMultiplier(block, x, y, z, 1.0F, 1.0F, 1.0F);
joints++;
}
}
if (BasicUtils.getBlockInstance(world, x + 1, y, z) instanceof IQEnergyComponent) {
if (((IQEnergyComponent) BasicUtils.getBlockInstance(world, x + 1, y, z))
.canFiberConnectOnSide(world, x + 1, y, z, BasicUtils.dirXNeg)) {
block.setBlockBounds(coremax, coremin, coremin, bordermax, coremax, coremax);
renderer.setRenderBoundsFromBlock(block);
renderer.renderStandardBlockWithColorMultiplier(block, x, y, z, 1.0F, 1.0F, 1.0F);
joints++;
}
}
if (BasicUtils.getBlockInstance(world, x, y - 1, z) instanceof IQEnergyComponent) {
if (((IQEnergyComponent) BasicUtils.getBlockInstance(world, x, y - 1, z))
.canFiberConnectOnSide(world, x, y - 1, z, BasicUtils.dirYPos)) {
block.setBlockBounds(coremin, bordermin, coremin, coremax, coremin, coremax);
renderer.setRenderBoundsFromBlock(block);
renderer.renderStandardBlockWithColorMultiplier(block, x, y, z, 1.0F, 1.0F, 1.0F);
joints++;
}
}
if (BasicUtils.getBlockInstance(world, x, y + 1, z) instanceof IQEnergyComponent) {
if (((IQEnergyComponent) BasicUtils.getBlockInstance(world, x, y + 1, z))
.canFiberConnectOnSide(world, x, y + 1, z, BasicUtils.dirYNeg)) {
block.setBlockBounds(coremin, coremax, coremin, coremax, bordermax, coremax);
renderer.setRenderBoundsFromBlock(block);
renderer.renderStandardBlockWithColorMultiplier(block, x, y, z, 1.0F, 1.0F, 1.0F);
joints++;
}
}
if (BasicUtils.getBlockInstance(world, x, y, z - 1) instanceof IQEnergyComponent) {
if (((IQEnergyComponent) BasicUtils.getBlockInstance(world, x, y, z - 1))
.canFiberConnectOnSide(world, x, y, z - 1, BasicUtils.dirZPos)) {
block.setBlockBounds(coremin, coremin, bordermin, coremax, coremax, coremin);
renderer.setRenderBoundsFromBlock(block);
renderer.renderStandardBlockWithColorMultiplier(block, x, y, z, 1.0F, 1.0F, 1.0F);
joints++;
}
}
if (BasicUtils.getBlockInstance(world, x, y, z + 1) instanceof IQEnergyComponent) {
if (((IQEnergyComponent) BasicUtils.getBlockInstance(world, x, y, z + 1))
.canFiberConnectOnSide(world, x, y, z + 1, BasicUtils.dirZNeg)) {
block.setBlockBounds(coremin, coremin, coremax, coremax, coremax, bordermax);
renderer.setRenderBoundsFromBlock(block);
renderer.renderStandardBlockWithColorMultiplier(block, x, y, z, 1.0F, 1.0F, 1.0F);
joints++;
}
}
if (joints > 2) {
Icon joint = BlockQuantumFiberWire.iconTexture;
coremin -= 0.0625F;
coremax += 0.0625F;
block.setBlockBounds(coremin, coremin, coremin, coremax, coremax, coremax);
renderer.setRenderBoundsFromBlock(block);
renderer.renderFaceXNeg(block, x, y, z, joint);
renderer.renderFaceXPos(block, x, y, z, joint);
renderer.renderFaceZNeg(block, x, y, z, joint);
renderer.renderFaceZPos(block, x, y, z, joint);
renderer.renderFaceYNeg(block, x, y, z, joint);
renderer.renderFaceYPos(block, x, y, z, joint);
} else {
block.setBlockBounds(coremin, coremin, coremin, coremax, coremax, coremax);
renderer.setRenderBoundsFromBlock(block);
renderer.renderStandardBlockWithColorMultiplier(block, x, y, z, 1.0F, 1.0F, 1.0F);
}
block.setBlockBoundsBasedOnState(world, x, y, z);
return true;
}
}
18 changes: 18 additions & 0 deletions qc_common/quantumcraft/util/BasicUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,26 @@

public class BasicUtils {

// Cardinal Orientation
public static final int dirBottom = 0;
public static final int dirTop = 1;
public static final int dirEast = 2;
public static final int dirWest = 3;
public static final int dirNorth = 4;
public static final int dirSouth = 5;
// Axial Orientation
public static final int dirYNeg = 0;
public static final int dirYPos = 1;
public static final int dirZNeg = 2;
public static final int dirZPos = 3;
public static final int dirXNeg = 4;
public static final int dirXPos = 5;
public static Random rand = new Random();

public static Block getBlockInstance(IBlockAccess world, int x, int y, int z) {
return Block.blocksList[world.getBlockId(x, y, z)];
}

public static int overclockMultiplier(int[] uids) {
int res = 0;
for (int u : uids) {
Expand Down

0 comments on commit 93d1020

Please sign in to comment.