use of riskyken.armourersWorkshop.common.skin.data.Skin in project Armourers-Workshop by RiskyKen.
the class CommandGiveSkin method processCommand.
@Override
public void processCommand(ICommandSender commandSender, String[] currentCommand) {
if (currentCommand.length < 3) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) currentCommand);
}
String playerName = currentCommand[1];
EntityPlayerMP player = getPlayer(commandSender, playerName);
if (player == null) {
return;
}
String skinName = currentCommand[2];
if (!skinName.substring(0, 1).equals("\"")) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
int usedCommands = 2;
if (!skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
for (int i = 3; i < currentCommand.length; i++) {
skinName += " " + currentCommand[i];
if (skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
usedCommands = i;
break;
}
}
}
ModLogger.log("usedCommands used: " + usedCommands);
ModLogger.log("total commands used: " + currentCommand.length);
if (!skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
skinName = skinName.replace("\"", "");
SkinDye skinDye = new SkinDye();
for (int i = usedCommands + 1; i < currentCommand.length; i++) {
String dyeCommand = currentCommand[i];
ModLogger.log("Command dye: " + dyeCommand);
if (!dyeCommand.contains("-")) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
String[] commandSplit = dyeCommand.split("-");
if (commandSplit.length != 2) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
int dyeIndex = parseIntBounded(commandSender, commandSplit[0], 1, 8) - 1;
String dye = commandSplit[1];
if (dye.startsWith("#") && dye.length() == 7) {
// dye = dye.substring(2, 8);
if (isValidHex(dye)) {
Color dyeColour = Color.decode(dye);
int r = dyeColour.getRed();
int g = dyeColour.getGreen();
int b = dyeColour.getBlue();
skinDye.addDye(dyeIndex, new byte[] { (byte) r, (byte) g, (byte) b, (byte) 255 });
} else {
throw new WrongUsageException("commands.armourers.invalidDyeFormat", (Object) dye);
}
} else if (dye.length() >= 5 & dye.contains(",")) {
String[] dyeValues = dye.split(",");
if (dyeValues.length != 3) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
int r = parseIntBounded(commandSender, dyeValues[0], 0, 255);
int g = parseIntBounded(commandSender, dyeValues[1], 0, 255);
int b = parseIntBounded(commandSender, dyeValues[2], 0, 255);
skinDye.addDye(dyeIndex, new byte[] { (byte) r, (byte) g, (byte) b, (byte) 255 });
} else {
throw new WrongUsageException("commands.armourers.invalidDyeFormat", (Object) dye);
}
}
LibraryFile libraryFile = new LibraryFile(skinName);
Skin skin = SkinIOUtils.loadSkinFromLibraryFile(libraryFile);
if (skin == null) {
throw new WrongUsageException("commands.armourers.fileNotFound", (Object) skinName);
}
try {
skin.lightHash();
} catch (Exception e) {
ModLogger.log(Level.ERROR, String.format("Unable to create ID for file %s.", libraryFile.toString()));
return;
}
CommonSkinCache.INSTANCE.addEquipmentDataToCache(skin, libraryFile);
SkinIdentifier skinIdentifier = new SkinIdentifier(0, libraryFile, 0, skin.getSkinType());
ItemStack skinStack = SkinNBTHelper.makeEquipmentSkinStack(new SkinPointer(skinIdentifier, skinDye));
EntityItem entityItem = player.dropPlayerItemWithRandomChoice(skinStack, false);
entityItem.delayBeforeCanPickup = 0;
entityItem.func_145797_a(player.getCommandSenderName());
}
use of riskyken.armourersWorkshop.common.skin.data.Skin in project Armourers-Workshop by RiskyKen.
the class CommandSetSkin method processCommand.
@Override
public void processCommand(ICommandSender commandSender, String[] currentCommand) {
if (currentCommand.length < 3) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) currentCommand);
}
String playerName = currentCommand[1];
EntityPlayerMP player = getPlayer(commandSender, playerName);
if (player == null) {
return;
}
int slotNum = 0;
slotNum = parseIntBounded(commandSender, currentCommand[2], 1, 8);
String skinName = currentCommand[3];
if (!skinName.substring(0, 1).equals("\"")) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
int usedCommands = 3;
if (!skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
for (int i = 3; i < currentCommand.length; i++) {
skinName += " " + currentCommand[i];
if (skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
usedCommands = i;
break;
}
}
}
ModLogger.log("usedCommands used: " + usedCommands);
ModLogger.log("total commands used: " + currentCommand.length);
if (!skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
skinName = skinName.replace("\"", "");
SkinDye skinDye = new SkinDye();
for (int i = usedCommands + 1; i < currentCommand.length; i++) {
String dyeCommand = currentCommand[i];
ModLogger.log("Command dye: " + dyeCommand);
if (!dyeCommand.contains("-")) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
String[] commandSplit = dyeCommand.split("-");
if (commandSplit.length != 2) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
int dyeIndex = parseIntBounded(commandSender, commandSplit[0], 1, 8) - 1;
String dye = commandSplit[1];
if (dye.startsWith("#") && dye.length() == 7) {
// dye = dye.substring(2, 8);
if (isValidHex(dye)) {
Color dyeColour = Color.decode(dye);
int r = dyeColour.getRed();
int g = dyeColour.getGreen();
int b = dyeColour.getBlue();
skinDye.addDye(dyeIndex, new byte[] { (byte) r, (byte) g, (byte) b, (byte) 255 });
} else {
throw new WrongUsageException("commands.armourers.invalidDyeFormat", (Object) dye);
}
} else if (dye.length() >= 5 & dye.contains(",")) {
String[] dyeValues = dye.split(",");
if (dyeValues.length != 3) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
int r = parseIntBounded(commandSender, dyeValues[0], 0, 255);
int g = parseIntBounded(commandSender, dyeValues[1], 0, 255);
int b = parseIntBounded(commandSender, dyeValues[2], 0, 255);
skinDye.addDye(dyeIndex, new byte[] { (byte) r, (byte) g, (byte) b, (byte) 255 });
} else {
throw new WrongUsageException("commands.armourers.invalidDyeFormat", (Object) dye);
}
}
LibraryFile libraryFile = new LibraryFile(skinName);
Skin skin = SkinIOUtils.loadSkinFromLibraryFile(libraryFile);
if (skin == null) {
throw new WrongUsageException("commands.armourers.fileNotFound", (Object) skinName);
}
try {
skin.lightHash();
} catch (Exception e) {
ModLogger.log(Level.ERROR, String.format("Unable to create ID for file %s.", libraryFile.toString()));
return;
}
CommonSkinCache.INSTANCE.addEquipmentDataToCache(skin, libraryFile);
SkinIdentifier skinIdentifier = new SkinIdentifier(0, libraryFile, 0, skin.getSkinType());
ItemStack skinStack = SkinNBTHelper.makeEquipmentSkinStack(new SkinPointer(skinIdentifier, skinDye));
ExPropsPlayerSkinData.get(player).setEquipmentStack(skinStack, slotNum - 1);
}
use of riskyken.armourersWorkshop.common.skin.data.Skin in project Armourers-Workshop by RiskyKen.
the class BlockSkinnable method getCollisionBoundingBoxFromPool.
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
Skin skin = getSkin(world, x, y, z);
if (skin != null) {
if (SkinProperties.PROP_BLOCK_NO_COLLISION.getValue(skin.getProperties())) {
return null;
}
}
setBlockBoundsBasedOnState(world, x, y, z);
return super.getCollisionBoundingBoxFromPool(world, x, y, z);
}
use of riskyken.armourersWorkshop.common.skin.data.Skin in project Armourers-Workshop by RiskyKen.
the class BlockSkinnable method onBlockActivated.
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float xHit, float yHit, float zHit) {
Skin skin = getSkin(world, x, y, z);
TileEntitySkinnable te = getTileEntity(world, x, y, z);
if (te == null) {
return false;
}
TileEntitySkinnable parentTe = te.getParent();
if (parentTe == null) {
return false;
}
if (parentTe.hasLinkedBlock()) {
BlockLocation loc = parentTe.getLinkedBlock();
Block block = world.getBlock(loc.x, loc.y, loc.z);
if (!(block instanceof BlockSkinnable)) {
return block.onBlockActivated(world, loc.x, loc.y, loc.z, player, side, xHit, yHit, zHit);
}
}
if (skin == null) {
return false;
}
if (SkinProperties.PROP_BLOCK_SEAT.getValue(skin.getProperties())) {
return sitOnSeat(world, parentTe.xCoord, parentTe.yCoord, parentTe.zCoord, player, skin);
}
if (SkinProperties.PROP_BLOCK_BED.getValue(skin.getProperties())) {
// return sleepInBed(world, parentTe.xCoord, parentTe.yCoord, parentTe.zCoord, player, skin, te.getRotation(), te);
}
if (SkinProperties.PROP_BLOCK_INVENTORY.getValue(skin.getProperties()) | SkinProperties.PROP_BLOCK_ENDER_INVENTORY.getValue(skin.getProperties())) {
if (!world.isRemote) {
FMLNetworkHandler.openGui(player, ArmourersWorkshop.instance, LibGuiIds.SKINNABLE, world, parentTe.xCoord, parentTe.yCoord, parentTe.zCoord);
}
return true;
}
return false;
}
Aggregations