use of com.ferreusveritas.dynamictrees.worldgen.JoCode in project DynamicTrees by DynamicTreesTeam.
the class CommandRotateJoCode method execute.
@Override
public void execute(World world, ICommandSender sender, String[] args) throws CommandException {
String code = "";
int turns = 0;
if (args.length < 2) {
throw new WrongUsageException("commands.dynamictrees.rotatejocode.usage");
}
for (int arg = 0; arg < args.length; arg++) {
switch(arg) {
case 1:
code = args[1];
break;
case 2:
try {
turns = Integer.parseInt(args[2]);
} catch (NumberFormatException e) {
throw new WrongUsageException("commands.dynamictrees.rotatejocode.turnserror", args[2]);
}
break;
}
}
if (code.isEmpty()) {
code = CommandSetTree.DEFAULTJOCODE;
}
turns = (3 - (turns % 4)) + 3;
code = new JoCode(code).rotate(EnumFacing.getHorizontal(turns)).toString();
sender.sendMessage((new TextComponentString(code)));
}
use of com.ferreusveritas.dynamictrees.worldgen.JoCode in project DynamicTrees by DynamicTreesTeam.
the class Staff method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack heldStack = player.getHeldItem(hand);
IBlockState clickedBlockState = world.getBlockState(pos);
if (!isReadOnly(heldStack)) {
Species species = TreeHelper.getBestGuessSpecies(world, pos);
if (species.isValid()) {
setSpecies(heldStack, species);
if (!player.isSneaking()) {
EnumFacing playerFacing = player.getHorizontalFacing();
Optional<JoCode> joCode = TreeHelper.getJoCode(world, pos, playerFacing, species);
if (joCode.isPresent()) {
String code = joCode.get().toString();
setCode(heldStack, code);
if (world.isRemote) {
// Make sure this doesn't run on the server
// Put the code in the system clipboard to annoy everyone.
GuiScreen.setClipboardString(code);
}
}
}
return EnumActionResult.SUCCESS;
}
}
// Create a tree from right clicking on soil
Species species = getSpecies(heldStack);
if (species.isValid() && species.isAcceptableSoil(world, pos, clickedBlockState)) {
species.getJoCode(getCode(heldStack)).setCareful(true).generate(world, species, pos, world.getBiome(pos), player.getHorizontalFacing(), 8, SafeChunkBounds.ANY);
if (!player.isCreative()) {
if (hasMaxUses(heldStack)) {
if (decUses(heldStack)) {
// If the player is in creative this will have no effect.
heldStack.shrink(1);
}
} else {
// If the player is in creative this will have no effect.
heldStack.shrink(1);
}
}
return EnumActionResult.SUCCESS;
}
return EnumActionResult.FAIL;
}
Aggregations