Removed /bop tpbiome as Vanilla added its own command

This commit is contained in:
Adubbz 2020-07-05 22:40:12 +10:00
parent a2b377f2d5
commit e31d46c2af
4 changed files with 0 additions and 192 deletions

View File

@ -1,24 +0,0 @@
/*******************************************************************************
* Copyright 2014-2019, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.common.command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.command.CommandSource;
public class BOPCommand
{
public BOPCommand(CommandDispatcher<CommandSource> dispatcher)
{
dispatcher.register(
LiteralArgumentBuilder.<CommandSource>literal("bop")
.requires(cs->cs.hasPermission(2))
.then(CommandTpBiome.register())
);
}
}

View File

@ -1,57 +0,0 @@
/*******************************************************************************
* Copyright 2014-2019, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.common.command;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.command.CommandSource;
import net.minecraft.command.ISuggestionProvider;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.biome.Biome;
import java.util.concurrent.CompletableFuture;
public class BiomeArgument implements ArgumentType<Biome>
{
public static final DynamicCommandExceptionType INVALID_BIOME_EXCEPTION = new DynamicCommandExceptionType((biome) -> {
return new TranslationTextComponent("argument.biomesoplenty.biome.invalid", new Object[]{biome});
});
public static BiomeArgument createArgument()
{
return new BiomeArgument();
}
public static Biome getValue(CommandContext<CommandSource> context, String name) throws CommandSyntaxException
{
return context.getArgument(name, Biome.class);
}
@Override
public Biome parse(StringReader reader) throws CommandSyntaxException
{
ResourceLocation location = ResourceLocation.read(reader);
return Registry.BIOME.getOptional(location).orElseThrow(() ->
{
return INVALID_BIOME_EXCEPTION.create(location);
});
}
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder suggestionsBuilder)
{
return ISuggestionProvider.suggestResource(Registry.BIOME.keySet(), suggestionsBuilder);
}
}

View File

@ -1,101 +0,0 @@
/*******************************************************************************
* Copyright 2014-2019, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.common.command;
import biomesoplenty.common.util.biome.BiomeUtil;
import biomesoplenty.common.util.block.BlockUtil;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.block.BlockState;
import net.minecraft.block.material.Material;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.IChunk;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class CommandTpBiome
{
private static final ExecutorService TP_BIOME_THREAD = Executors.newFixedThreadPool(1);
static ArgumentBuilder<CommandSource, ?> register()
{
return Commands.literal("tpbiome")
.then(Commands.argument("biome", BiomeArgument.createArgument())
.executes(ctx -> {
ServerPlayerEntity player = ctx.getSource().getPlayerOrException();
TP_BIOME_THREAD.execute(() -> {
try
{
findTeleportBiome(ctx.getSource(), player, BiomeArgument.getValue(ctx, "biome"));
}
catch (CommandSyntaxException e)
{
e.printStackTrace();
}
});
return 1;
}));
}
private static int findTeleportBiome(CommandSource cs, ServerPlayerEntity player, Biome biome)
{
World world = player.level;
BlockPos closestBiomePos = biome == null ? null : BiomeUtil.spiralOutwardsLookingForBiome(world, biome, player.getX(), player.getZ());
String biomeName = biome != null && world.isClientSide ? biome.getName().toString() : biome.getRegistryName().toString();
if (closestBiomePos != null)
{
double x = (double)closestBiomePos.getX();
double y = (double) BlockUtil.getTopSolidOrLiquidBlock(world, closestBiomePos.getX(), closestBiomePos.getZ()).getY();
double z = (double)closestBiomePos.getZ();
if (!world.dimensionType().natural())
{
y = (double)getTopBlockNonOverworld(world, closestBiomePos).getY();
}
player.connection.teleport(x, y, z, player.yRot, player.xRot);
cs.sendSuccess(new TranslationTextComponent("commands.biomesoplenty.tpbiome.success", player.getName(), biomeName, x, y, z), true);
}
else
{
cs.sendSuccess(new TranslationTextComponent("commands.biomesoplenty.tpbiome.error", biomeName), true);
}
return 1;
}
public static BlockPos getTopBlockNonOverworld(World world, BlockPos pos)
{
IChunk chunk = world.getChunk(pos);
BlockPos blockpos;
BlockPos blockpos1;
BlockPos blockpos2 = new BlockPos(pos.getX(), chunk.getHighestSectionPosition() + 16, pos.getZ());
for (blockpos = blockpos2; blockpos.getY() >= 0; blockpos = blockpos1)
{
blockpos1 = blockpos.below();
BlockState state = chunk.getBlockState(blockpos1);
if (!state.getMaterial().blocksMotion() && !world.isEmptyBlock(blockpos1.below()) && state.getMaterial() != Material.LEAVES)
{
return blockpos1;
}
}
return blockpos2;
}
}

View File

@ -8,15 +8,12 @@
package biomesoplenty.core;
import biomesoplenty.common.command.BOPCommand;
import biomesoplenty.init.*;
import net.minecraft.server.dedicated.ServerProperties;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@ -40,7 +37,6 @@ public class BiomesOPlenty
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::commonSetup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::loadComplete);
MinecraftForge.EVENT_BUS.addListener(this::serverStarting);
ModBiomes.setup();
ModConfig.setup();
@ -62,10 +58,4 @@ public class BiomesOPlenty
//GenLayerVisualizer.run();
ModCompatibility.setup();
}
public void serverStarting(FMLServerStartingEvent evt)
{
logger.info("Registering BoP commands...");
new BOPCommand(evt.getCommandDispatcher());
}
}