Added Farm inventory cable

This commit is contained in:
modmuss50 2015-07-14 17:18:00 +01:00
parent b6807d249d
commit 29398d50dd
4 changed files with 360 additions and 3 deletions

View file

@ -0,0 +1,105 @@
package techreborn.client.render;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.init.Blocks;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
import techreborn.lib.Functions;
import techreborn.lib.vecmath.Vecs3d;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.parts.FarmInventoryCable;
import java.util.ArrayList;
public class RenderFarmInventoryCable {
public static void renderBox(Vecs3dCube cube, Block block, Tessellator tessellator, RenderBlocks renderblocks, IIcon texture, Double xD, Double yD, double zD, float thickness) {
block.setBlockBounds((float) cube.getMinX(), (float) cube.getMinY(), (float) cube.getMinZ(), (float) cube.getMaxX() + thickness, (float) cube.getMaxY() + thickness, (float) cube.getMaxZ() + thickness);
renderblocks.setRenderBoundsFromBlock(block);
tessellator.setColorOpaque_F(0.5F, 0.5F, 0.5F);
renderblocks.renderFaceYNeg(block, xD, yD, zD, texture);
tessellator.setColorOpaque_F(1.0F, 1.0F, 1.0F);
renderblocks.renderFaceYPos(block, xD, yD, zD, texture);
tessellator.setColorOpaque_F(0.8F, 0.8F, 0.8F);
renderblocks.renderFaceZNeg(block, xD, yD, zD, texture);
renderblocks.renderFaceZPos(block, xD, yD, zD, texture);
tessellator.setColorOpaque_F(0.6F, 0.6F, 0.6F);
renderblocks.renderFaceXNeg(block, xD, yD, zD, texture);
renderblocks.renderFaceXPos(block, xD, yD, zD, texture);
}
@SideOnly(Side.CLIENT)
public static boolean renderStatic(Vecs3d translation, int pass, FarmInventoryCable part) {
Tessellator tessellator = Tessellator.instance;
IIcon stone = Blocks.stone.getIcon(0, 0);
IIcon redstone = Blocks.redstone_block.getIcon(0, 0);
IIcon quartz = Blocks.quartz_block.getIcon(0, 0);
RenderBlocks renderblocks = RenderBlocks.getInstance();
double xD = part.xCoord;
double yD = part.yCoord;
double zD = part.zCoord;
Block block = part.getBlockType();
tessellator.setBrightness(block.getMixedBrightnessForBlock(part.getWorld(), part.getX(), part.getY(), part.getZ()));
Vecs3dCube cube = new Vecs3dCube(part.boundingBoxes[6].getMinX() + 0.1, part.boundingBoxes[6].getMinY() + 0.1,part.boundingBoxes[6].getMinZ() + 0.1,part.boundingBoxes[6].getMaxX() - 0.1, part.boundingBoxes[6].getMaxY() - 0.1,part.boundingBoxes[6].getMaxZ() - 0.1);
renderBox(cube, block, tessellator, renderblocks, stone, xD, yD, zD, 0F);
ArrayList<Vecs3dCube> cubes = new ArrayList<Vecs3dCube>();
cube = new Vecs3dCube(0.15, 0.15,0.15, 0.3, 0.3,0.85);
cubes.add(cube);
cube = new Vecs3dCube(0.15, 0.15,0.15, 0.85, 0.3,0.3);
cubes.add(cube);
cube = new Vecs3dCube(0.15, 0.15,0.15, 0.3, 0.85,0.3);
renderBox(cube, block, tessellator, renderblocks, redstone, xD, yD, zD, 0F);
cube = new Vecs3dCube(0.85, 0.85,0.85, 0.7, 0.15,0.7);
cubes.add(cube);
cube = new Vecs3dCube(0.85, 0.85,0.85, 0.7, 0.7,0.15);
cubes.add(cube);
cube = new Vecs3dCube(0.85, 0.85,0.85, 0.15, 0.7,0.7);
cubes.add(cube);
cube = new Vecs3dCube(0.15, 0.85,0.85, 0.3, 0.15,0.7);
cubes.add(cube);
cube = new Vecs3dCube(0.85, 0.85,0.15, 0.7, 0.15,0.3);
cubes.add(cube);
cube = new Vecs3dCube(0.85, 0.15,0.85, 0.7, 0.3,0.15);
cubes.add(cube);
cube = new Vecs3dCube(0.85, 0.15,0.85, 0.15, 0.3,0.7);
cubes.add(cube);
cube = new Vecs3dCube(0.15, 0.85,0.15, 0.85, 0.7,0.3);
cubes.add(cube);
cube = new Vecs3dCube(0.15, 0.85,0.15, 0.3, 0.7,0.85);
cubes.add(cube);
for(Vecs3dCube vecs3dCube : cubes){
renderBox(vecs3dCube, block, tessellator, renderblocks, redstone, xD, yD, zD, 0f);
}
for (ForgeDirection direction : ForgeDirection.values()) {
if (part.connectedSides.get(direction) != null) {
renderBox(part.boundingBoxes[Functions.getIntDirFromDirection(direction)], block, tessellator, renderblocks, quartz, xD, yD, zD, 0f);
}
}
block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
renderblocks.setRenderBoundsFromBlock(block);
return true;
}
}

View file

@ -4,6 +4,7 @@ import net.minecraft.item.ItemStack;
import techreborn.partSystem.IPartProvider;
import techreborn.partSystem.ModPartRegistry;
import techreborn.partSystem.parts.CablePart;
import techreborn.partSystem.parts.FarmInventoryCable;
import java.util.HashMap;
@ -18,9 +19,10 @@ public class ModParts {
part.setType(i);
ModPartRegistry.registerPart(part);
}
//ModPartRegistry.addProvider("techreborn.partSystem.QLib.QModPartFactory", "qmunitylib");
ModPartRegistry.registerPart(new FarmInventoryCable());
ModPartRegistry.addProvider("techreborn.partSystem.fmp.FMPFactory",
"ForgeMultipart");
ModPartRegistry.addProvider("techreborn.partSystem.QLib.QModPartFactory", "qmunitylib");
ModPartRegistry.addAllPartsToSystems();
for(IPartProvider provider : ModPartRegistry.providers){
if(provider.modID().equals("ForgeMultipart")){

View file

@ -43,7 +43,7 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
public ItemStack stack;
private boolean hasCheckedSinceStartup;
public int type = 0;//TODO save this to nbt and not use the constructor.
public int type = 0;
public CablePart() {
connectedSides = new HashMap<ForgeDirection, TileEntity>();
@ -160,7 +160,7 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
nearByChange();
}
if (worldObj != null) {
if (worldObj.getTotalWorldTime() % 40 == 0 || hasCheckedSinceStartup == false) {
if (worldObj.getTotalWorldTime() % 40 == 0 || !hasCheckedSinceStartup) {
checkConnectedSides();
hasCheckedSinceStartup = true;
}

View file

@ -0,0 +1,250 @@
package techreborn.partSystem.parts;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ic2.api.energy.tile.IEnergyTile;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import techreborn.client.render.RenderFarmInventoryCable;
import techreborn.lib.Functions;
import techreborn.lib.vecmath.Vecs3d;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class FarmInventoryCable extends ModPart implements IPartDesc {
public Vecs3dCube[] boundingBoxes = new Vecs3dCube[14];
public float center = 0.6F;
public float offset = 0.10F;
public Map<ForgeDirection, TileEntity> connectedSides;
public int ticks = 0;
public ItemStack stack;
protected ForgeDirection[] dirs = ForgeDirection.values();
private boolean[] connections = new boolean[6];
private boolean hasCheckedSinceStartup;
public FarmInventoryCable() {
connectedSides = new HashMap<ForgeDirection, TileEntity>();
refreshBounding();
}
public void refreshBounding() {
float centerFirst = center - offset;
double w = 0.7F / 2;
boundingBoxes[6] = new Vecs3dCube(centerFirst - w, centerFirst - w,
centerFirst - w, centerFirst + w, centerFirst + w, centerFirst
+ w);
w = 0.4F /2;
int i = 0;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
double xMin1 = (dir.offsetX < 0 ? 0.0
: (dir.offsetX == 0 ? centerFirst - w : centerFirst + w));
double xMax1 = (dir.offsetX > 0 ? 1.0
: (dir.offsetX == 0 ? centerFirst + w : centerFirst - w));
double yMin1 = (dir.offsetY < 0 ? 0.0
: (dir.offsetY == 0 ? centerFirst - w : centerFirst + w));
double yMax1 = (dir.offsetY > 0 ? 1.0
: (dir.offsetY == 0 ? centerFirst + w : centerFirst - w));
double zMin1 = (dir.offsetZ < 0 ? 0.0
: (dir.offsetZ == 0 ? centerFirst - w : centerFirst + w));
double zMax1 = (dir.offsetZ > 0 ? 1.0
: (dir.offsetZ == 0 ? centerFirst + w : centerFirst - w));
boundingBoxes[i] = new Vecs3dCube(xMin1, yMin1, zMin1, xMax1,
yMax1, zMax1);
i++;
}
}
@Override
public void addCollisionBoxesToList(List<Vecs3dCube> boxes, Entity entity) {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (connectedSides.containsKey(dir))
boxes.add(boundingBoxes[Functions.getIntDirFromDirection(dir)]);
}
boxes.add(boundingBoxes[6]);
}
@Override
public List<Vecs3dCube> getSelectionBoxes() {
List<Vecs3dCube> vec3dCubeList = new ArrayList<Vecs3dCube>();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (connectedSides.containsKey(dir))
vec3dCubeList.add(boundingBoxes[Functions
.getIntDirFromDirection(dir)]);
}
vec3dCubeList.add(boundingBoxes[6]);
return vec3dCubeList;
}
@Override
public List<Vecs3dCube> getOcclusionBoxes() {
List<Vecs3dCube> vecs3dCubesList = new ArrayList<Vecs3dCube>();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (connectedSides.containsKey(dir))
vecs3dCubesList.add(boundingBoxes[Functions
.getIntDirFromDirection(dir)]);
}
return vecs3dCubesList;
}
@Override
public void renderDynamic(Vecs3d translation, double delta) {
}
@Override
public boolean renderStatic(Vecs3d translation, int pass) {
return RenderFarmInventoryCable.renderStatic(translation, pass, this);
}
@Override
public void writeToNBT(NBTTagCompound tag) {
writeConnectedSidesToNBT(tag);
}
@Override
public void readFromNBT(NBTTagCompound tag) {
}
@Override
public String getName() {
return "FarmInventoryCable";
}
@SideOnly(Side.CLIENT)
@Override
public String getItemTextureName() {
return "";
}
@Override
public void tick() {
if (worldObj != null) {
if (worldObj.getTotalWorldTime() % 40 == 0 || hasCheckedSinceStartup == false) {
checkConnectedSides();
hasCheckedSinceStartup = true;
}
}
}
@Override
public void nearByChange() {
checkConnectedSides();
}
@Override
public void onAdded() {
checkConnections(world, getX(), getY(), getZ());
checkConnectedSides();
}
@Override
public void onRemoved() {
}
@Override
public IModPart copy() {
FarmInventoryCable part = new FarmInventoryCable();
return part;
}
@Override
public ItemStack getItem() {
return new ItemStack(ModPartRegistry.getItem(getName()));
}
public boolean shouldConnectTo(TileEntity entity, ForgeDirection dir) {
if (entity == null) {
return false;
} else if (entity instanceof IEnergyTile) {
return true;
} else {
return ModPartUtils.hasPart(entity.getWorldObj(), entity.xCoord,
entity.yCoord, entity.zCoord, this.getName());
}
}
public void checkConnectedSides() {
refreshBounding();
connectedSides = new HashMap<ForgeDirection, TileEntity>();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
int d = Functions.getIntDirFromDirection(dir);
if (world == null) {
return;
}
TileEntity te = world.getTileEntity(getX() + dir.offsetX, getY()
+ dir.offsetY, getZ() + dir.offsetZ);
if (shouldConnectTo(te, dir)) {
if (ModPartUtils.checkOcclusion(getWorld(), getX(),
getY(), getZ(), boundingBoxes[d])) {
connectedSides.put(dir, te);
}
}
if (te != null) {
te.getWorldObj().markBlockForUpdate(te.xCoord, te.yCoord, te.zCoord);
}
}
checkConnections(world, getX(), getY(), getZ());
getWorld().markBlockForUpdate(getX(), getY(), getZ());
}
public void checkConnections(World world, int x, int y, int z) {
for (int i = 0; i < 6; i++) {
ForgeDirection dir = dirs[i];
int dx = x + dir.offsetX;
int dy = y + dir.offsetY;
int dz = z + dir.offsetZ;
connections[i] = shouldConnectTo(world.getTileEntity(dx, dy, dz),
dir);
world.func_147479_m(dx, dy, dz);
}
world.func_147479_m(x, y, z);
}
private void readConnectedSidesFromNBT(NBTTagCompound tagCompound) {
NBTTagCompound ourCompound = tagCompound.getCompoundTag("connectedSides");
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
connections[dir.ordinal()] = ourCompound.getBoolean(dir.ordinal() + "");
}
checkConnectedSides();
}
private void writeConnectedSidesToNBT(NBTTagCompound tagCompound) {
NBTTagCompound ourCompound = new NBTTagCompound();
int i = 0;
for (boolean b : connections) {
ourCompound.setBoolean(i + "", b);
i++;
}
tagCompound.setTag("connectedSides", ourCompound);
}
@Override
public void readDesc(NBTTagCompound tagCompound) {
readConnectedSidesFromNBT(tagCompound);
}
@Override
public void writeDesc(NBTTagCompound tagCompound) {
writeConnectedSidesToNBT(tagCompound);
}
}