TechReborn/src/main/java/techreborn/partSystem/QLib/QModPart.java

171 lines
3.5 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.QLib;
2015-04-24 15:20:09 +02:00
import java.util.ArrayList;
import java.util.List;
2015-04-23 21:49:30 +02:00
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
2015-04-20 22:28:54 +02:00
import techreborn.lib.Location;
2015-04-23 21:49:30 +02:00
import techreborn.lib.vecmath.Vecs3d;
2015-04-20 22:28:54 +02:00
import techreborn.lib.vecmath.Vecs3dCube;
2015-04-20 22:02:25 +02:00
import techreborn.partSystem.ModPart;
2015-04-23 21:49:30 +02:00
import uk.co.qmunity.lib.client.render.RenderHelper;
import uk.co.qmunity.lib.part.*;
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;
2015-04-23 21:49:30 +02:00
import uk.co.qmunity.lib.vec.Vec3i;
2015-04-24 15:20:09 +02:00
public class QModPart extends PartBase implements IPartCollidable,
IPartSelectable, IPartRenderPlacement, IPartTicking,
IPartUpdateListener {
ModPart iModPart;
2015-04-24 15:20:09 +02:00
public QModPart(ModPart iModPart)
{
this.iModPart = iModPart;
}
@Override
2015-04-24 15:20:09 +02:00
public void setParent(ITilePartHolder parent)
{
super.setParent(parent);
}
@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 ItemStack getItem()
{
return iModPart.getItem();
}
@Override
2015-04-24 15:20:09 +02:00
public void addCollisionBoxesToList(List<Vec3dCube> boxes, Entity entity)
{
List<Vecs3dCube> cubes = new ArrayList<Vecs3dCube>();
iModPart.addCollisionBoxesToList(cubes, entity);
2015-04-24 15:20:09 +02:00
for (Vecs3dCube cube : cubes)
{
if (cube != null)
boxes.add(ModLib2QLib.convert(cube));
}
}
@Override
2015-04-24 15:20:09 +02:00
public void renderDynamic(Vec3d translation, double delta, int pass)
{
iModPart.renderDynamic(ModLib2QLib.convert(translation), delta);
}
2015-04-23 21:49:30 +02:00
@Override
public boolean renderStatic(Vec3i translation, RenderHelper renderer, RenderBlocks renderBlocks, int pass) {
return iModPart.renderStatic(new Vecs3d(translation.getX(), translation.getY(), translation.getZ()), renderer, pass);
2015-04-23 21:49:30 +02:00
}
@Override
2015-04-24 15:20:09 +02:00
public QMovingObjectPosition rayTrace(Vec3d start, Vec3d end)
{
return RayTracer.instance().rayTraceCubes(this, start, end);
}
@Override
2015-04-24 15:20:09 +02:00
public List<Vec3dCube> getSelectionBoxes()
{
return ModLib2QLib.convert2(iModPart.getSelectionBoxes());
}
@Override
2015-04-24 15:20:09 +02:00
public World getWorld()
{
return getParent().getWorld();
}
@Override
2015-04-24 15:20:09 +02:00
public void update()
{
if (iModPart.world == null || iModPart.location == null)
{
iModPart.setWorld(getWorld());
iModPart.setLocation(new Location(getX(), getY(), getZ()));
}
iModPart.tick();
}
@Override
2015-04-24 15:20:09 +02:00
public void onPartChanged(IPart part)
{
iModPart.nearByChange();
}
@Override
2015-04-24 15:20:09 +02:00
public void onNeighborBlockChange()
{
iModPart.nearByChange();
}
@Override
2015-04-24 15:20:09 +02:00
public void onNeighborTileChange()
{
if (iModPart.world == null || iModPart.location == null)
{
iModPart.setWorld(getWorld());
iModPart.setLocation(new Location(getX(), getY(), getZ()));
}
iModPart.nearByChange();
}
@Override
2015-04-24 15:20:09 +02:00
public void onAdded()
{
if (iModPart.location != null)
{
iModPart.nearByChange();
iModPart.onAdded();
}
}
@Override
2015-04-24 15:20:09 +02:00
public void onRemoved()
{
iModPart.onRemoved();
}
@Override
2015-04-24 15:20:09 +02:00
public void onLoaded()
{
if (iModPart.world == null || iModPart.location == null)
{
iModPart.setWorld(getWorld());
iModPart.setLocation(new Location(getX(), getY(), getZ()));
}
iModPart.nearByChange();
}
@Override
2015-04-24 15:20:09 +02:00
public void onUnloaded()
{
}
@Override
2015-04-24 15:20:09 +02:00
public void onConverted()
{
}
}