2015-04-20 21:08:14 +02:00
|
|
|
/*
|
|
|
|
* 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-20 21:08:14 +02:00
|
|
|
|
|
|
|
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;
|
2015-11-23 15:45:16 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2015-11-08 13:15:45 +01:00
|
|
|
import reborncore.common.misc.Location;
|
|
|
|
import reborncore.common.misc.vecmath.Vecs3dCube;
|
2015-05-20 00:00:36 +02:00
|
|
|
import techreborn.partSystem.IModPart;
|
|
|
|
import techreborn.partSystem.IPartProvider;
|
|
|
|
import techreborn.partSystem.ModPart;
|
|
|
|
import techreborn.partSystem.ModPartRegistry;
|
2015-04-20 21:08:14 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
public class QModPartFactory implements IPartFactory, IPartProvider {
|
2015-08-09 12:05:32 +02:00
|
|
|
@Override
|
|
|
|
public IPart createPart(String type, boolean client) {
|
|
|
|
for (ModPart modPart : ModPartRegistry.parts) {
|
|
|
|
if (modPart.getName().equals(type)) {
|
|
|
|
return new QModPart((ModPart) modPart.copy());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
2015-11-23 15:45:16 +01:00
|
|
|
EnumFacing dir = EnumFacing.getOrientation(face);
|
2015-08-09 12:05:32 +02:00
|
|
|
return MultipartCompatibility.placePartInWorld(part, world, new Vec3i(
|
|
|
|
x, y, z), dir, player, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isTileFromProvider(TileEntity tileEntity) {
|
|
|
|
return tileEntity instanceof TileMultipart;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IModPart getPartFromWorld(World world, Location location, String name) {
|
|
|
|
IPart part = MultipartCompatibility.getPart(world, location.getX(), location.getY(), location.getZ(), name);
|
|
|
|
if (part != null) {
|
|
|
|
if (part instanceof QModPart) {
|
|
|
|
return ((QModPart) part).iModPart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-10-05 18:39:45 +02:00
|
|
|
@Override
|
|
|
|
public void init() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
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) {
|
|
|
|
if (MultipartCompatibility.getPartHolder(world, location.getX(), location.getY(), location.getZ()) == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return MultipartCompatibility.getPart(world, location.getX(), location.getY(), location.getZ(), name) == null;
|
|
|
|
}
|
2015-04-20 21:08:14 +02:00
|
|
|
}
|