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;
|
2015-04-20 21:08:14 +02:00
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.world.World;
|
2015-11-23 15:45:16 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2015-04-20 21:08:14 +02:00
|
|
|
import uk.co.qmunity.lib.ref.Names;
|
|
|
|
|
|
|
|
public class ModPartItem extends Item {
|
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
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_) {
|
2015-11-23 15:45:16 +01:00
|
|
|
EnumFacing dir = EnumFacing.getOrientation(face);
|
2015-08-09 12:05:32 +02:00
|
|
|
if (ModPartUtils.hasPart(world, x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, modPart.getName())) {
|
|
|
|
x = x + dir.offsetX;
|
|
|
|
y = y + dir.offsetY;
|
|
|
|
z = z + dir.offsetZ;
|
|
|
|
}
|
|
|
|
if (ModPartUtils.hasPart(world, x, y, z, modPart.getName())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (ModPartRegistry.masterProvider != null) {
|
|
|
|
if (ModPartRegistry.masterProvider.placePart(item, player,
|
|
|
|
world, x, y, z, face, x_, y_, z_, (ModPart) modPart.copy())) {
|
|
|
|
player.swingItem();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
for (IPartProvider partProvider : ModPartRegistry.providers) {
|
|
|
|
if (partProvider.placePart(item, player, world, x, y, z, face, x_, y_, z_, (ModPart) modPart.copy())) {
|
|
|
|
player.swingItem();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUnlocalizedName(ItemStack stack) {
|
|
|
|
return modPart.getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
public ModPart getModPart() {
|
|
|
|
return modPart;
|
|
|
|
}
|
2015-04-20 21:08:14 +02:00
|
|
|
}
|