[1.15] Reimplemented the ITeleporter interface (#6404)

This commit is contained in:
mcenderdragon authored and GitHub committed 2020-01-29 09:18:07 -08:00
1 parent 509a28efd3
commit 44d9fff2b4
10 files changed
+217 -21

No files matched your search

@@ -28,6 +28,8 @@ import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.util.ITeleporter;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
@@ -35,6 +37,7 @@ import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import java.util.Collection;
import java.util.function.Function;
public class CommandSetDimension
{
@@ -54,6 +57,15 @@ public class CommandSetDimension
);
}
private static final ITeleporter PORTALLESS = new ITeleporter()
{
@Override
public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity)
{
return repositionEntity.apply(false);
}
};
private static int execute(CommandSource sender, Collection<? extends Entity> entities, DimensionType dim, BlockPos pos) throws CommandSyntaxException
{
entities.removeIf(e -> !canEntityTeleport(e));
@@ -64,7 +76,7 @@ public class CommandSetDimension
// throw INVALID_DIMENSION.create(dim);
entities.stream().filter(e -> e.dimension == dim).forEach(e -> sender.sendFeedback(new TranslationTextComponent("commands.forge.setdim.invalid.nochange", e.getDisplayName().getFormattedText(), dim), true));
entities.stream().filter(e -> e.dimension != dim).forEach(e -> e.changeDimension(dim));
entities.stream().filter(e -> e.dimension != dim).forEach(e -> e.changeDimension(dim, PORTALLESS));
return 0;
}