use of riskyken.armourersWorkshop.common.exception.SkinSaveException in project Armourers-Workshop by RiskyKen.
the class ArmourerWorldHelper method saveSkinFromWorld.
/**
* Converts blocks in the world into a skin class.
* @param world The world.
* @param skinProps The skin properties for this skin.
* @param skinType The type of skin to save.
* @param paintData Paint data for this skin.
* @param xCoord Armourers x location.
* @param yCoord Armourers y location.
* @param zCoord Armourers z location.
* @param directionDirection the armourer is facing.
* @return
* @throws InvalidCubeTypeException
* @throws SkinSaveException
*/
public static Skin saveSkinFromWorld(World world, SkinProperties skinProps, ISkinType skinType, int[] paintData, int xCoord, int yCoord, int zCoord, ForgeDirection direction) throws SkinSaveException {
ArrayList<SkinPart> parts = new ArrayList<SkinPart>();
if (skinType == SkinTypeRegistry.skinBlock) {
ISkinPartType partType = ((SkinBlock) SkinTypeRegistry.skinBlock).partBase;
if (SkinProperties.PROP_BLOCK_MULTIBLOCK.getValue(skinProps)) {
partType = ((SkinBlock) SkinTypeRegistry.skinBlock).partMultiblock;
}
SkinPart skinPart = saveArmourPart(world, partType, xCoord, yCoord, zCoord, direction, true);
if (skinPart != null) {
parts.add(skinPart);
}
} else {
for (int i = 0; i < skinType.getSkinParts().size(); i++) {
ISkinPartType partType = skinType.getSkinParts().get(i);
SkinPart skinPart = saveArmourPart(world, partType, xCoord, yCoord, zCoord, direction, true);
if (skinPart != null) {
parts.add(skinPart);
}
}
}
if (paintData != null) {
paintData = paintData.clone();
}
Skin skin = new Skin(skinProps, skinType, paintData, parts);
// Check if there are any blocks in the build guides.
if (skin.getParts().size() == 0 && !skin.hasPaintData()) {
throw new SkinSaveException("Nothing to save.", SkinSaveExceptionType.NO_DATA);
}
// Check if the skin has all needed parts.
for (int i = 0; i < skinType.getSkinParts().size(); i++) {
ISkinPartType partType = skinType.getSkinParts().get(i);
if (partType.isPartRequired()) {
boolean havePart = false;
for (int j = 0; j < skin.getPartCount(); j++) {
if (partType == skin.getParts().get(j).getPartType()) {
havePart = true;
break;
}
}
if (!havePart) {
throw new SkinSaveException("Skin is missing part " + partType.getPartName(), SkinSaveExceptionType.MISSING_PARTS);
}
}
}
// Check if the skin is not a seat and a bed.
if (SkinProperties.PROP_BLOCK_BED.getValue(skinProps) & SkinProperties.PROP_BLOCK_SEAT.getValue(skinProps)) {
throw new SkinSaveException("Skin can not be a bed and a seat.", SkinSaveExceptionType.BED_AND_SEAT);
}
// Check if multiblock is valid.
if (skinType == SkinTypeRegistry.skinBlock & SkinProperties.PROP_BLOCK_MULTIBLOCK.getValue(skinProps)) {
SkinPart testPart = saveArmourPart(world, ((SkinBlock) SkinTypeRegistry.skinBlock).partBase, xCoord, yCoord, zCoord, direction, true);
if (testPart == null) {
throw new SkinSaveException("Multiblock has no blocks in the yellow area.", SkinSaveExceptionType.INVALID_MULTIBLOCK);
}
}
return skin;
}
use of riskyken.armourersWorkshop.common.exception.SkinSaveException in project Armourers-Workshop by RiskyKen.
the class ArmourerWorldHelper method saveArmourPart.
private static SkinPart saveArmourPart(World world, ISkinPartType skinPart, int xCoord, int yCoord, int zCoord, ForgeDirection direction, boolean markerCheck) throws SkinSaveException {
int cubeCount = getNumberOfCubesInPart(world, xCoord, yCoord, zCoord, skinPart);
if (cubeCount < 1) {
return null;
}
SkinCubeData cubeData = new SkinCubeData();
cubeData.setCubeCount(cubeCount);
ArrayList<CubeMarkerData> markerBlocks = new ArrayList<CubeMarkerData>();
IRectangle3D buildSpace = skinPart.getBuildingSpace();
IPoint3D offset = skinPart.getOffset();
int i = 0;
for (int ix = 0; ix < buildSpace.getWidth(); ix++) {
for (int iy = 0; iy < buildSpace.getHeight(); iy++) {
for (int iz = 0; iz < buildSpace.getDepth(); iz++) {
int x = xCoord + ix + -offset.getX() + buildSpace.getX();
int y = yCoord + iy + -offset.getY();
int z = zCoord + iz + offset.getZ() + buildSpace.getZ();
int xOrigin = -ix + -buildSpace.getX();
int yOrigin = -iy + -buildSpace.getY();
int zOrigin = -iz + -buildSpace.getZ();
if (!world.isAirBlock(x, y, z)) {
Block block = world.getBlock(x, y, z);
if (CubeRegistry.INSTANCE.isBuildingBlock(block)) {
saveArmourBlockToList(world, x, y, z, xOrigin - 1, yOrigin - 1, -zOrigin, cubeData, i, markerBlocks, direction);
i++;
}
}
}
}
}
if (markerCheck) {
if (skinPart.getMinimumMarkersNeeded() > markerBlocks.size()) {
throw new SkinSaveException("Missing marker for part " + skinPart.getPartName(), SkinSaveExceptionType.MARKER_ERROR);
}
if (markerBlocks.size() > skinPart.getMaximumMarkersNeeded()) {
throw new SkinSaveException("Too many markers for part " + skinPart.getPartName(), SkinSaveExceptionType.MARKER_ERROR);
}
}
return new SkinPart(cubeData, skinPart, markerBlocks);
}
use of riskyken.armourersWorkshop.common.exception.SkinSaveException in project Armourers-Workshop by RiskyKen.
the class TileEntityArmourer method saveArmourItem.
/**
* Get blocks in the world and saved them onto an items NBT data.
* @param player The player that pressed the save button.
* @param name Custom name for the item.
*/
public void saveArmourItem(EntityPlayerMP player, String customName, String tags) {
if (getWorldObj().isRemote) {
return;
}
ItemStack stackInput = getStackInSlot(0);
ItemStack stackOutput = getStackInSlot(1);
if (stackInput == null) {
return;
}
if (stackOutput != null) {
return;
}
if (!(stackInput.getItem() instanceof ISkinHolder)) {
return;
}
ISkinHolder inputItem = (ISkinHolder) stackInput.getItem();
Skin armourItemData = null;
SkinProperties skinProps = new SkinProperties();
skinProps.setProperty(Skin.KEY_AUTHOR_NAME, player.getCommandSenderName());
if (player.getGameProfile() != null && player.getGameProfile().getId() != null) {
skinProps.setProperty(Skin.KEY_AUTHOR_UUID, player.getGameProfile().getId().toString());
}
skinProps.setProperty(Skin.KEY_CUSTOM_NAME, customName);
for (int i = 0; i < skinType.getProperties().size(); i++) {
SkinProperty skinProp = (SkinProperty) skinType.getProperties().get(i);
skinProp.setValue(skinProps, skinProp.getValue(this.skinProps));
}
try {
armourItemData = ArmourerWorldHelper.saveSkinFromWorld(worldObj, skinProps, skinType, paintData, xCoord, yCoord + HEIGHT_OFFSET, zCoord, direction);
} catch (SkinSaveException e) {
switch(e.getType()) {
case NO_DATA:
player.addChatMessage(new ChatComponentText(e.getMessage()));
break;
case MARKER_ERROR:
player.addChatMessage(new ChatComponentText(e.getMessage()));
break;
case MISSING_PARTS:
player.addChatMessage(new ChatComponentText(e.getMessage()));
break;
case BED_AND_SEAT:
player.addChatMessage(new ChatComponentText(e.getMessage()));
break;
case INVALID_MULTIBLOCK:
player.addChatMessage(new ChatComponentText(e.getMessage()));
break;
}
}
if (armourItemData == null) {
return;
}
CommonSkinCache.INSTANCE.addEquipmentDataToCache(armourItemData, (LibraryFile) null);
stackOutput = inputItem.makeStackForEquipment(armourItemData);
if (stackOutput == null) {
return;
}
this.decrStackSize(0, 1);
setInventorySlotContents(1, stackOutput);
}
Aggregations