Merge branch 'fmp'

This commit is contained in:
modmuss50 2015-04-20 21:35:30 +01:00
commit 0aa7927e28
27 changed files with 2995 additions and 0 deletions

View file

@ -33,6 +33,14 @@ repositories {
name 'CB Repo'
url "http://chickenbones.net/maven/"
}
maven {
name = "Modmuss50"
url = "http://modmuss50.me/maven/"
}
maven {
name = "Qmunity"
url = "http://maven.bluepowermod.com/"
}
}
def ENV = System.getenv()
@ -77,6 +85,7 @@ dependencies {
compile "codechicken:ForgeMultipart:1.7.10-1.1.2.331:dev"
compile "mcp.mobius.waila:Waila:1.5.10_1.7.10:dev"
compile 'com.mod-buildcraft:buildcraft:6.4.8:dev'
compile "qmunity:QmunityLib:0.1.+:deobf"
grabDep('ThermalFoundation-[1.7.10]1.0.0-81.jar', 'http://addons-origin.cursecdn.com/files/2233/780/ThermalFoundation-[1.7.10]1.0.0-81.jar')
grabDep('CoFHCore-[1.7.10]3.0.2-262.jar', 'http://addons-origin.cursecdn.com/files/2234/198/CoFHCore-[1.7.10]3.0.2-262.jar')
grabDep('CoFHLib-[1.7.10]1.0.1-151.jar', 'http://addons-origin.cursecdn.com/files/2233/832/CoFHLib-[1.7.10]1.0.1-151.jar')

View file

@ -17,6 +17,7 @@ import techreborn.compat.recipes.RecipeManager;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
import techreborn.init.ModItems;
import techreborn.init.ModParts;
import techreborn.init.ModRecipes;
import techreborn.lib.ModInfo;
import techreborn.packets.PacketHandler;
@ -48,6 +49,8 @@ public class Core {
ModBlocks.init();
//Register ModItems
ModItems.init();
//Register Multiparts
ModParts.init();
// Recipes
ModRecipes.init();

View file

@ -0,0 +1,16 @@
package techreborn.init;
import techreborn.partSystem.ModPartRegistry;
import techreborn.partSystem.block.WorldProvider;
import techreborn.partSystem.parts.CablePart;
public class ModParts {
public static void init(){
ModPartRegistry.registerPart(new CablePart());
ModPartRegistry.addProvider("techreborn.partSystem.QLib.QModPartFactory", "qmunitylib");
ModPartRegistry.addProvider("techreborn.partSystem.fmp.FMPFactory", "ForgeMultipart");
ModPartRegistry.addProvider(new WorldProvider());
ModPartRegistry.addAllPartsToSystems();
}
}

View file

@ -0,0 +1,45 @@
package techreborn.lib;
import net.minecraftforge.common.util.ForgeDirection;
public class Functions {
public static int getIntDirFromDirection(ForgeDirection dir) {
switch (dir) {
case DOWN:
return 0;
case EAST:
return 5;
case NORTH:
return 2;
case SOUTH:
return 3;
case UNKNOWN:
return 0;
case UP:
return 1;
case WEST:
return 4;
default:
return 0;
}
}
public static ForgeDirection getDirectionFromInt(int dir) {
int metaDataToSet = 0;
switch (dir) {
case 0:
metaDataToSet = 2;
break;
case 1:
metaDataToSet = 4;
break;
case 2:
metaDataToSet = 3;
break;
case 3:
metaDataToSet = 5;
break;
}
return ForgeDirection.getOrientation(metaDataToSet);
}
}

View file

@ -0,0 +1,271 @@
package techreborn.lib;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.ChunkPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class Location {
public int x;
public int y;
public int z;
public int depth;
public Location(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public Location(int x, int y, int z, int depth) {
this.x = x;
this.y = y;
this.z = z;
this.depth = depth;
}
public Location(int xCoord, int yCoord, int zCoord, ForgeDirection dir) {
this.x = xCoord + dir.offsetX;
this.y = yCoord + dir.offsetY;
this.z = zCoord + dir.offsetZ;
}
public Location(int[] coords) {
if (coords.length >= 2) {
this.x = coords[0];
this.y = coords[1];
this.z = coords[2];
}
}
public Location(ChunkPosition pos) {
if (pos != null) {
this.x = pos.chunkPosX;
this.y = pos.chunkPosY;
this.z = pos.chunkPosZ;
}
}
public Location(MovingObjectPosition blockLookedAt) {
if (blockLookedAt != null) {
this.x = blockLookedAt.blockX;
this.y = blockLookedAt.blockY;
this.z = blockLookedAt.blockZ;
}
}
public Location(TileEntity par1)
{
this.x = par1.xCoord;
this.y = par1.yCoord;
this.z = par1.zCoord;
}
public boolean equals(Location toTest) {
if (this.x == toTest.x && this.y == toTest.y && this.z == toTest.z) {
return true;
}
return false;
}
public void setLocation(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public int getX() {
return this.x;
}
public void setX(int newX) {
this.x = newX;
}
public int getY() {
return this.y;
}
public void setY(int newY) {
this.y = newY;
}
public int getZ() {
return this.z;
}
public void setZ(int newZ) {
this.z = newZ;
}
public int[] getLocation() {
int[] ret = new int[3];
ret[0] = this.x;
ret[1] = this.y;
ret[2] = this.z;
return ret;
}
public void setLocation(int[] coords) {
this.x = coords[0];
this.y = coords[1];
this.z = coords[2];
}
public int getDifference(Location otherLoc) {
return (int) Math.sqrt(Math.pow(this.x - otherLoc.x, 2) + Math.pow(this.y - otherLoc.y, 2) + Math.pow(this.z - otherLoc.z, 2));
}
public String printLocation() {
return "X: " + this.x + " Y: " + this.y + " Z: " + this.z;
}
public String printCoords() {
return this.x + ", " + this.y + ", " + this.z;
}
public boolean compare(int x, int y, int z) {
return (this.x == x && this.y == y && this.z == z);
}
public Location getLocation(ForgeDirection dir) {
return new Location(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
}
public Location modifyPositionFromSide(ForgeDirection side, int amount)
{
switch (side.ordinal())
{
case 0:
this.y -= amount;
break;
case 1:
this.y += amount;
break;
case 2:
this.z -= amount;
break;
case 3:
this.z += amount;
break;
case 4:
this.x -= amount;
break;
case 5:
this.x += amount;
break;
}
return this;
}
public Location modifyPositionFromSide(ForgeDirection side)
{
return this.modifyPositionFromSide(side, 1);
}
/**
* This will load the chunk.
*/
public TileEntity getTileEntity(IBlockAccess world)
{
return world.getTileEntity(this.x, this.y, this.z);
}
public final Location clone()
{
return new Location(this.x, this.y, this.z);
}
/**
* No chunk load: returns null if chunk to side is unloaded
*/
public TileEntity getTileEntityOnSide(World world, ForgeDirection side)
{
int x = this.x;
int y = this.y;
int z = this.z;
switch (side.ordinal())
{
case 0:
y--;
break;
case 1:
y++;
break;
case 2:
z--;
break;
case 3:
z++;
break;
case 4:
x--;
break;
case 5:
x++;
break;
default:
return null;
}
if (world.blockExists(x, y, z))
{
return world.getTileEntity(x, y, z);
}
else
{
return null;
}
}
/**
* No chunk load: returns null if chunk to side is unloaded
*/
public TileEntity getTileEntityOnSide(World world, int side)
{
int x = this.x;
int y = this.y;
int z = this.z;
switch (side)
{
case 0:
y--;
break;
case 1:
y++;
break;
case 2:
z--;
break;
case 3:
z++;
break;
case 4:
x--;
break;
case 5:
x++;
break;
default:
return null;
}
if (world.blockExists(x, y, z))
{
return world.getTileEntity(x, y, z);
}
else
{
return null;
}
}
public int getDepth() {
return depth;
}
public int compareTo(Location o) {
return ((Integer)depth).compareTo(o.depth);
}
}

View file

@ -0,0 +1,431 @@
package techreborn.lib.vecmath;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import java.util.StringTokenizer;
public class Vecs3d {
protected double x, y, z;
protected World w = null;
public Vecs3d(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public Vecs3d(double x, double y, double z, World w) {
this(x, y, z);
this.w = w;
}
public Vecs3d(TileEntity te) {
this(te.xCoord, te.yCoord, te.zCoord, te.getWorldObj());
}
public Vecs3d(Vec3 vec) {
this(vec.xCoord, vec.yCoord, vec.zCoord);
}
public Vecs3d(Vec3 vec, World w) {
this(vec.xCoord, vec.yCoord, vec.zCoord);
this.w = w;
}
public boolean hasWorld() {
return w != null;
}
public Vecs3d add(double x, double y, double z) {
this.x += x;
this.y += y;
this.z += z;
return this;
}
public Vecs3d add(ForgeDirection dir) {
return add(dir.offsetX, dir.offsetY, dir.offsetZ);
}
public Vecs3d add(Vecs3d vec) {
return add(vec.x, vec.y, vec.z);
}
public Vecs3d sub(double x, double y, double z) {
this.x -= x;
this.y -= y;
this.z -= z;
return this;
}
public Vecs3d sub(ForgeDirection dir) {
return sub(dir.offsetX, dir.offsetY, dir.offsetZ);
}
public Vecs3d sub(Vecs3d vec) {
return sub(vec.x, vec.y, vec.z);
}
public Vecs3d mul(double x, double y, double z) {
this.x *= x;
this.y *= y;
this.z *= z;
return this;
}
public Vecs3d mul(double multiplier) {
return mul(multiplier, multiplier, multiplier);
}
public Vecs3d mul(ForgeDirection direction) {
return mul(direction.offsetX, direction.offsetY, direction.offsetZ);
}
public Vecs3d multiply(Vecs3d v) {
return mul(v.getX(), v.getY(), v.getZ());
}
public Vecs3d div(double x, double y, double z) {
this.x /= x;
this.y /= y;
this.z /= z;
return this;
}
public Vecs3d div(double multiplier) {
return div(multiplier, multiplier, multiplier);
}
public Vecs3d div(ForgeDirection direction) {
return div(direction.offsetX, direction.offsetY, direction.offsetZ);
}
public double length() {
return Math.sqrt(x * x + y * y + z * z);
}
public Vecs3d normalize() {
Vecs3d v = clone();
double len = length();
if (len == 0)
return v;
v.x /= len;
v.y /= len;
v.z /= len;
return v;
}
public Vecs3d abs() {
return new Vecs3d(Math.abs(x), Math.abs(y), Math.abs(z));
}
public double dot(Vecs3d v) {
return x * v.getX() + y * v.getY() + z * v.getZ();
}
public Vecs3d cross(Vecs3d v) {
return new Vecs3d(y * v.getZ() - z * v.getY(), x * v.getZ() - z * v.getX(), x * v.getY() - y * v.getX());
}
public Vecs3d getRelative(double x, double y, double z) {
return clone().add(x, y, z);
}
public Vecs3d getRelative(ForgeDirection dir) {
return getRelative(dir.offsetX, dir.offsetY, dir.offsetZ);
}
public ForgeDirection getDirectionTo(Vecs3d vec) {
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS)
if (getBlockX() + d.offsetX == vec.getBlockX() && getBlockY() + d.offsetY == vec.getBlockY()
&& getBlockZ() + d.offsetZ == vec.getBlockZ())
return d;
return null;
}
public boolean isZero() {
return x == 0 && y == 0 && z == 0;
}
@Override
public Vecs3d clone() {
return new Vecs3d(x, y, z, w);
}
public boolean hasTileEntity() {
if (hasWorld()) {
return w.getTileEntity((int) x, (int) y, (int) z) != null;
}
return false;
}
public TileEntity getTileEntity() {
if (hasTileEntity()) {
return w.getTileEntity((int) x, (int) y, (int) z);
}
return null;
}
public boolean isBlock(Block b) {
return isBlock(b, false);
}
public boolean isBlock(Block b, boolean checkAir) {
if (hasWorld()) {
Block bl = w.getBlock((int) x, (int) y, (int) z);
if (b == null && bl == Blocks.air)
return true;
if (b == null && checkAir && bl.getMaterial() == Material.air)
return true;
if (b == null && checkAir && bl.isAir(w, (int) x, (int) y, (int) z))
return true;
return bl.getClass().isInstance(b);
}
return false;
}
public int getBlockMeta() {
if (hasWorld()) {
return w.getBlockMetadata((int) x, (int) y, (int) z);
}
return -1;
}
public Block getBlock() {
return getBlock(false);
}
public Block getBlock(boolean airIsNull) {
if (hasWorld()) {
if (airIsNull && isBlock(null, true))
return null;
return w.getBlock((int) x, (int) y, (int) z);
}
return null;
}
public World getWorld() {
return w;
}
public Vecs3d setWorld(World world) {
w = world;
return this;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public double getZ() {
return z;
}
public int getBlockX() {
return (int) Math.floor(x);
}
public int getBlockY() {
return (int) Math.floor(y);
}
public int getBlockZ() {
return (int) Math.floor(z);
}
public double distanceTo(Vecs3d vec) {
return distanceTo(vec.x, vec.y, vec.z);
}
public double distanceTo(double x, double y, double z) {
double dx = x - this.x;
double dy = y - this.y;
double dz = z - this.z;
return dx * dx + dy * dy + dz * dz;
}
public void setX(double x) {
this.x = x;
}
public void setY(double y) {
this.y = y;
}
public void setZ(double z) {
this.z = z;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Vecs3d) {
Vecs3d vec = (Vecs3d) obj;
return vec.w == w && vec.x == x && vec.y == y && vec.z == z;
}
return false;
}
@Override
public int hashCode() {
return new Double(x).hashCode() + new Double(y).hashCode() << 8 + new Double(z).hashCode() << 16;
}
public Vec3 toVec3() {
return Vec3.createVectorHelper(x, y, z);
}
@Override
public String toString() {
String s = "Vector3{";
if (hasWorld())
s += "w=" + w.provider.dimensionId + ";";
s += "x=" + x + ";y=" + y + ";z=" + z + "}";
return s;
}
public ForgeDirection toForgeDirection() {
if (z == 1)
return ForgeDirection.SOUTH;
if (z == -1)
return ForgeDirection.NORTH;
if (x == 1)
return ForgeDirection.EAST;
if (x == -1)
return ForgeDirection.WEST;
if (y == 1)
return ForgeDirection.UP;
if (y == -1)
return ForgeDirection.DOWN;
return ForgeDirection.UNKNOWN;
}
public static Vecs3d fromString(String s) {
if (s.startsWith("Vector3{") && s.endsWith("}")) {
World w = null;
double x = 0, y = 0, z = 0;
String s2 = s.substring(s.indexOf("{") + 1, s.lastIndexOf("}"));
StringTokenizer st = new StringTokenizer(s2, ";");
while (st.hasMoreTokens()) {
String t = st.nextToken();
if (t.toLowerCase().startsWith("w")) {
int world = Integer.parseInt(t.split("=")[1]);
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
for (World wo : MinecraftServer.getServer().worldServers) {
if (wo.provider.dimensionId == world) {
w = wo;
break;
}
}
} else {
w = getClientWorld(world);
}
}
if (t.toLowerCase().startsWith("x"))
x = Double.parseDouble(t.split("=")[1]);
if (t.toLowerCase().startsWith("y"))
y = Double.parseDouble(t.split("=")[1]);
if (t.toLowerCase().startsWith("z"))
z = Double.parseDouble(t.split("=")[1]);
}
if (w != null) {
return new Vecs3d(x, y, z, w);
} else {
return new Vecs3d(x, y, z);
}
}
return null;
}
@SideOnly(Side.CLIENT)
private static World getClientWorld(int world) {
if (Minecraft.getMinecraft().theWorld.provider.dimensionId != world)
return null;
return Minecraft.getMinecraft().theWorld;
}
}

View file

@ -0,0 +1,161 @@
package techreborn.lib.vecmath;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import java.util.List;
public class Vecs3dCube {
private Vecs3d min, max;
public Vecs3dCube(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
this(minX, minY, minZ, maxX, maxY, maxZ, (World) null);
}
public Vecs3dCube(double minX, double minY, double minZ, double maxX, double maxY, double maxZ, World world) {
this(new Vecs3d(minX, minY, minZ, world), new Vecs3d(maxX, maxY, maxZ, world));
}
public Vecs3dCube(Vecs3d a, Vecs3d b) {
World w = a.getWorld();
if (w == null)
w = b.getWorld();
min = a;
max = b;
fix();
}
public Vecs3dCube(AxisAlignedBB aabb) {
this(aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ);
}
public Vecs3d getMin() {
return min;
}
public Vecs3d getMax() {
return max;
}
public Vecs3d getCenter() {
return new Vecs3d((getMinX() + getMaxX()) / 2D, (getMinY() + getMaxY()) / 2D, (getMinZ() + getMaxZ()) / 2D, getMin().getWorld());
}
public double getMinX() {
return min.getX();
}
public double getMinY() {
return min.getY();
}
public double getMinZ() {
return min.getZ();
}
public double getMaxX() {
return max.getX();
}
public double getMaxY() {
return max.getY();
}
public double getMaxZ() {
return max.getZ();
}
public AxisAlignedBB toAABB() {
return AxisAlignedBB.getBoundingBox(getMinX(), getMinY(), getMinZ(), getMaxX(), getMaxY(), getMaxZ());
}
@Override
public Vecs3dCube clone() {
return new Vecs3dCube(min.clone(), max.clone());
}
public Vecs3dCube expand(double size) {
min.sub(size, size, size);
max.add(size, size, size);
return this;
}
public Vecs3dCube fix() {
Vecs3d a = min.clone();
Vecs3d b = max.clone();
double minX = Math.min(a.getX(), b.getX());
double minY = Math.min(a.getY(), b.getY());
double minZ = Math.min(a.getZ(), b.getZ());
double maxX = Math.max(a.getX(), b.getX());
double maxY = Math.max(a.getY(), b.getY());
double maxZ = Math.max(a.getZ(), b.getZ());
min = new Vecs3d(minX, minY, minZ, a.w);
max = new Vecs3d(maxX, maxY, maxZ, b.w);
return this;
}
public Vecs3dCube add(double x, double y, double z) {
min.add(x, y, z);
max.add(x, y, z);
return this;
}
public static final Vecs3dCube merge(List<Vecs3dCube> cubes) {
double minx = Double.MAX_VALUE;
double miny = Double.MAX_VALUE;
double minz = Double.MAX_VALUE;
double maxx = Double.MIN_VALUE;
double maxy = Double.MIN_VALUE;
double maxz = Double.MIN_VALUE;
for (Vecs3dCube c : cubes) {
minx = Math.min(minx, c.getMinX());
miny = Math.min(miny, c.getMinY());
minz = Math.min(minz, c.getMinZ());
maxx = Math.max(maxx, c.getMaxX());
maxy = Math.max(maxy, c.getMaxY());
maxz = Math.max(maxz, c.getMaxZ());
}
if (cubes.size() == 0)
return new Vecs3dCube(0, 0, 0, 0, 0, 0);
return new Vecs3dCube(minx, miny, minz, maxx, maxy, maxz);
}
@Override
public int hashCode() {
return min.hashCode() << 8 + max.hashCode();
}
}

View file

@ -0,0 +1,13 @@
package techreborn.partSystem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import java.util.ArrayList;
public interface ICustomHighlight {
ArrayList<AxisAlignedBB> getBoxes(World world, int x, int y, int z, EntityPlayer player);
}

View file

@ -0,0 +1,106 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import techreborn.lib.vecmath.Vecs3d;
import techreborn.lib.vecmath.Vecs3dCube;
import java.util.List;
/**
* This is based of https://github.com/Qmunity/QmunityLib/blob/master/src/main/java/uk/co/qmunity/lib/part/IPart.java
* <p/>
* You should not be implementing this.
*/
public interface IModPart {
/**
* Adds all of this part's collision boxes to the list. These boxes can depend on the entity that's colliding with them.
*/
public void addCollisionBoxesToList(List<Vecs3dCube> boxes, Entity entity);
/**
* Gets this part's selection boxes.
*/
public List<Vecs3dCube> getSelectionBoxes();
/**
* Gets this part's occlusion boxes.
*/
public List<Vecs3dCube> getOcclusionBoxes();
/**
* Renders this part dynamically (every render tick).
*/
@SideOnly(Side.CLIENT)
public void renderDynamic(Vecs3d translation, double delta);
/**
* Writes the part's data to an NBT tag, which is saved with the game data.
*/
public void writeToNBT(NBTTagCompound tag);
/**
* Reads the part's data from an NBT tag, which was stored in the game data.
*/
public void readFromNBT(NBTTagCompound tag);
/**
* Gets the itemstack that places this part.
*/
public ItemStack getItem();
/**
* Gets the name of this part.
*/
public String getName();
/**
* Gets the world of this part.
*/
public World getWorld();
/**
* This is the item texture eg: "network:cable"
*/
public String getItemTextureName();
/**
* Gets the X cord of this part.
*/
public int getX();
/**
* Gets the Y cord of this part.
*/
public int getY();
/**
* Gets the Z cord of this part.
*/
public int getZ();
/**
* Called every tick
*/
public void tick();
/**
* Called when a block or part has been changed. Can be used for cables to check nearby blocks
*/
public void nearByChange();
public void onAdded();
public void onRemoved();
}

View file

@ -0,0 +1,28 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import techreborn.lib.Location;
import techreborn.lib.vecmath.Vecs3dCube;
public interface IPartProvider {
public String modID();
public void registerPart();
public boolean checkOcclusion(World world, Location location, Vecs3dCube cube);
public boolean hasPart(World world, Location location, String name);
public boolean placePart(ItemStack item, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, ModPart modPart);
public boolean isTileFromProvider(TileEntity tileEntity);
}

View file

@ -0,0 +1,100 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import techreborn.lib.Location;
/**
* Extend this class to make your multipart
*/
public abstract class ModPart extends TileEntity implements IModPart {
/**
* The world of the part
*/
public World world;
/**
* The location of the part
*/
public Location location;
/**
* This is the world
*/
@Override
public World getWorld() {
return world;
}
/**
* This sets the world
* Don't use this unless you know what you are doing.
*/
public void setWorld(World world) {
this.world = world;
setWorldObj(world);
}
/**
* Gets the x position in the world
*/
@Override
public int getX() {
return location.getX();
}
/**
* Gets the y position in the world
*/
@Override
public int getY() {
return location.getY();
}
/**
* Gets the z position in the world
*/
@Override
public int getZ() {
return location.getZ();
}
/**
* Gets the location of the part
*/
public Location getLocation() {
return location;
}
/**
* Sets the x position in the world
*/
public void setLocation(Location location) {
this.location = location;
this.xCoord = location.getX();
this.yCoord = location.getY();
this.zCoord = location.getZ();
}
@Override
public World getWorldObj() {
return getWorld();
}
@Override
public void setWorldObj(World p_145834_1_) {
super.setWorldObj(p_145834_1_);
}
}

View file

@ -0,0 +1,60 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import uk.co.qmunity.lib.ref.Names;
public class ModPartItem extends Item {
ModPart modPart;
public ModPartItem(ModPart part) {
modPart = part;
setUnlocalizedName(Names.Unlocalized.Items.MULTIPART);
}
@Override
public boolean onItemUse(ItemStack item, EntityPlayer player, World world, int x, int y, int z, int face, float x_, float y_, float z_) {
if(ModPartRegistry.masterProvider != null){
try {
if (ModPartRegistry.masterProvider.placePart(item, player, world, x, y, z, face, x_, y_, z_, modPart.getClass().newInstance())) {
return true;
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return false;
}else {
for (IPartProvider partProvider : ModPartRegistry.providers) {
try {
if (partProvider.placePart(item, player, world, x, y, z, face, x_, y_, z_, modPart.getClass().newInstance())) {
return true;
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
return true;
}
}
@Override
public String getUnlocalizedName(ItemStack stack) {
return modPart.getName();
}
public ModPart getModPart() {
return modPart;
}
}

View file

@ -0,0 +1,80 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.item.Item;
import techreborn.client.TechRebornCreativeTab;
import techreborn.util.LogHelper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class ModPartRegistry {
public static ArrayList<ModPart> parts = new ArrayList<ModPart>();
public static ArrayList<IPartProvider> providers = new ArrayList<IPartProvider>();
public static IPartProvider masterProvider = null;
public static Map<Item, String> itemParts = new HashMap<Item, String>();
public static void registerPart(ModPart iModPart) {
parts.add(iModPart);
}
public static void addAllPartsToSystems() {
LogHelper.info("Started to load all parts");
for (ModPart modPart : ModPartRegistry.parts) {
Item part = new ModPartItem(modPart).setUnlocalizedName(modPart.getName()).setCreativeTab(TechRebornCreativeTab.instance).setTextureName(modPart.getItemTextureName());
GameRegistry.registerItem(part, modPart.getName());
itemParts.put(part, modPart.getName());
}
for (IPartProvider iPartProvider : providers) {
iPartProvider.registerPart();
}
}
public static Item getItem(String string) {
for (Map.Entry<Item, String> entry : itemParts.entrySet()) {
if (entry.getValue().equals(string)) {
return entry.getKey();
}
}
return null;
}
public static void addProvider(String className, String modid) {
if (Loader.isModLoaded(modid) || modid.equals("Minecraft")) {
try {
IPartProvider iPartProvider = null;
iPartProvider = (IPartProvider) Class.forName(className).newInstance();
providers.add(iPartProvider);
} catch (ClassNotFoundException e) {
e.printStackTrace();
LogHelper.error("Failed to load " + className + " to the part system!");
} catch (InstantiationException e) {
e.printStackTrace();
LogHelper.error("Failed to load " + className + " to the part system!");
} catch (IllegalAccessException e) {
e.printStackTrace();
LogHelper.error("Failed to load " + className + " to the part system!");
}
}
}
//Only use this one if it is a standalone Provider
public static void addProvider(IPartProvider iPartProvider) {
if (Loader.isModLoaded(iPartProvider.modID()) || iPartProvider.modID().equals("Minecraft")) {
providers.add(iPartProvider);
}
}
}

View file

@ -0,0 +1,79 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem;
import net.minecraft.item.Item;
import net.minecraft.world.World;
import techreborn.lib.Location;
import techreborn.lib.vecmath.Vecs3dCube;
import java.util.Map;
public class ModPartUtils {
public static boolean checkOcclusion(World world, Location location, Vecs3dCube cube) {
if (world == null) {
return false;
}
IPartProvider partProvider = getPartProvider(world, location);
if (partProvider != null) {
return partProvider.checkOcclusion(world, location, cube);
}
return false;
}
public static boolean checkOcclusion(World world, int x, int y, int z, Vecs3dCube cube) {
return checkOcclusion(world, new Location(x, y, z), cube);
}
public static boolean checkOcclusionInvert(World world, Location location, Vecs3dCube cube) {
if (world == null) {
return false;
}
for (IPartProvider iPartProvider : ModPartRegistry.providers) {
if (!iPartProvider.checkOcclusion(world, location, cube)) {
return false;
}
}
return false;
}
public static boolean checkOcclusionInvert(World world, int x, int y, int z, Vecs3dCube cube) {
return checkOcclusionInvert(world, new Location(x, y, z), cube);
}
public static boolean hasPart(World world, Location location, String name) {
for (IPartProvider iPartProvider : ModPartRegistry.providers) {
if (iPartProvider.hasPart(world, location, name)) {
return true;
}
}
return false;
}
public static boolean hasPart(World world, int x, int y, int z, String name) {
return hasPart(world, new Location(x, y, z), name);
}
public static Item getItemForPart(String string) {
for (Map.Entry<Item, String> item : ModPartRegistry.itemParts.entrySet()) {
if (item.getValue().equals(string)) {
return item.getKey();
}
}
return null;
}
public static IPartProvider getPartProvider(World world, Location location) {
for (IPartProvider partProvider : ModPartRegistry.providers) {
if (partProvider.isTileFromProvider(world.getTileEntity(location.getX(), location.getY(), location.getZ()))) {
return partProvider;
}
}
return null;
}
}

View file

@ -0,0 +1,55 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem.QLib;
import techreborn.lib.vecmath.Vecs3d;
import techreborn.lib.vecmath.Vecs3dCube;
import uk.co.qmunity.lib.vec.Vec3d;
import uk.co.qmunity.lib.vec.Vec3dCube;
import java.util.ArrayList;
import java.util.List;
/**
* Created by mark on 09/12/14.
*/
public class ModLib2QLib {
public static Vec3d convert(Vecs3d input) {
return new Vec3d(input.getX(), input.getY(), input.getZ());
}
public static Vec3dCube convert(Vecs3dCube input) {
return new Vec3dCube(input.toAABB());
}
public static Vecs3d convert(Vec3d input) {
return new Vecs3d(input.getX(), input.getY(), input.getZ());
}
public static Vecs3dCube convert(Vec3dCube input) {
return new Vecs3dCube(input.toAABB());
}
public static List<Vecs3dCube> convert(List<Vec3dCube> input) {
List<Vecs3dCube> list = new ArrayList<Vecs3dCube>();
for (Vec3dCube cube : input) {
list.add(new Vecs3dCube(cube.toAABB()));
}
return list;
}
//Its got to be called becuase of some weird thing see: https://stackoverflow.com/questions/1998544/method-has-the-same-erasure-as-another-method-in-type
public static List<Vec3dCube> convert2(List<Vecs3dCube> input) {
List<Vec3dCube> list = new ArrayList<Vec3dCube>();
for (Vecs3dCube cube : input) {
list.add(new Vec3dCube(cube.toAABB()));
}
return list;
}
}

View file

@ -0,0 +1,143 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem.QLib;
import techreborn.lib.Location;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.ModPart;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import uk.co.qmunity.lib.part.IPart;
import uk.co.qmunity.lib.part.IPartCollidable;
import uk.co.qmunity.lib.part.IPartRenderPlacement;
import uk.co.qmunity.lib.part.IPartSelectable;
import uk.co.qmunity.lib.part.IPartTicking;
import uk.co.qmunity.lib.part.IPartUpdateListener;
import uk.co.qmunity.lib.part.ITilePartHolder;
import uk.co.qmunity.lib.part.PartBase;
import uk.co.qmunity.lib.raytrace.QMovingObjectPosition;
import uk.co.qmunity.lib.raytrace.RayTracer;
import uk.co.qmunity.lib.vec.Vec3d;
import uk.co.qmunity.lib.vec.Vec3dCube;
import java.util.ArrayList;
import java.util.List;
public class QModPart extends PartBase implements IPartCollidable, IPartSelectable, IPartRenderPlacement, IPartTicking, IPartUpdateListener {
ModPart iModPart;
public QModPart(ModPart iModPart) {
this.iModPart = iModPart;
}
@Override
public void setParent(ITilePartHolder parent) {
super.setParent(parent);
}
@Override
public String getType() {
return iModPart.getName();
}
@Override
public ItemStack getItem() {
return iModPart.getItem();
}
@Override
public void addCollisionBoxesToList(List<Vec3dCube> boxes, Entity entity) {
List<Vecs3dCube> cubes = new ArrayList<Vecs3dCube>();
iModPart.addCollisionBoxesToList(cubes, entity);
for (Vecs3dCube cube : cubes) {
if (cube != null)
boxes.add(ModLib2QLib.convert(cube));
}
}
@Override
public void renderDynamic(Vec3d translation, double delta, int pass) {
iModPart.renderDynamic(ModLib2QLib.convert(translation), delta);
}
@Override
public QMovingObjectPosition rayTrace(Vec3d start, Vec3d end) {
return RayTracer.instance().rayTraceCubes(this, start, end);
}
@Override
public List<Vec3dCube> getSelectionBoxes() {
return ModLib2QLib.convert2(iModPart.getSelectionBoxes());
}
@Override
public World getWorld() {
return getParent().getWorld();
}
@Override
public void update() {
if (iModPart.world == null || iModPart.location == null) {
iModPart.setWorld(getWorld());
iModPart.setLocation(new Location(getX(), getY(), getZ()));
}
iModPart.tick();
}
@Override
public void onPartChanged(IPart part) {
iModPart.nearByChange();
}
@Override
public void onNeighborBlockChange() {
iModPart.nearByChange();
}
@Override
public void onNeighborTileChange() {
if (iModPart.world == null || iModPart.location == null) {
iModPart.setWorld(getWorld());
iModPart.setLocation(new Location(getX(), getY(), getZ()));
}
iModPart.nearByChange();
}
@Override
public void onAdded() {
if(iModPart.location != null){
iModPart.nearByChange();
iModPart.onAdded();
}
}
@Override
public void onRemoved() {
iModPart.onRemoved();
}
@Override
public void onLoaded() {
if (iModPart.world == null || iModPart.location == null) {
iModPart.setWorld(getWorld());
iModPart.setLocation(new Location(getX(), getY(), getZ()));
}
iModPart.nearByChange();
}
@Override
public void onUnloaded() {
}
@Override
public void onConverted() {
}
}

View file

@ -0,0 +1,108 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem.QLib;
import techreborn.lib.Location;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.IPartProvider;
import techreborn.partSystem.ModPart;
import techreborn.partSystem.ModPartRegistry;
import uk.co.qmunity.lib.QLModInfo;
import uk.co.qmunity.lib.part.IPart;
import uk.co.qmunity.lib.part.IPartFactory;
import uk.co.qmunity.lib.part.PartRegistry;
import uk.co.qmunity.lib.part.compat.MultipartCompatibility;
import uk.co.qmunity.lib.tile.TileMultipart;
import uk.co.qmunity.lib.vec.Vec3dCube;
import uk.co.qmunity.lib.vec.Vec3i;
import java.util.List;
public class QModPartFactory implements IPartFactory, IPartProvider {
@Override
public IPart createPart(String type, boolean client) {
for (ModPart modPart : ModPartRegistry.parts) {
if (modPart.getName().equals(type)) {
try {
return new QModPart(modPart.getClass().newInstance());
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
return null;
}
@Override
public boolean placePart(ItemStack item, EntityPlayer player, World world, int x, int y, int z, int face, float x_, float y_, float z_, ModPart modPart) {
IPart part = createPart(item, player, world,
new MovingObjectPosition(x, y, z, face, Vec3.createVectorHelper(x + x_, y + y_, z + z_)), modPart);
if (part == null)
return false;
ForgeDirection dir = ForgeDirection.getOrientation(face);
return MultipartCompatibility.placePartInWorld(part, world, new Vec3i(x, y, z), dir, player, item);
}
@Override
public boolean isTileFromProvider(TileEntity tileEntity) {
return tileEntity instanceof TileMultipart;
}
public String getCreatedPartType(ItemStack item, EntityPlayer player, World world, MovingObjectPosition mop, ModPart modPart) {
return modPart.getName();
}
public IPart createPart(ItemStack item, EntityPlayer player, World world, MovingObjectPosition mop, ModPart modPart) {
return PartRegistry.createPart(getCreatedPartType(item, player, world, mop, modPart), world.isRemote);
}
@Override
public String modID() {
return QLModInfo.MODID;
}
@Override
public void registerPart() {
PartRegistry.registerFactory(new QModPartFactory());
}
@Override
public boolean checkOcclusion(World world, Location location, Vecs3dCube cube) {
return MultipartCompatibility.checkOcclusion(world, location.x, location.y, location.z, new Vec3dCube(cube.toAABB()));
}
@Override
public boolean hasPart(World world, Location location, String name) {
TileEntity tileEntity = world.getTileEntity(location.getX(), location.getY(), location.getZ());
if (tileEntity instanceof TileMultipart) {
TileMultipart mp = (TileMultipart) tileEntity;
boolean ret = false;
List<IPart> t = mp.getParts();
for (IPart p : t) {
if (ret == false) {
if (p.getType().equals(name)) {
ret = true;
}
}
}
return ret;
}
return false;
}
}

View file

@ -0,0 +1,155 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem.block;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.ICustomHighlight;
import techreborn.partSystem.IModPart;
import techreborn.partSystem.ModPart;
import java.util.ArrayList;
import java.util.List;
/**
* Created by mark on 10/12/14.
*/
public class BlockModPart extends BlockContainer implements ICustomHighlight {
public BlockModPart(Material met) {
super(met);
}
public static TileEntityModPart get(IBlockAccess world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if (te == null)
return null;
if (!(te instanceof TileEntityModPart))
return null;
return (TileEntityModPart) te;
}
@Override
public TileEntity createNewTileEntity(World world, int i) {
return new TileEntityModPart();
}
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB bounds, List l, Entity entity) {
TileEntityModPart te = get(world, x, y, z);
if (te == null)
return;
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
te.addCollisionBoxesToList(boxes, bounds, entity);
for (Vecs3dCube c : boxes)
l.add(c.toAABB());
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public int getRenderType() {
return -1;
}
@Override
//TODO move to array list
public ArrayList<AxisAlignedBB> getBoxes(World world, int x, int y, int z, EntityPlayer player) {
TileEntityModPart te = get(world, x, y, z);
if (te == null)
return null;
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
ArrayList<AxisAlignedBB> list = new ArrayList<AxisAlignedBB>();
if (!te.getParts().isEmpty()) {
for (ModPart modPart : te.getParts())
boxes.addAll(modPart.getSelectionBoxes());
for (int i = 0; i < boxes.size(); i++) {
Vecs3dCube cube = boxes.get(i);
list.add(cube.toAABB());
}
}
return list;
}
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
for (ModPart part : get(world, x, y, z).getParts()) {
part.nearByChange();
}
}
@Override
public MovingObjectPosition collisionRayTrace(World wrd, int x, int y, int z, Vec3 origin, Vec3 direction) {
ArrayList<AxisAlignedBB> aabbs = getBoxes(wrd, x, y, z, null);
MovingObjectPosition closest = null;
for (AxisAlignedBB aabb : aabbs) {
MovingObjectPosition mop = aabb.getOffsetBoundingBox(x, y, z).calculateIntercept(origin, direction);
if (mop != null) {
if (closest != null && mop.hitVec.distanceTo(origin) < closest.hitVec.distanceTo(origin)) {
closest = mop;
} else {
closest = mop;
}
}
}
if (closest != null) {
closest.blockX = x;
closest.blockY = y;
closest.blockZ = z;
}
return closest;
}
@Override
public void onBlockAdded(World world, int x, int y, int z) {
for (ModPart part : get(world, x, y, z).getParts()) {
part.onAdded();
}
super.onBlockAdded(world, x, y, z);
}
@Override
public void breakBlock(World world, int x, int y, int z, Block oldid, int oldmeta) {
for (ModPart part : get(world, x, y, z).getParts()) {
part.onRemoved();
}
super.breakBlock(world, x, y, z, oldid, oldmeta);
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
ArrayList<ItemStack> l = new ArrayList<ItemStack>();
TileEntityModPart te = get(world, x, y, z);
if (te != null) {
for (IModPart p : te.getParts()) {
ItemStack item = p.getItem();
if (item != null)
l.add(item);
}
}
return l;
}
}

View file

@ -0,0 +1,28 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem.block;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11;
import techreborn.lib.vecmath.Vecs3d;
import techreborn.partSystem.ModPart;
public class RenderModPart extends TileEntitySpecialRenderer {
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float delta) {
TileEntityModPart te = (TileEntityModPart) tileEntity;
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
{
for (ModPart modPart : te.getParts()) {
modPart.renderDynamic(new Vecs3d(0, 0, 0), delta);
}
}
GL11.glPopMatrix();
}
}

View file

@ -0,0 +1,243 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem.block;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import techreborn.lib.Location;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.ModPart;
import techreborn.partSystem.ModPartRegistry;
import techreborn.partSystem.parts.NullPart;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TileEntityModPart extends TileEntity {
private Map<String, ModPart> parts = new HashMap<String, ModPart>();
public void addCollisionBoxesToList(List<Vecs3dCube> l, AxisAlignedBB bounds, Entity entity) {
if (getParts().size() == 0)
addPart(new NullPart());
List<Vecs3dCube> boxes2 = new ArrayList<Vecs3dCube>();
for (ModPart mp : getParts()) {
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
mp.addCollisionBoxesToList(boxes, entity);
for (int i = 0; i < boxes.size(); i++) {
Vecs3dCube cube = boxes.get(i).clone();
cube.add(getX(), getY(), getZ());
boxes2.add(cube);
}
}
for (Vecs3dCube c : boxes2) {
//if (c.toAABB().intersectsWith(bounds))
l.add(c);
}
}
public List<Vecs3dCube> getOcclusionBoxes() {
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
for (ModPart mp : getParts()) {
boxes.addAll(mp.getOcclusionBoxes());
}
return boxes;
}
@Override
public AxisAlignedBB getRenderBoundingBox() {
return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1);
}
public World getWorld() {
return getWorldObj();
}
public int getX() {
return xCoord;
}
public int getY() {
return yCoord;
}
public int getZ() {
return zCoord;
}
@Override
public void updateEntity() {
if (parts.isEmpty()) {
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
for (ModPart mp : getParts()) {
if (mp.world != null && mp.location != null) {
mp.tick();
}
}
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
NBTTagList l = new NBTTagList();
writeParts(l, false);
tag.setTag("parts", l);
}
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
NBTTagList l = tag.getTagList("parts", new NBTTagCompound().getId());
try {
readParts(l);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
}
private void writeParts(NBTTagList l, boolean update) {
for (ModPart p : getParts()) {
String id = getIdentifier(p);
NBTTagCompound tag = new NBTTagCompound();
tag.setString("id", id);
tag.setString("type", p.getName());
NBTTagCompound data = new NBTTagCompound();
p.writeToNBT(data);
tag.setTag("data", data);
l.appendTag(tag);
}
}
private void readParts(NBTTagList l) throws IllegalAccessException, InstantiationException {
for (int i = 0; i < l.tagCount(); i++) {
NBTTagCompound tag = l.getCompoundTagAt(i);
String id = tag.getString("id");
ModPart p = getPart(id);
if (p == null) {
for (ModPart modPart : ModPartRegistry.parts) {
if (modPart.getName().equals(id)) {
p = modPart.getClass().newInstance();
}
}
if (p == null)
continue;
addPart(p);
}
NBTTagCompound data = tag.getCompoundTag("data");
p.readFromNBT(data);
}
}
public void addPart(ModPart modPart) {
try {
ModPart newPart = modPart.getClass().newInstance();
newPart.setWorld(getWorldObj());
newPart.setLocation(new Location(xCoord, yCoord, zCoord));
parts.put(newPart.getName(), newPart);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
private ModPart getPart(String id) {
for (String s : parts.keySet())
if (s.equals(id))
return parts.get(s);
return null;
}
private String getIdentifier(ModPart part) {
for (String s : parts.keySet())
if (parts.get(s).equals(part))
return s;
return null;
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound tag = new NBTTagCompound();
writeToNBT(tag);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, tag);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
readFromNBT(pkt.func_148857_g());
}
public List<ModPart> getParts() {
List<ModPart> parts = new ArrayList<ModPart>();
for (String s : this.parts.keySet()) {
ModPart p = this.parts.get(s);
parts.add(p);
}
return parts;
}
public List<String> getPartsByName() {
List<String> parts = new ArrayList<String>();
for (String s : this.parts.keySet()) {
parts.add(s);
}
return parts;
}
public boolean canAddPart(ModPart modpart) {
List<Vecs3dCube> cubes = new ArrayList<Vecs3dCube>();
modpart.addCollisionBoxesToList(cubes, null);
for (Vecs3dCube c : cubes)
if (c != null && !getWorld().checkNoEntityCollision(c.clone().add(getX(), getY(), getZ()).toAABB()))
return false;
List<Vecs3dCube> l = getOcclusionBoxes();
for (Vecs3dCube b : modpart.getOcclusionBoxes())
for (Vecs3dCube c : l)
if (c != null && b != null && b.toAABB().intersectsWith(c.toAABB()))
return false;
return true;
}
}

View file

@ -0,0 +1,98 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem.block;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import techreborn.lib.Location;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.IPartProvider;
import techreborn.partSystem.ModPart;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
/**
* Created by mark on 10/12/14.
*/
public class WorldProvider implements IPartProvider {
Block blockModPart;
@Override
public String modID() {
return "Minecraft";
}
@Override
public void registerPart() {
//Loads all of the items
blockModPart = new BlockModPart(Material.ground).setBlockName("modPartBlock");
GameRegistry.registerBlock(blockModPart, "modPartBlock");
//registers the tile and renderer
GameRegistry.registerTileEntity(TileEntityModPart.class, "TileEntityModPart");
}
public void clientRegister() {
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityModPart.class, new RenderModPart());
}
@Override
public boolean checkOcclusion(World world, Location location, Vecs3dCube cube) {
return true;
}
@Override
public boolean hasPart(World world, Location location, String name) {
TileEntity tileEntity = world.getTileEntity(location.getX(), location.getY(), location.getZ());
if (tileEntity instanceof TileEntityModPart) {
for (ModPart part : ((TileEntityModPart) tileEntity).getParts()) {
if (part.getName().equals(name)) {
return true;
}
}
}
return false;
}
@Override
public boolean placePart(ItemStack item, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, ModPart modPart) {
ForgeDirection forgeDirection = ForgeDirection.getOrientation(side);
if (world.getBlock(x + forgeDirection.offsetX, y + forgeDirection.offsetY, z + forgeDirection.offsetZ) == Blocks.air) {
TileEntityModPart modPart1;
world.setBlock(x + forgeDirection.offsetX, y + forgeDirection.offsetY, z + forgeDirection.offsetZ, blockModPart);
modPart1 = (TileEntityModPart) world.getTileEntity(x + forgeDirection.offsetX, y + forgeDirection.offsetY, z + forgeDirection.offsetZ);
//if(modPart1.canAddPart(modPart)){
modPart1.addPart(modPart);
return true;
//}
}
//this adds a part to a block
if (world.getBlock(x, y, z) == blockModPart) {
TileEntityModPart tileEntityModPart = (TileEntityModPart) world.getTileEntity(x + forgeDirection.offsetX, y + forgeDirection.offsetY, z + forgeDirection.offsetZ);
if (!tileEntityModPart.getPartsByName().contains(modPart.getName()) && tileEntityModPart.canAddPart(modPart))
tileEntityModPart.addPart(modPart);
return true;
}
if (world.getBlock(x + forgeDirection.offsetX, y + forgeDirection.offsetY, z + forgeDirection.offsetZ) == blockModPart) {
TileEntityModPart tileEntityModPart = (TileEntityModPart) world.getTileEntity(x + forgeDirection.offsetX, y + forgeDirection.offsetY, z + forgeDirection.offsetZ);
if (!tileEntityModPart.getPartsByName().contains(modPart.getName()) && tileEntityModPart.canAddPart(modPart))
tileEntityModPart.addPart(modPart);
return true;
}
return false;
}
@Override
public boolean isTileFromProvider(TileEntity tileEntity) {
return tileEntity instanceof TileEntityModPart;
}
}

View file

@ -0,0 +1,125 @@
package techreborn.partSystem.client;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.shader.Framebuffer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
import techreborn.lib.Location;
import techreborn.lib.vecmath.Vecs3d;
import techreborn.partSystem.IModPart;
import techreborn.partSystem.ModPartItem;
/**
* This is based of https://github.com/Qmunity/QmunityLib/blob/master/src%2Fmain%2Fjava%2Fuk%2Fco%2Fqmunity%2Flib%2Fclient%2Frender%2FRenderPartPlacement.java
* <p/>
* You should go check them out!
*/
@SideOnly(Side.CLIENT)
public class PartPlacementRenderer {
private Framebuffer fb = null;
private int width = 0, height = 0;
@SubscribeEvent
public void onRenderTick(RenderWorldLastEvent event) {
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
ItemStack item = player.getCurrentEquippedItem();
if (item == null)
return;
if (!(item.getItem() instanceof ModPartItem))
return;
if (Minecraft.getMinecraft().gameSettings.hideGUI && Minecraft.getMinecraft().currentScreen == null)
return;
MovingObjectPosition mop = player.rayTrace(player.capabilities.isCreativeMode ? 5 : 4, 0);
if (mop == null || mop.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK)
return;
IModPart part = ((ModPartItem) item.getItem()).getModPart();
if (part == null)
return;
ForgeDirection faceHit = ForgeDirection.getOrientation(mop.sideHit);
Location location = new Location(mop.blockX, mop.blockY, mop.blockZ);
if (fb == null || width != Minecraft.getMinecraft().displayWidth || height != Minecraft.getMinecraft().displayHeight) {
width = Minecraft.getMinecraft().displayWidth;
height = Minecraft.getMinecraft().displayHeight;
fb = new Framebuffer(width, height, true);
}
GL11.glPushMatrix();
{
Minecraft.getMinecraft().getFramebuffer().unbindFramebuffer();
GL11.glPushMatrix();
{
GL11.glLoadIdentity();
fb.bindFramebuffer(true);
GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glClearColor(0, 0, 0, 0);
net.minecraft.client.renderer.RenderHelper.enableStandardItemLighting();
GL11.glPushMatrix();
{
Vec3 playerPos = player.getPosition(event.partialTicks);
double x = location.getX() - playerPos.xCoord + faceHit.offsetX;
double y = location.getY() - playerPos.yCoord + faceHit.offsetY;
double z = location.getZ() - playerPos.zCoord + faceHit.offsetZ;
GL11.glRotated(player.rotationPitch, 1, 0, 0);
GL11.glRotated(player.rotationYaw - 180, 0, 1, 0);
GL11.glTranslated(x, y, z);
part.renderDynamic(new Vecs3d(0, 0, 0), event.partialTicks);
}
GL11.glPopMatrix();
net.minecraft.client.renderer.RenderHelper.disableStandardItemLighting();
fb.unbindFramebuffer();
}
GL11.glPopMatrix();
Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(true);
GL11.glPushMatrix();
{
Minecraft mc = Minecraft.getMinecraft();
ScaledResolution scaledresolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0, 0.1, 10000D);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glTranslatef(0.0F, 0.0F, -2000.0F);
fb.bindFramebufferTexture();
{
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Tessellator tessellator = Tessellator.instance;
int w = scaledresolution.getScaledWidth();
int h = scaledresolution.getScaledHeight();
tessellator.startDrawingQuads();
tessellator.setColorRGBA_F(1, 1, 1, 0.5F);
tessellator.addVertexWithUV(w, h, 0.0D, 1.0D, 0.0D);
tessellator.addVertexWithUV(w, 0, 0.0D, 1.0D, 1.0D);
tessellator.addVertexWithUV(0, 0, 0.0D, 0.0D, 1.0D);
tessellator.addVertexWithUV(0, h, 0.0D, 0.0D, 0.0D);
tessellator.draw();
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_LIGHTING);
}
fb.unbindFramebufferTexture();
GL11.glDisable(GL11.GL_BLEND);
}
GL11.glPopMatrix();
fb.framebufferClear();
Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(true);
}
GL11.glPopMatrix();
}
}

View file

@ -0,0 +1,93 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem.fmp;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Cuboid6;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.NormallyOccludedPart;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
import techreborn.lib.Location;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.IPartProvider;
import techreborn.partSystem.ModPart;
import techreborn.partSystem.ModPartRegistry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import java.util.List;
/**
* Created by mark on 09/12/14.
*/
public class FMPFactory implements MultiPartRegistry.IPartFactory, IPartProvider {
@Override
public TMultiPart createPart(String type, boolean client) {
for (ModPart modPart : ModPartRegistry.parts) {
if (modPart.getName().equals(type)) {
try {
return new FMPModPart(modPart.getClass().newInstance());
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
return null;
}
public boolean placePart(ItemStack item, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, ModPart modPart) {
return new FakeFMPPlacerItem(modPart).onItemUse(item, player, world, x, y, z, side, hitX, hitY, hitZ);
}
@Override
public boolean isTileFromProvider(TileEntity tileEntity) {
return tileEntity instanceof TileMultipart;
}
@Override
public String modID() {
return "ForgeMultipart";
}
@Override
public void registerPart() {
for (ModPart modPart : ModPartRegistry.parts) {
MultiPartRegistry.registerParts(new FMPFactory(), new String[]{modPart.getName()});
}
}
@Override
public boolean checkOcclusion(World world, Location location, Vecs3dCube cube) {
codechicken.multipart.TileMultipart tmp = codechicken.multipart.TileMultipart.getOrConvertTile(world, new BlockCoord(location.getX(), location.getY(), location.getZ()));
if (tmp == null)
return false;
return !tmp.occlusionTest(tmp.partList(), new NormallyOccludedPart(new Cuboid6(cube.toAABB())));
}
@Override
public boolean hasPart(World world, Location location, String name) {
TileEntity tileEntity = world.getTileEntity(location.getX(), location.getY(), location.getZ());
if (tileEntity instanceof TileMultipart) {
TileMultipart mp = (TileMultipart) tileEntity;
boolean ret = false;
List<TMultiPart> t = mp.jPartList();
for (TMultiPart p : t) {
if (ret == false) {
if (p.getType().equals(name)) {
ret = true;
}
}
}
return ret;
}
return false;
}
}

View file

@ -0,0 +1,179 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem.fmp;
import codechicken.lib.raytracer.IndexedCuboid6;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Vector3;
import codechicken.microblock.ISidedHollowConnect;
import codechicken.multipart.JNormalOcclusion;
import codechicken.multipart.NormalOcclusionTest;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TSlottedPart;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import techreborn.lib.Location;
import techreborn.lib.vecmath.Vecs3d;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.ModPart;
import java.util.ArrayList;
import java.util.List;
public class FMPModPart extends TMultiPart implements TSlottedPart, JNormalOcclusion, ISidedHollowConnect {
ModPart iModPart;
public FMPModPart(ModPart iModPart) {
this.iModPart = iModPart;
}
@Override
public int getHollowSize(int i) {
return 0;
}
@Override
public Iterable<Cuboid6> getOcclusionBoxes() {
List<Cuboid6> cubes = new ArrayList<Cuboid6>();
for (Vecs3dCube c : iModPart.getOcclusionBoxes())
cubes.add(new Cuboid6(c.toAABB()));
return cubes;
}
@Override
public boolean occlusionTest(TMultiPart npart) {
return NormalOcclusionTest.apply(this, npart);
}
public void addCollisionBoxesToList(List<Vecs3dCube> l, AxisAlignedBB bounds, Entity entity) {
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
List<Vecs3dCube> boxes_ = new ArrayList<Vecs3dCube>();
iModPart.addCollisionBoxesToList(boxes_, entity);
for (Vecs3dCube c : boxes_) {
Vecs3dCube cube = c.clone();
cube.add(getX(), getY(), getZ());
boxes.add(cube);
}
boxes_.clear();
for (Vecs3dCube c : boxes) {
if (c.toAABB().intersectsWith(bounds))
l.add(c);
}
}
@Override
public Iterable<Cuboid6> getCollisionBoxes() {
List<Cuboid6> cubes = new ArrayList<Cuboid6>();
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
iModPart.addCollisionBoxesToList(boxes, null);
for (Vecs3dCube c : boxes) {
if (c != null)
cubes.add(new Cuboid6(c.toAABB()));
}
return cubes;
}
@Override
public Iterable<IndexedCuboid6> getSubParts() {
List<IndexedCuboid6> cubes = new ArrayList<IndexedCuboid6>();
if (iModPart.getSelectionBoxes() != null) {
for (Vecs3dCube c : iModPart.getSelectionBoxes())
if (c != null)
cubes.add(new IndexedCuboid6(0, new Cuboid6(c.toAABB())));
if (cubes.size() == 0)
cubes.add(new IndexedCuboid6(0, new Cuboid6(0, 0, 0, 1, 1, 1)));
}
return cubes;
}
@Override
@SideOnly(Side.CLIENT)
public void renderDynamic(Vector3 pos, float frame, int pass) {
iModPart.renderDynamic(new Vecs3d(pos.x, pos.y, pos.z), frame);
}
@Override
public String getType() {
return iModPart.getName();
}
@Override
public int getSlotMask() {
return 0;
}
public World getWorld() {
return world();
}
public int getX() {
if (iModPart.world == null || iModPart.location == null) {
iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z()));
}
return x();
}
public int getY() {
if (iModPart.world == null || iModPart.location == null) {
iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z()));
}
return y();
}
public int getZ() {
if (iModPart.world == null || iModPart.location == null) {
iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z()));
}
return z();
}
@Override
public void onAdded() {
iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z()));
iModPart.nearByChange();
iModPart.onAdded();
}
@Override
public void update() {
if(iModPart.location != null){
iModPart.tick();
}
}
@Override
public void onNeighborChanged() {
super.onNeighborChanged();
if (iModPart.world == null || iModPart.location == null) {
iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z()));
}
iModPart.nearByChange();
}
public void onRemoved() {
iModPart.onRemoved();
super.onRemoved();
}
}

View file

@ -0,0 +1,32 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem.fmp;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Vector3;
import codechicken.multipart.JItemMultiPart;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.TMultiPart;
import techreborn.partSystem.ModPart;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
/**
* This item is never added into the game, it is only used to add the part to the world.
*/
public class FakeFMPPlacerItem extends JItemMultiPart {
ModPart modPart;
public FakeFMPPlacerItem(ModPart part) {
modPart = part;
}
@Override
public TMultiPart newPart(ItemStack item, EntityPlayer player, World world, BlockCoord pos, int side, Vector3 vhit) {
TMultiPart w = MultiPartRegistry.createPart(modPart.getName(), false);
return w;
}
}

View file

@ -0,0 +1,247 @@
package techreborn.partSystem.parts;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergyConductor;
import ic2.api.energy.tile.IEnergyTile;
import ic2.core.IC2;
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.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import techreborn.lib.Functions;
import techreborn.lib.vecmath.Vecs3d;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.ModPart;
import techreborn.partSystem.ModPartUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CablePart extends ModPart implements IEnergyConductor {
public static Vecs3dCube[] boundingBoxes = new Vecs3dCube[14];
public static float center = 0.6F;
public static float offset = 0.10F;
public Map<ForgeDirection, TileEntity> connectedSides;
public int ticks = 0;
protected ForgeDirection[] dirs = ForgeDirection.values();
private boolean[] connections = new boolean[6];
public boolean addedToEnergyNet = false;
public static void
refreshBounding() {
float centerFirst = center - offset;
double w = 0.2D / 2;
boundingBoxes[6] = new Vecs3dCube(centerFirst - w - 0.03, centerFirst - w - 0.08, centerFirst - w - 0.03, centerFirst + w + 0.08, centerFirst + w + 0.04, centerFirst + w + 0.08);
boundingBoxes[6] = new Vecs3dCube(centerFirst - w, centerFirst - w, centerFirst - w, centerFirst + w, centerFirst + w, centerFirst + w);
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) {
if (world != null || location != null) {
checkConnectedSides();
} else {
connectedSides = new HashMap<ForgeDirection, TileEntity>();
}
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>();
checkConnectedSides();
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() {
checkConnectedSides();
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 void writeToNBT(NBTTagCompound tag) {
}
@Override
public void readFromNBT(NBTTagCompound tag) {
}
@Override
public String getName() {
return "Cable";
}
@Override
public String getItemTextureName() {
return "network:networkCable";
}
@Override
public void tick() {
if (ticks == 0) {
checkConnectedSides();
ticks += 1;
} else if (ticks == 40) {
ticks = 0;
} else {
ticks += 1;
}
if(IC2.platform.isSimulating()) {
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
this.addedToEnergyNet = true;
checkConnectedSides();
}
}
@Override
public void nearByChange() {
checkConnectedSides();
}
@Override
public void onAdded() {
checkConnections(world, getX(), getY(), getZ());
}
@Override
public void onRemoved() {
if(IC2.platform.isSimulating() && this.addedToEnergyNet) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
this.addedToEnergyNet = false;
}
}
@Override
public ItemStack getItem() {
return new ItemStack(ModPartUtils.getItemForPart(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)) {
//TODO if (ModPartUtils.checkOcclusion(getWorld(), getX(), getY(), getZ(), boundingBoxes[d])) {
connectedSides.put(dir, te);
// }
}
}
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);
}
@Override
public double getConductionLoss() {
return 0D;
}
@Override
public double getInsulationEnergyAbsorption() {
return 256;
}
@Override
public double getInsulationBreakdownEnergy() {
return 2048;
}
@Override
public double getConductorBreakdownEnergy() {
return 2048;
}
@Override
public void removeInsulation() {
}
@Override
public void removeConductor() {
}
@Override
public boolean acceptsEnergyFrom(TileEntity tileEntity, ForgeDirection forgeDirection) {
return true;
}
@Override
public boolean emitsEnergyTo(TileEntity tileEntity, ForgeDirection forgeDirection) {
return true;
}
}

View file

@ -0,0 +1,87 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem.parts;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import techreborn.lib.vecmath.Vecs3d;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.ModPart;
import java.util.ArrayList;
import java.util.List;
/**
* Created by mark on 11/12/14.
*/
public class NullPart extends ModPart {
@Override
public void addCollisionBoxesToList(List<Vecs3dCube> boxes, Entity entity) {
boxes.add(new Vecs3dCube(0, 0, 0, 1, 1, 1));
}
@Override
public List<Vecs3dCube> getSelectionBoxes() {
List<Vecs3dCube> cubes = new ArrayList<Vecs3dCube>();
cubes.add(new Vecs3dCube(0, 0, 0, 1, 1, 1));
return cubes;
}
@Override
public List<Vecs3dCube> getOcclusionBoxes() {
return null;
}
@Override
public void renderDynamic(Vecs3d translation, double delta) {
}
@Override
public void writeToNBT(NBTTagCompound tag) {
}
@Override
public void readFromNBT(NBTTagCompound tag) {
}
@Override
public ItemStack getItem() {
return null;
}
@Override
public String getName() {
return "NullPart";
}
@Override
public String getItemTextureName() {
return "";
}
@Override
public void tick() {
}
@Override
public void nearByChange() {
}
@Override
public void onAdded() {
}
@Override
public void onRemoved() {
}
}