TechReborn/src/main/java/techreborn/partSystem/fmp/FMPModPart.java

225 lines
5.1 KiB
Java
Raw Normal View History

/*
* 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.
*/
2015-04-20 22:02:25 +02:00
package techreborn.partSystem.fmp;
2015-04-24 15:20:09 +02:00
import java.util.ArrayList;
import java.util.List;
2015-04-24 15:20:09 +02:00
import net.minecraft.client.renderer.RenderBlocks;
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 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.client.renderer.RenderBlocks;
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
2015-04-20 22:28:54 +02:00
import techreborn.lib.Location;
import techreborn.lib.vecmath.Vecs3d;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.ModPart;
import uk.co.qmunity.lib.client.render.RenderHelper;
2015-04-24 15:20:09 +02:00
public class FMPModPart extends TMultiPart implements TSlottedPart,
JNormalOcclusion, ISidedHollowConnect {
ModPart iModPart;
2015-04-24 15:20:09 +02:00
public FMPModPart(ModPart iModPart)
{
this.iModPart = iModPart;
}
@Override
2015-04-24 15:20:09 +02:00
public int getHollowSize(int i)
{
return 0;
}
@Override
2015-04-24 15:20:09 +02:00
public Iterable<Cuboid6> getOcclusionBoxes()
{
List<Cuboid6> cubes = new ArrayList<Cuboid6>();
for (Vecs3dCube c : iModPart.getOcclusionBoxes())
cubes.add(new Cuboid6(c.toAABB()));
return cubes;
}
@Override
2015-04-24 15:20:09 +02:00
public boolean occlusionTest(TMultiPart npart)
{
return NormalOcclusionTest.apply(this, npart);
}
2015-04-24 15:20:09 +02:00
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);
2015-04-24 15:20:09 +02:00
for (Vecs3dCube c : boxes_)
{
Vecs3dCube cube = c.clone();
cube.add(getX(), getY(), getZ());
boxes.add(cube);
}
boxes_.clear();
2015-04-24 15:20:09 +02:00
for (Vecs3dCube c : boxes)
{
if (c.toAABB().intersectsWith(bounds))
l.add(c);
}
}
@Override
2015-04-24 15:20:09 +02:00
public Iterable<Cuboid6> getCollisionBoxes()
{
List<Cuboid6> cubes = new ArrayList<Cuboid6>();
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
iModPart.addCollisionBoxesToList(boxes, null);
2015-04-24 15:20:09 +02:00
for (Vecs3dCube c : boxes)
{
if (c != null)
cubes.add(new Cuboid6(c.toAABB()));
}
return cubes;
}
@Override
2015-04-24 15:20:09 +02:00
public Iterable<IndexedCuboid6> getSubParts()
{
List<IndexedCuboid6> cubes = new ArrayList<IndexedCuboid6>();
2015-04-24 15:20:09 +02:00
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)
2015-04-24 15:20:09 +02:00
public void renderDynamic(Vector3 pos, float frame, int pass)
{
iModPart.renderDynamic(new Vecs3d(pos.x, pos.y, pos.z), frame);
}
@Override
2015-04-24 15:20:09 +02:00
public String getType()
{
return iModPart.getName();
}
@Override
2015-04-24 15:20:09 +02:00
public int getSlotMask()
{
return 0;
}
2015-04-24 15:20:09 +02:00
public World getWorld()
{
return world();
}
2015-04-24 15:20:09 +02:00
public int getX()
{
if (iModPart.world == null || iModPart.location == null)
{
iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z()));
}
return x();
}
2015-04-24 15:20:09 +02:00
public int getY()
{
if (iModPart.world == null || iModPart.location == null)
{
iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z()));
}
return y();
}
2015-04-24 15:20:09 +02:00
public int getZ()
{
if (iModPart.world == null || iModPart.location == null)
{
iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z()));
}
return z();
}
@Override
2015-04-24 15:20:09 +02:00
public void onAdded()
{
iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z()));
iModPart.nearByChange();
iModPart.onAdded();
}
@Override
2015-04-24 15:20:09 +02:00
public void update()
{
if (iModPart.location != null)
{
iModPart.tick();
}
}
@Override
2015-04-24 15:20:09 +02:00
public void onNeighborChanged()
{
super.onNeighborChanged();
2015-04-24 15:20:09 +02:00
if (iModPart.world == null || iModPart.location == null)
{
iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z()));
}
iModPart.nearByChange();
}
2015-04-24 15:20:09 +02:00
public void onRemoved()
{
iModPart.onRemoved();
super.onRemoved();
}
@Override
2015-04-24 15:20:09 +02:00
public boolean renderStatic(Vector3 pos, int pass)
{
boolean render = false;
render = iModPart.renderStatic(new Vecs3d(pos.x, pos.y, pos.z), uk.co.qmunity.lib.client.render.RenderHelper.instance, pass);
RenderHelper.instance.resetRenderedSides();
RenderHelper.instance.resetTextureRotations();
RenderHelper.instance.resetTransformations();
RenderHelper.instance.setColor(0xFFFFFF);
return render;
}
}