cleanup of scarpet dependencies
This commit is contained in:
1 parent
fd93785fec
commit
75d94b0570
71 files changed
+1623
-1014
No files matched your search
@@ -1,15 +1,13 @@
|
||||
package carpet.script.utils;
|
||||
|
||||
import carpet.CarpetServer;
|
||||
import carpet.api.settings.CarpetRule;
|
||||
import carpet.api.settings.Validator;
|
||||
import carpet.script.CarpetScriptHost;
|
||||
import carpet.script.CarpetScriptServer;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.external.Carpet;
|
||||
import carpet.script.external.Vanilla;
|
||||
import carpet.script.value.MapValue;
|
||||
import carpet.script.value.StringValue;
|
||||
import carpet.script.value.Value;
|
||||
import carpet.utils.Messenger;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -36,6 +34,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A class used to save scarpet app store scripts to disk
|
||||
*/
|
||||
@@ -52,40 +52,15 @@ public class AppStoreManager
|
||||
*/
|
||||
private static String scarpetRepoLink = "https://api.github.com/repos/gnembon/scarpet/contents/programs/";
|
||||
|
||||
private record AppInfo(String name, String url, StoreNode source)
|
||||
public static void setScarpetRepoLink(@Nullable final String link)
|
||||
{
|
||||
APP_STORE_ROOT = AppStoreManager.StoreNode.folder(null, "");
|
||||
scarpetRepoLink = link;
|
||||
}
|
||||
|
||||
public static class ScarpetAppStoreValidator extends Validator<String>
|
||||
{
|
||||
@Override
|
||||
public String validate(final CommandSourceStack source, final CarpetRule<String> currentRule, String newValue, final String stringInput)
|
||||
{
|
||||
if (newValue.equals(currentRule.value()))
|
||||
{
|
||||
// Don't refresh the local repo if it's the same (world change), helps preventing hitting rate limits from github when
|
||||
// getting suggestions. Pending is a way to invalidate the cache when it gets old, and investigating api usage further
|
||||
return newValue;
|
||||
}
|
||||
APP_STORE_ROOT = StoreNode.folder(null, "");
|
||||
if (newValue.equalsIgnoreCase("none"))
|
||||
{
|
||||
scarpetRepoLink = null;
|
||||
return newValue;
|
||||
}
|
||||
if (newValue.endsWith("/"))
|
||||
{
|
||||
newValue = newValue.replaceAll("/$", "");
|
||||
}
|
||||
scarpetRepoLink = "https://api.github.com/repos/" + newValue + "/";
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description()
|
||||
{
|
||||
return "Appstore link should point to a valid github repository";
|
||||
}
|
||||
private record AppInfo(String name, String url, StoreNode source)
|
||||
{
|
||||
}
|
||||
|
||||
public static class StoreNode
|
||||
@@ -291,13 +266,13 @@ public class AppStoreManager
|
||||
}
|
||||
catch (final IOException e)
|
||||
{
|
||||
throw new CommandRuntimeException(Messenger.c("rb Failed to obtain app file content: " + e.getMessage()));
|
||||
throw new CommandRuntimeException(Carpet.Messenger_compose("rb Failed to obtain app file content: " + e.getMessage()));
|
||||
}
|
||||
if (!saveScriptToFile(source, path, nodeInfo.name(), code, false, useTrash))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
final boolean success = CarpetServer.scriptServer.addScriptHost(source, nodeInfo.name().replaceFirst("\\.sc$", ""), null, true, false, false, nodeInfo.source());
|
||||
final boolean success = Vanilla.MinecraftServer_getScriptServer(source.getServer()).addScriptHost(source, nodeInfo.name().replaceFirst("\\.sc$", ""), null, true, false, false, nodeInfo.source());
|
||||
return success ? 1 : 0;
|
||||
}
|
||||
|
||||
@@ -328,7 +303,7 @@ public class AppStoreManager
|
||||
}
|
||||
catch (final IOException e)
|
||||
{
|
||||
throw new CommandRuntimeException(Messenger.c("rb '" + appPath + "' is not a valid path to a scarpet app: " + e.getMessage()));
|
||||
throw new CommandRuntimeException(Carpet.Messenger_compose("rb '" + appPath + "' is not a valid path to a scarpet app: " + e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,7 +338,7 @@ public class AppStoreManager
|
||||
}
|
||||
Files.move(scriptLocation, trashPath);
|
||||
}
|
||||
Messenger.m(source, String.format("gi Note: replaced existing app '%s'" + (useTrash ? " (old moved to /trash folder)" : ""), appFileName));
|
||||
Carpet.Messenger_message(source, String.format("gi Note: replaced existing app '%s'" + (useTrash ? " (old moved to /trash folder)" : ""), appFileName));
|
||||
}
|
||||
final BufferedWriter writer = Files.newBufferedWriter(scriptLocation);
|
||||
writer.write(code);
|
||||
@@ -371,7 +346,7 @@ public class AppStoreManager
|
||||
}
|
||||
catch (final IOException e)
|
||||
{
|
||||
Messenger.m(source, "r Error while downloading app: " + e);
|
||||
Carpet.Messenger_message(source, "r Error while downloading app: " + e);
|
||||
CarpetScriptServer.LOG.warn("Error while downloading app", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package carpet.script.utils;
|
||||
|
||||
import carpet.fakes.BiomeInterface;
|
||||
import carpet.script.external.Vanilla;
|
||||
import carpet.script.value.ListValue;
|
||||
import carpet.script.value.NumericValue;
|
||||
import carpet.script.value.StringValue;
|
||||
@@ -30,7 +30,7 @@ public class BiomeInfo
|
||||
put("sky_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getSkyColor()));
|
||||
put("water_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getWaterColor()));
|
||||
put("water_fog_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getWaterFogColor()));
|
||||
put("humidity", (w, b) -> NumericValue.of(((BiomeInterface) (Object) b).getClimateSettings().downfall()));
|
||||
put("humidity", (w, b) -> NumericValue.of(Vanilla.Biome_getClimateSettings(b).downfall()));
|
||||
put("precipitation", (w, b) -> StringValue.of(b.getPrecipitationAt(new BlockPos(0, w.getSeaLevel(), 0)).name().toLowerCase(Locale.ROOT)));
|
||||
put("features", (w, b) -> {
|
||||
final Registry<ConfiguredFeature<?, ?>> registry = w.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package carpet.script.utils;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class EntityTools
|
||||
{
|
||||
/**
|
||||
* Not a replacement for living entity jump() - this barely is to allow other entities that can't jump in vanilla to 'jump'
|
||||
*
|
||||
* @param e
|
||||
*/
|
||||
public static void genericJump(final Entity e)
|
||||
{
|
||||
if (!e.isOnGround() && !e.isInWaterOrBubble() && !e.isInLava())
|
||||
{
|
||||
return;
|
||||
}
|
||||
final float m = e.level.getBlockState(e.blockPosition()).getBlock().getJumpFactor();
|
||||
final float g = e.level.getBlockState(new BlockPos(e.getX(), e.getBoundingBox().minY - 0.5000001D, e.getZ())).getBlock().getJumpFactor();
|
||||
final float jumpVelocityMultiplier = m == 1.0D ? g : m;
|
||||
final float jumpStrength = (0.42F * jumpVelocityMultiplier);
|
||||
final Vec3 vec3d = e.getDeltaMovement();
|
||||
e.setDeltaMovement(vec3d.x, jumpStrength, vec3d.z);
|
||||
if (e.isSprinting())
|
||||
{
|
||||
final float u = e.getYRot() * 0.017453292F; // yaw
|
||||
e.setDeltaMovement(e.getDeltaMovement().add((-Mth.sin(g) * 0.2F), 0.0D, (Mth.cos(u) * 0.2F)));
|
||||
}
|
||||
e.hasImpulse = true;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package carpet.script.utils;
|
||||
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.fakes.ServerWorldInterface;
|
||||
//import carpet.fakes.MinecraftServerInterface;
|
||||
//import carpet.fakes.ServerWorldInterface;
|
||||
import carpet.script.CarpetScriptServer;
|
||||
import carpet.script.value.ListValue;
|
||||
import carpet.script.value.Value;
|
||||
|
||||
@@ -0,0 +1,473 @@
|
||||
package carpet.script.utils;
|
||||
|
||||
import carpet.script.CarpetScriptServer;
|
||||
import carpet.script.external.Vanilla;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderGetter;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.worldgen.Pools;
|
||||
import net.minecraft.data.worldgen.ProcessorLists;
|
||||
import net.minecraft.data.worldgen.placement.PlacementUtils;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerChunkCache;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.tags.BiomeTags;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.util.valueproviders.ConstantInt;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.chunk.ChunkGeneratorStructureState;
|
||||
import net.minecraft.world.level.levelgen.GenerationStep;
|
||||
import net.minecraft.world.level.levelgen.RandomState;
|
||||
import net.minecraft.world.level.levelgen.VerticalAnchor;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.level.levelgen.feature.Feature;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.SimpleRandomFeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.featuresize.TwoLayersFeatureSize;
|
||||
import net.minecraft.world.level.levelgen.feature.foliageplacers.BlobFoliagePlacer;
|
||||
import net.minecraft.world.level.levelgen.feature.foliageplacers.FancyFoliagePlacer;
|
||||
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
|
||||
import net.minecraft.world.level.levelgen.heightproviders.ConstantHeight;
|
||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureType;
|
||||
import net.minecraft.world.level.levelgen.structure.TerrainAdjustment;
|
||||
import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElement;
|
||||
import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool;
|
||||
import net.minecraft.world.level.levelgen.feature.treedecorators.BeehiveDecorator;
|
||||
import net.minecraft.world.level.levelgen.feature.trunkplacers.FancyTrunkPlacer;
|
||||
import net.minecraft.world.level.levelgen.feature.trunkplacers.StraightTrunkPlacer;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureStart;
|
||||
import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement;
|
||||
import net.minecraft.world.level.levelgen.structure.structures.JigsawStructure;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorList;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class FeatureGenerator
|
||||
{
|
||||
@Nullable
|
||||
public static synchronized Boolean plop(final String featureName, final ServerLevel world, final BlockPos pos)
|
||||
{
|
||||
final Function<ServerLevel, Thing> custom = featureMap.get(featureName);
|
||||
if (custom != null)
|
||||
{
|
||||
return custom.apply(world).plop(world, pos);
|
||||
}
|
||||
final ResourceLocation id = new ResourceLocation(featureName);
|
||||
final Structure structure = world.registryAccess().registryOrThrow(Registries.STRUCTURE).get(id);
|
||||
if (structure != null)
|
||||
{
|
||||
return plopAnywhere(structure, world, pos, world.getChunkSource().getGenerator(), false);
|
||||
}
|
||||
|
||||
final ConfiguredFeature<?, ?> configuredFeature = world.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).get(id);
|
||||
if (configuredFeature != null)
|
||||
{
|
||||
final ThreadLocal<Boolean> checks = Vanilla.skipGenerationChecks(world);
|
||||
checks.set(true);
|
||||
try
|
||||
{
|
||||
return configuredFeature.place(world, world.getChunkSource().getGenerator(), world.random, pos);
|
||||
}
|
||||
finally
|
||||
{
|
||||
checks.set(false);
|
||||
}
|
||||
}
|
||||
final Optional<StructureType<?>> structureType = world.registryAccess().registryOrThrow(Registries.STRUCTURE_TYPE).getOptional(id);
|
||||
if (structureType.isPresent())
|
||||
{
|
||||
final Structure configuredStandard = getDefaultFeature(structureType.get(), world, pos);
|
||||
if (configuredStandard != null)
|
||||
{
|
||||
return plopAnywhere(configuredStandard, world, pos, world.getChunkSource().getGenerator(), false);
|
||||
}
|
||||
}
|
||||
final Feature<?> feature = world.registryAccess().registryOrThrow(Registries.FEATURE).get(id);
|
||||
if (feature != null)
|
||||
{
|
||||
final ConfiguredFeature<?, ?> configuredStandard = getDefaultFeature(feature, world, pos, true);
|
||||
if (configuredStandard != null)
|
||||
{
|
||||
final ThreadLocal<Boolean> checks = Vanilla.skipGenerationChecks(world);
|
||||
checks.set(true);
|
||||
try
|
||||
{
|
||||
return configuredStandard.place(world, world.getChunkSource().getGenerator(), world.random, pos);
|
||||
}
|
||||
finally
|
||||
{
|
||||
checks.set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Structure resolveConfiguredStructure(final String name, final ServerLevel world, final BlockPos pos)
|
||||
{
|
||||
final ResourceLocation id = new ResourceLocation(name);
|
||||
final Structure configuredStructureFeature = world.registryAccess().registryOrThrow(Registries.STRUCTURE).get(id);
|
||||
if (configuredStructureFeature != null)
|
||||
{
|
||||
return configuredStructureFeature;
|
||||
}
|
||||
final StructureType<?> structureFeature = world.registryAccess().registryOrThrow(Registries.STRUCTURE_TYPE).get(id);
|
||||
if (structureFeature == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return getDefaultFeature(structureFeature, world, pos);
|
||||
}
|
||||
|
||||
public static synchronized Boolean plopGrid(final Structure structureFeature, final ServerLevel world, final BlockPos pos)
|
||||
{
|
||||
return plopAnywhere(structureFeature, world, pos, world.getChunkSource().getGenerator(), true);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface Thing
|
||||
{
|
||||
Boolean plop(ServerLevel world, BlockPos pos);
|
||||
}
|
||||
|
||||
private static Thing simplePlop(final ConfiguredFeature<?, ?> feature)
|
||||
{
|
||||
return (w, p) -> {
|
||||
final ThreadLocal<Boolean> checks = Vanilla.skipGenerationChecks(w);
|
||||
checks.set(true);
|
||||
try
|
||||
{
|
||||
return feature.place(w, w.getChunkSource().getGenerator(), w.random, p);
|
||||
}
|
||||
finally
|
||||
{
|
||||
checks.set(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static <FC extends FeatureConfiguration, F extends Feature<FC>> Thing simplePlop(final F feature, final FC config)
|
||||
{
|
||||
return simplePlop(new ConfiguredFeature<>(feature, config));
|
||||
}
|
||||
|
||||
private static Thing simpleTree(final TreeConfiguration config)
|
||||
{
|
||||
//config.ignoreFluidCheck();
|
||||
return simplePlop(new ConfiguredFeature<>(Feature.TREE, config));
|
||||
}
|
||||
|
||||
private static Thing spawnCustomStructure(final Structure structure)
|
||||
{
|
||||
return setupCustomStructure(structure, false);
|
||||
}
|
||||
|
||||
private static Thing setupCustomStructure(final Structure structure, final boolean wireOnly)
|
||||
{
|
||||
return (w, p) -> plopAnywhere(structure, w, p, w.getChunkSource().getGenerator(), wireOnly);
|
||||
}
|
||||
|
||||
private static Structure getDefaultFeature(final StructureType<?> structure, final ServerLevel world, final BlockPos pos)
|
||||
{
|
||||
// would be nice to have a way to grab structures of this type for position
|
||||
// TODO allow old types, like vaillage, or bastion
|
||||
final Holder<Biome> existingBiome = world.getBiome(pos);
|
||||
Structure result = null;
|
||||
for (final Structure confstr : world.registryAccess().registryOrThrow(Registries.STRUCTURE).entrySet().stream().
|
||||
filter(cS -> cS.getValue().type() == structure).map(Map.Entry::getValue).toList())
|
||||
{
|
||||
result = confstr;
|
||||
if (confstr.biomes().contains(existingBiome))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ConfiguredFeature<?, ?> getDefaultFeature(final Feature<?> feature, final ServerLevel world, final BlockPos pos, final boolean tryHard)
|
||||
{
|
||||
final List<HolderSet<PlacedFeature>> configuredStepFeatures = world.getBiome(pos).value().getGenerationSettings().features();
|
||||
for (final HolderSet<PlacedFeature> step : configuredStepFeatures)
|
||||
{
|
||||
for (final Holder<PlacedFeature> provider : step)
|
||||
{
|
||||
if (provider.value().feature().value().feature() == feature)
|
||||
{
|
||||
return provider.value().feature().value();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!tryHard)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return world.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).entrySet().stream().
|
||||
filter(cS -> cS.getValue().feature() == feature).
|
||||
findFirst().map(Map.Entry::getValue).orElse(null);
|
||||
}
|
||||
|
||||
public static <T extends FeatureConfiguration> StructureStart shouldStructureStartAt(final ServerLevel world, final BlockPos pos, final Structure structure, final boolean computeBox)
|
||||
{
|
||||
final ServerChunkCache chunkSource = world.getChunkSource();
|
||||
final RandomState seed = chunkSource.randomState();
|
||||
final ChunkGenerator generator = chunkSource.getGenerator();
|
||||
final ChunkGeneratorStructureState structureState = chunkSource.getGeneratorState();
|
||||
final List<StructurePlacement> structureConfig = structureState.getPlacementsForStructure(Holder.direct(structure));
|
||||
final ChunkPos chunkPos = new ChunkPos(pos);
|
||||
final boolean couldPlace = structureConfig.stream().anyMatch(p -> p.isStructureChunk(structureState, chunkPos.x, chunkPos.z));
|
||||
if (!couldPlace)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final HolderSet<Biome> structureBiomes = structure.biomes();
|
||||
|
||||
if (!computeBox)
|
||||
{
|
||||
//Holder<Biome> genBiome = generator.getBiomeSource().getNoiseBiome(QuartPos.fromBlock(pos.getX()), QuartPos.fromBlock(pos.getY()), QuartPos.fromBlock(pos.getZ()), seed.sampler());
|
||||
if (structure.findValidGenerationPoint(new Structure.GenerationContext(
|
||||
world.registryAccess(), generator, generator.getBiomeSource(),
|
||||
seed, world.getStructureManager(), world.getSeed(), chunkPos, world, structureBiomes::contains
|
||||
)).isPresent())
|
||||
{
|
||||
return StructureStart.INVALID_START;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final StructureStart filledStructure = structure.generate(
|
||||
world.registryAccess(), generator, generator.getBiomeSource(), seed, world.getStructureManager(),
|
||||
world.getSeed(), chunkPos, 0, world, structureBiomes::contains);
|
||||
if (filledStructure != null && filledStructure.isValid())
|
||||
{
|
||||
return filledStructure;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static TreeConfiguration.TreeConfigurationBuilder createTree(final Block block, final Block block2, final int i, final int j, final int k, final int l)
|
||||
{
|
||||
return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(block), new StraightTrunkPlacer(i, j, k), BlockStateProvider.simple(block2), new BlobFoliagePlacer(ConstantInt.of(l), ConstantInt.of(0), 3), new TwoLayersFeatureSize(1, 0, 1));
|
||||
}
|
||||
|
||||
public static final Map<String, Function<ServerLevel, Thing>> featureMap = new HashMap<>()
|
||||
{{
|
||||
|
||||
put("oak_bees", l -> simpleTree(createTree(Blocks.OAK_LOG, Blocks.OAK_LEAVES, 4, 2, 0, 2).ignoreVines().decorators(List.of(new BeehiveDecorator(1.00F))).build()));
|
||||
put("fancy_oak_bees", l -> simpleTree((new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(Blocks.OAK_LOG), new FancyTrunkPlacer(3, 11, 0), BlockStateProvider.simple(Blocks.OAK_LEAVES), new FancyFoliagePlacer(ConstantInt.of(2), ConstantInt.of(4), 4), new TwoLayersFeatureSize(0, 0, 0, OptionalInt.of(4)))).ignoreVines().decorators(List.of(new BeehiveDecorator(1.00F))).build()));
|
||||
put("birch_bees", l -> simpleTree(createTree(Blocks.BIRCH_LOG, Blocks.BIRCH_LEAVES, 5, 2, 0, 2).ignoreVines().decorators(List.of(new BeehiveDecorator(1.00F))).build()));
|
||||
|
||||
put("coral_tree", l -> simplePlop(Feature.CORAL_TREE, FeatureConfiguration.NONE));
|
||||
|
||||
put("coral_claw", l -> simplePlop(Feature.CORAL_CLAW, FeatureConfiguration.NONE));
|
||||
put("coral_mushroom", l -> simplePlop(Feature.CORAL_MUSHROOM, FeatureConfiguration.NONE));
|
||||
put("coral", l -> simplePlop(Feature.SIMPLE_RANDOM_SELECTOR, new SimpleRandomFeatureConfiguration(HolderSet.direct(
|
||||
PlacementUtils.inlinePlaced(Feature.CORAL_TREE, FeatureConfiguration.NONE),
|
||||
PlacementUtils.inlinePlaced(Feature.CORAL_CLAW, FeatureConfiguration.NONE),
|
||||
PlacementUtils.inlinePlaced(Feature.CORAL_MUSHROOM, FeatureConfiguration.NONE)
|
||||
))));
|
||||
put("bastion_remnant_units", l -> {
|
||||
final RegistryAccess regs = l.registryAccess();
|
||||
|
||||
final HolderGetter<StructureProcessorList> processorLists = regs.lookupOrThrow(Registries.PROCESSOR_LIST);
|
||||
final Holder<StructureProcessorList> bastionGenericDegradation = processorLists.getOrThrow(ProcessorLists.BASTION_GENERIC_DEGRADATION);
|
||||
|
||||
final HolderGetter<StructureTemplatePool> pools = regs.lookupOrThrow(Registries.TEMPLATE_POOL);
|
||||
final Holder<StructureTemplatePool> empty = pools.getOrThrow(Pools.EMPTY);
|
||||
|
||||
|
||||
return spawnCustomStructure(
|
||||
new JigsawStructure(new Structure.StructureSettings(
|
||||
l.registryAccess().registryOrThrow(Registries.BIOME).getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
|
||||
Map.of(),
|
||||
GenerationStep.Decoration.SURFACE_STRUCTURES,
|
||||
TerrainAdjustment.NONE
|
||||
),
|
||||
Holder.direct(new StructureTemplatePool(
|
||||
empty,
|
||||
ImmutableList.of(
|
||||
Pair.of(StructurePoolElement.single("bastion/units/air_base", bastionGenericDegradation), 1)
|
||||
),
|
||||
StructureTemplatePool.Projection.RIGID
|
||||
)),
|
||||
6,
|
||||
ConstantHeight.of(VerticalAnchor.absolute(33)),
|
||||
false
|
||||
)
|
||||
);
|
||||
});
|
||||
put("bastion_remnant_hoglin_stable", l -> {
|
||||
final RegistryAccess regs = l.registryAccess();
|
||||
|
||||
final HolderGetter<StructureProcessorList> processorLists = regs.lookupOrThrow(Registries.PROCESSOR_LIST);
|
||||
final Holder<StructureProcessorList> bastionGenericDegradation = processorLists.getOrThrow(ProcessorLists.BASTION_GENERIC_DEGRADATION);
|
||||
|
||||
final HolderGetter<StructureTemplatePool> pools = regs.lookupOrThrow(Registries.TEMPLATE_POOL);
|
||||
final Holder<StructureTemplatePool> empty = pools.getOrThrow(Pools.EMPTY);
|
||||
|
||||
return spawnCustomStructure(
|
||||
new JigsawStructure(new Structure.StructureSettings(
|
||||
l.registryAccess().registryOrThrow(Registries.BIOME).getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
|
||||
Map.of(),
|
||||
GenerationStep.Decoration.SURFACE_STRUCTURES,
|
||||
TerrainAdjustment.NONE
|
||||
),
|
||||
Holder.direct(new StructureTemplatePool(
|
||||
empty,
|
||||
ImmutableList.of(
|
||||
Pair.of(StructurePoolElement.single("bastion/hoglin_stable/air_base", bastionGenericDegradation), 1)
|
||||
),
|
||||
StructureTemplatePool.Projection.RIGID
|
||||
)),
|
||||
6,
|
||||
ConstantHeight.of(VerticalAnchor.absolute(33)),
|
||||
false
|
||||
)
|
||||
);
|
||||
});
|
||||
put("bastion_remnant_treasure", l -> {
|
||||
final RegistryAccess regs = l.registryAccess();
|
||||
|
||||
final HolderGetter<StructureProcessorList> processorLists = regs.lookupOrThrow(Registries.PROCESSOR_LIST);
|
||||
final Holder<StructureProcessorList> bastionGenericDegradation = processorLists.getOrThrow(ProcessorLists.BASTION_GENERIC_DEGRADATION);
|
||||
|
||||
final HolderGetter<StructureTemplatePool> pools = regs.lookupOrThrow(Registries.TEMPLATE_POOL);
|
||||
final Holder<StructureTemplatePool> empty = pools.getOrThrow(Pools.EMPTY);
|
||||
|
||||
return spawnCustomStructure(
|
||||
new JigsawStructure(new Structure.StructureSettings(
|
||||
l.registryAccess().registryOrThrow(Registries.BIOME).getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
|
||||
Map.of(),
|
||||
GenerationStep.Decoration.SURFACE_STRUCTURES,
|
||||
TerrainAdjustment.NONE
|
||||
),
|
||||
Holder.direct(new StructureTemplatePool(
|
||||
empty,
|
||||
ImmutableList.of(
|
||||
Pair.of(StructurePoolElement.single("bastion/treasure/big_air_full", bastionGenericDegradation), 1)
|
||||
),
|
||||
StructureTemplatePool.Projection.RIGID
|
||||
)),
|
||||
6,
|
||||
ConstantHeight.of(VerticalAnchor.absolute(33)),
|
||||
false
|
||||
)
|
||||
);
|
||||
});
|
||||
put("bastion_remnant_bridge", l -> {
|
||||
final RegistryAccess regs = l.registryAccess();
|
||||
|
||||
final HolderGetter<StructureProcessorList> processorLists = regs.lookupOrThrow(Registries.PROCESSOR_LIST);
|
||||
final Holder<StructureProcessorList> bastionGenericDegradation = processorLists.getOrThrow(ProcessorLists.BASTION_GENERIC_DEGRADATION);
|
||||
|
||||
final HolderGetter<StructureTemplatePool> pools = regs.lookupOrThrow(Registries.TEMPLATE_POOL);
|
||||
final Holder<StructureTemplatePool> empty = pools.getOrThrow(Pools.EMPTY);
|
||||
|
||||
return spawnCustomStructure(
|
||||
new JigsawStructure(new Structure.StructureSettings(
|
||||
l.registryAccess().registryOrThrow(Registries.BIOME).getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
|
||||
Map.of(),
|
||||
GenerationStep.Decoration.SURFACE_STRUCTURES,
|
||||
TerrainAdjustment.NONE
|
||||
),
|
||||
Holder.direct(new StructureTemplatePool(
|
||||
empty,
|
||||
ImmutableList.of(
|
||||
Pair.of(StructurePoolElement.single("bastion/bridge/starting_pieces/entrance_base", bastionGenericDegradation), 1)
|
||||
),
|
||||
StructureTemplatePool.Projection.RIGID
|
||||
)),
|
||||
6,
|
||||
ConstantHeight.of(VerticalAnchor.absolute(33)),
|
||||
false
|
||||
)
|
||||
);
|
||||
});
|
||||
}};
|
||||
|
||||
|
||||
public static boolean plopAnywhere(final Structure structure, final ServerLevel world, final BlockPos pos, final ChunkGenerator generator, final boolean wireOnly)
|
||||
{
|
||||
final ThreadLocal<Boolean> checks = Vanilla.skipGenerationChecks(world);
|
||||
checks.set(true);
|
||||
try
|
||||
{
|
||||
final StructureStart start = structure.generate(world.registryAccess(), generator, generator.getBiomeSource(), world.getChunkSource().randomState(), world.getStructureManager(), world.getSeed(), new ChunkPos(pos), 0, world, b -> true);
|
||||
if (start == StructureStart.INVALID_START)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
final RandomSource rand = RandomSource.create(world.getRandom().nextInt());
|
||||
final int j = pos.getX() >> 4;
|
||||
final int k = pos.getZ() >> 4;
|
||||
final long chId = ChunkPos.asLong(j, k);
|
||||
world.getChunk(j, k).setStartForStructure(structure, start);
|
||||
world.getChunk(j, k).addReferenceForStructure(structure, chId);
|
||||
|
||||
final BoundingBox box = start.getBoundingBox();
|
||||
|
||||
if (!wireOnly)
|
||||
{
|
||||
final Registry<Structure> registry3 = world.registryAccess().registryOrThrow(Registries.STRUCTURE);
|
||||
world.setCurrentlyGenerating(() -> {
|
||||
Objects.requireNonNull(structure);
|
||||
return registry3.getResourceKey(structure).map(Object::toString).orElseGet(structure::toString);
|
||||
});
|
||||
start.placeInChunk(world, world.structureManager(), generator, rand, box, new ChunkPos(j, k));
|
||||
}
|
||||
//structurestart.notifyPostProcessAt(new ChunkPos(j, k));
|
||||
final int i = Math.max(box.getXSpan(), box.getZSpan()) / 16 + 1;
|
||||
|
||||
//int i = getRadius();
|
||||
for (int k1 = j - i; k1 <= j + i; ++k1)
|
||||
{
|
||||
for (int l1 = k - i; l1 <= k + i; ++l1)
|
||||
{
|
||||
if (k1 == j && l1 == k)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (box.intersects(k1 << 4, l1 << 4, (k1 << 4) + 15, (l1 << 4) + 15))
|
||||
{
|
||||
world.getChunk(k1, l1).addReferenceForStructure(structure, chId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (final Exception booboo)
|
||||
{
|
||||
CarpetScriptServer.LOG.error("Unknown Exception while plopping structure: " + booboo, booboo);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
checks.set(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package carpet.script.utils;
|
||||
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.commands.arguments.ParticleArgument;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.particles.ParticleOptions;
|
||||
import net.minecraft.core.particles.ParticleType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ParticleParser
|
||||
{
|
||||
private static final Map<String, ParticleOptions> particleCache = new HashMap<>(); // we reset this on reloads, but probably need something better
|
||||
|
||||
private static ParticleOptions parseParticle(final String name, final HolderLookup<ParticleType<?>> lookup)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ParticleArgument.readParticle(new StringReader(name), lookup);
|
||||
}
|
||||
catch (final CommandSyntaxException e)
|
||||
{
|
||||
throw new IllegalArgumentException("No such particle: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
public static ParticleOptions getEffect(final String name, final HolderLookup<ParticleType<?>> lookup)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return particleCache.computeIfAbsent(name, particle -> parseParticle(particle, lookup));
|
||||
}
|
||||
|
||||
public static void resetCache()
|
||||
{
|
||||
particleCache.clear();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package carpet.script.utils;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.helpers.ParticleDisplay;
|
||||
import carpet.network.ServerNetworkHandler;
|
||||
import carpet.script.CarpetScriptServer;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.exception.ThrowStatement;
|
||||
import carpet.script.exception.Throwables;
|
||||
import carpet.script.external.Carpet;
|
||||
import carpet.script.external.Vanilla;
|
||||
import carpet.script.language.Sys;
|
||||
import carpet.script.utils.shapes.ShapeDirection;
|
||||
import carpet.script.value.AbstractListValue;
|
||||
@@ -149,7 +149,7 @@ public class ShapeDispatcher
|
||||
final List<ServerPlayer> alternativePlayers = new ArrayList<>();
|
||||
for (final ServerPlayer player : players)
|
||||
{
|
||||
(ServerNetworkHandler.isValidCarpetPlayer(player) ? clientPlayers : alternativePlayers).add(player);
|
||||
(Carpet.isValidCarpetPlayer(player) ? clientPlayers : alternativePlayers).add(player);
|
||||
}
|
||||
if (!clientPlayers.isEmpty())
|
||||
{
|
||||
@@ -162,14 +162,14 @@ public class ShapeDispatcher
|
||||
{
|
||||
tagcount = 0;
|
||||
final Tag finalTag = tag;
|
||||
clientPlayers.forEach(p -> ServerNetworkHandler.sendCustomCommand(p, "scShapes", finalTag));
|
||||
clientPlayers.forEach(p -> Vanilla.sendScarpetShapesDataToPlayer(p, finalTag));
|
||||
tag = new ListTag();
|
||||
}
|
||||
}
|
||||
final Tag finalTag = tag;
|
||||
if (!tag.isEmpty())
|
||||
{
|
||||
clientPlayers.forEach(p -> ServerNetworkHandler.sendCustomCommand(p, "scShapes", finalTag));
|
||||
clientPlayers.forEach(p -> Vanilla.sendScarpetShapesDataToPlayer(p, finalTag));
|
||||
}
|
||||
}
|
||||
if (!alternativePlayers.isEmpty())
|
||||
@@ -184,7 +184,7 @@ public class ShapeDispatcher
|
||||
{
|
||||
try
|
||||
{
|
||||
return ParticleDisplay.getEffect(name, regs.lookupOrThrow(Registries.PARTICLE_TYPE));
|
||||
return ParticleParser.getEffect(name, regs.lookupOrThrow(Registries.PARTICLE_TYPE));
|
||||
}
|
||||
catch (final IllegalArgumentException e)
|
||||
{
|
||||
@@ -239,7 +239,7 @@ public class ShapeDispatcher
|
||||
final Param decoder = Param.of.get(key);
|
||||
if (decoder == null)
|
||||
{
|
||||
CarpetSettings.LOG.info("Unknown parameter for shape: " + key);
|
||||
CarpetScriptServer.LOG.info("Unknown parameter for shape: " + key);
|
||||
return null;
|
||||
}
|
||||
final Value decodedValue = decoder.decode(tag.get(key), level);
|
||||
@@ -248,13 +248,13 @@ public class ShapeDispatcher
|
||||
final Value shapeValue = options.get("shape");
|
||||
if (shapeValue == null)
|
||||
{
|
||||
CarpetSettings.LOG.info("Shape id missing in " + String.join(", ", tag.getAllKeys()));
|
||||
CarpetScriptServer.LOG.info("Shape id missing in " + String.join(", ", tag.getAllKeys()));
|
||||
return null;
|
||||
}
|
||||
final BiFunction<Map<String, Value>, RegistryAccess, ExpiringShape> factory = ExpiringShape.shapeProviders.get(shapeValue.getString());
|
||||
if (factory == null)
|
||||
{
|
||||
CarpetSettings.LOG.info("Unknown shape: " + shapeValue.getString());
|
||||
CarpetScriptServer.LOG.info("Unknown shape: " + shapeValue.getString());
|
||||
return null;
|
||||
}
|
||||
try
|
||||
@@ -263,7 +263,7 @@ public class ShapeDispatcher
|
||||
}
|
||||
catch (final InternalExpressionException exc)
|
||||
{
|
||||
CarpetSettings.LOG.info(exc.getMessage());
|
||||
CarpetScriptServer.LOG.info(exc.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -2022,7 +2022,7 @@ public class ShapeDispatcher
|
||||
new NumericValue(e.getZ())
|
||||
);
|
||||
}
|
||||
CarpetSettings.LOG.error("Value: " + value.getString());
|
||||
CarpetScriptServer.LOG.error("Value: " + value.getString());
|
||||
throw new InternalExpressionException("'" + p.id + "' requires a triple, block or entity to indicate position");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package carpet.script.utils;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.mixins.ShulkerBoxAccessMixin;
|
||||
import carpet.script.CarpetScriptServer;
|
||||
import carpet.script.external.Carpet;
|
||||
import carpet.script.external.VanillaClient;
|
||||
import carpet.script.utils.shapes.ShapeDirection;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
@@ -82,7 +82,7 @@ public class ShapesRenderer
|
||||
|
||||
public void render(final PoseStack matrices, final Camera camera, final float partialTick)
|
||||
{
|
||||
final CarpetProfiler.ProfilerToken token = CarpetProfiler.start_section(null, "Scarpet client", CarpetProfiler.TYPE.GENERAL);
|
||||
final Runnable token = Carpet.startProfilerSection("Scarpet client");
|
||||
//Camera camera = this.client.gameRenderer.getCamera();
|
||||
final ClientLevel iWorld = this.client.level;
|
||||
final ResourceKey<Level> dimensionType = iWorld.dimension();
|
||||
@@ -163,17 +163,17 @@ public class ShapesRenderer
|
||||
RenderSystem.depthMask(true);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
CarpetProfiler.end_current_section(token);
|
||||
token.run();
|
||||
}
|
||||
|
||||
public void addShapes(final ListTag tag)
|
||||
{
|
||||
final CarpetProfiler.ProfilerToken token = CarpetProfiler.start_section(null, "Scarpet client", CarpetProfiler.TYPE.GENERAL);
|
||||
final Runnable token = Carpet.startProfilerSection("Scarpet client");
|
||||
for (int i = 0, count = tag.size(); i < count; i++)
|
||||
{
|
||||
addShape(tag.getCompound(i));
|
||||
}
|
||||
CarpetProfiler.end_current_section(token);
|
||||
token.run();
|
||||
}
|
||||
|
||||
public void addShape(final CompoundTag tag)
|
||||
@@ -187,7 +187,7 @@ public class ShapesRenderer
|
||||
shapeFactory = renderedShapes.get(tag.getString("shape"));
|
||||
if (shapeFactory == null)
|
||||
{
|
||||
CarpetSettings.LOG.info("Unrecognized shape: " + tag.getString("shape"));
|
||||
CarpetScriptServer.LOG.info("Unrecognized shape: " + tag.getString("shape"));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -217,11 +217,11 @@ public class ShapesRenderer
|
||||
|
||||
public void renewShapes()
|
||||
{
|
||||
final CarpetProfiler.ProfilerToken token = CarpetProfiler.start_section(null, "Scarpet client", CarpetProfiler.TYPE.GENERAL);
|
||||
final Runnable token = Carpet.startProfilerSection("Scarpet client");
|
||||
shapes.values().forEach(el -> el.values().forEach(shape -> shape.expiryTick++));
|
||||
labels.values().forEach(el -> el.values().forEach(shape -> shape.expiryTick++));
|
||||
|
||||
CarpetProfiler.end_current_section(token);
|
||||
token.run();
|
||||
}
|
||||
|
||||
public abstract static class RenderedShape<T extends ShapeDispatcher.ExpiringShape>
|
||||
@@ -468,7 +468,7 @@ public class ShapesRenderer
|
||||
poseStack.mulPose(direction.getRotation());
|
||||
poseStack.scale(1.0F, -1.0F, -1.0F);
|
||||
poseStack.translate(0.0, -1.0, 0.0);
|
||||
final ShulkerModel<?> model = ((ShulkerBoxAccessMixin) client.getBlockEntityRenderDispatcher().getRenderer(BlockEntity)).getModel();
|
||||
final ShulkerModel<?> model = VanillaClient.ShulkerBoxRenderer_model(client.getBlockEntityRenderDispatcher().getRenderer(shulkerBoxBlockEntity));
|
||||
final ModelPart modelPart = model.getLid();
|
||||
modelPart.setPos(0.0F, 24.0F - shulkerBoxBlockEntity.getProgress(f) * 0.5F * 16.0F, 0.0F);
|
||||
modelPart.yRot = 270.0F * shulkerBoxBlockEntity.getProgress(f) * (float) (Math.PI / 180.0);
|
||||
@@ -561,7 +561,7 @@ public class ShapesRenderer
|
||||
}
|
||||
catch (final ClassCastException ignored)
|
||||
{
|
||||
CarpetSettings.LOG.error("shape " + rshape.shape.getClass() + " cannot cast to a Label");
|
||||
CarpetScriptServer.LOG.error("shape " + rshape.shape.getClass() + " cannot cast to a Label");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package carpet.script.utils;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.script.external.Vanilla;
|
||||
import com.mojang.brigadier.ResultConsumer;
|
||||
import net.minecraft.commands.CommandSigningContext;
|
||||
import net.minecraft.commands.CommandSource;
|
||||
@@ -42,14 +42,14 @@ public class SnoopyCommandSource extends CommandSourceStack
|
||||
|
||||
public SnoopyCommandSource(final CommandSourceStack original, final Component[] error, final List<Component> chatOutput)
|
||||
{
|
||||
super(CommandSource.NULL, original.getPosition(), original.getRotation(), original.getLevel(), CarpetSettings.runPermissionLevel,
|
||||
super(CommandSource.NULL, original.getPosition(), original.getRotation(), original.getLevel(), Vanilla.MinecraftServer_getRunPermissionLevel(original.getServer()),
|
||||
original.getTextName(), original.getDisplayName(), original.getServer(), original.getEntity(), false,
|
||||
(ctx, succ, res) -> {
|
||||
}, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(original.getServer()));
|
||||
this.output = CommandSource.NULL;
|
||||
this.position = original.getPosition();
|
||||
this.world = original.getLevel();
|
||||
this.level = CarpetSettings.runPermissionLevel;
|
||||
this.level = Vanilla.MinecraftServer_getRunPermissionLevel(original.getServer());
|
||||
this.simpleName = original.getTextName();
|
||||
this.name = original.getDisplayName();
|
||||
this.server = original.getServer();
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package carpet.script.utils;
|
||||
|
||||
import carpet.CarpetServer;
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.api.settings.CarpetRule;
|
||||
import carpet.api.settings.RuleHelper;
|
||||
import carpet.script.CarpetContext;
|
||||
import carpet.script.CarpetScriptHost;
|
||||
import carpet.script.external.Carpet;
|
||||
import carpet.script.external.Vanilla;
|
||||
import carpet.script.value.BooleanValue;
|
||||
import carpet.script.value.EntityValue;
|
||||
import carpet.script.value.ListValue;
|
||||
@@ -14,10 +12,7 @@ import carpet.script.value.NumericValue;
|
||||
import carpet.script.value.StringValue;
|
||||
import carpet.script.value.Value;
|
||||
import carpet.script.value.ValueConversions;
|
||||
import carpet.api.settings.SettingsManager;
|
||||
import com.sun.management.OperatingSystemMXBean;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.world.level.GameRules;
|
||||
@@ -29,7 +24,6 @@ import net.minecraft.world.phys.Vec2;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -93,14 +87,14 @@ public class SystemInfo
|
||||
put("game_view_distance", c -> new NumericValue(c.server().getPlayerList().getViewDistance()));
|
||||
put("game_mod_name", c -> StringValue.of(c.server().getServerModName()));
|
||||
put("game_version", c -> StringValue.of(c.server().getServerVersion()));
|
||||
put("game_target", c -> StringValue.of(CarpetSettings.releaseTarget));
|
||||
put("game_target", c -> StringValue.of(Vanilla.MinecraftServer_getReleaseTarget(c.server())));
|
||||
put("game_protocol", c -> NumericValue.of(SharedConstants.getProtocolVersion()));
|
||||
put("game_major_target", c -> {
|
||||
final String[] vers = CarpetSettings.releaseTarget.split("\\.");
|
||||
final String[] vers = Vanilla.MinecraftServer_getReleaseTarget(c.server()).split("\\.");
|
||||
return NumericValue.of((vers.length > 1) ? Integer.parseInt(vers[1]) : 0);
|
||||
});
|
||||
put("game_minor_target", c -> {
|
||||
final String[] vers = CarpetSettings.releaseTarget.split("\\.");
|
||||
final String[] vers = Vanilla.MinecraftServer_getReleaseTarget(c.server()).split("\\.");
|
||||
return NumericValue.of((vers.length > 2) ? Integer.parseInt(vers[2]) : 0);
|
||||
});
|
||||
put("game_stable", c -> BooleanValue.of(SharedConstants.getCurrentVersion().isStable()));
|
||||
@@ -133,15 +127,8 @@ public class SystemInfo
|
||||
}
|
||||
return whitelist;
|
||||
});
|
||||
put("server_dev_environment", c -> BooleanValue.of(FabricLoader.getInstance().isDevelopmentEnvironment()));
|
||||
put("server_mods", c -> {
|
||||
final Map<Value, Value> ret = new HashMap<>();
|
||||
for (final ModContainer mod : FabricLoader.getInstance().getAllMods())
|
||||
{
|
||||
ret.put(new StringValue(mod.getMetadata().getId()), new StringValue(mod.getMetadata().getVersion().getFriendlyString()));
|
||||
}
|
||||
return MapValue.wrap(ret);
|
||||
});
|
||||
put("server_dev_environment", c -> BooleanValue.of(Vanilla.isDevelopmentEnvironment()));
|
||||
put("server_mods", c -> Vanilla.getServerMods(c.server()));
|
||||
put("server_last_tick_times", c -> {
|
||||
//assuming we are in the tick world section
|
||||
// might be off one tick when run in the off tasks or asynchronously.
|
||||
@@ -181,20 +168,7 @@ public class SystemInfo
|
||||
OperatingSystemMXBean.class);
|
||||
return new NumericValue(osBean.getProcessCpuLoad());
|
||||
});
|
||||
put("world_carpet_rules", c -> {
|
||||
final Collection<CarpetRule<?>> rules = CarpetServer.settingsManager.getCarpetRules();
|
||||
final MapValue carpetRules = new MapValue(Collections.emptyList());
|
||||
rules.forEach(rule -> carpetRules.put(new StringValue(rule.name()), new StringValue(RuleHelper.toRuleString(rule.value()))));
|
||||
CarpetServer.extensions.forEach(e -> {
|
||||
final SettingsManager manager = e.extensionSettingsManager();
|
||||
if (manager == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
manager.getCarpetRules().forEach(rule -> carpetRules.put(new StringValue(manager.identifier() + ":" + rule.name()), new StringValue(RuleHelper.toRuleString(rule.value()))));
|
||||
});
|
||||
return carpetRules;
|
||||
});
|
||||
put("world_carpet_rules", c -> Carpet.getAllCarpetRules());
|
||||
put("world_gamerules", c -> {
|
||||
final Map<Value, Value> rules = new HashMap<>();
|
||||
final GameRules gameRules = c.level().getGameRules();
|
||||
@@ -217,9 +191,7 @@ public class SystemInfo
|
||||
final Vec2 rotation = c.source().getRotation();
|
||||
return ListValue.of(new NumericValue(rotation.x), new NumericValue(rotation.y));
|
||||
});
|
||||
|
||||
put("scarpet_version", c -> StringValue.of(CarpetSettings.carpetVersion));
|
||||
|
||||
put("scarpet_version", c -> StringValue.of(Carpet.getCarpetVersion()));
|
||||
}};
|
||||
|
||||
public static Value get(final String what, final CarpetContext cc)
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package carpet.script.utils;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class Tracer
|
||||
{
|
||||
public static HitResult rayTrace(final Entity source, final float partialTicks, final double reach, final boolean fluids)
|
||||
{
|
||||
final BlockHitResult blockHit = rayTraceBlocks(source, partialTicks, reach, fluids);
|
||||
double maxSqDist = reach * reach;
|
||||
if (blockHit != null)
|
||||
{
|
||||
maxSqDist = blockHit.getLocation().distanceToSqr(source.getEyePosition(partialTicks));
|
||||
}
|
||||
final EntityHitResult entityHit = rayTraceEntities(source, partialTicks, reach, maxSqDist);
|
||||
return entityHit == null ? blockHit : entityHit;
|
||||
}
|
||||
|
||||
public static BlockHitResult rayTraceBlocks(final Entity source, final float partialTicks, final double reach, final boolean fluids)
|
||||
{
|
||||
final Vec3 pos = source.getEyePosition(partialTicks);
|
||||
final Vec3 rotation = source.getViewVector(partialTicks);
|
||||
final Vec3 reachEnd = pos.add(rotation.x * reach, rotation.y * reach, rotation.z * reach);
|
||||
return source.level.clip(new ClipContext(pos, reachEnd, ClipContext.Block.OUTLINE, fluids ?
|
||||
ClipContext.Fluid.ANY : ClipContext.Fluid.NONE, source));
|
||||
}
|
||||
|
||||
public static EntityHitResult rayTraceEntities(final Entity source, final float partialTicks, final double reach, final double maxSqDist)
|
||||
{
|
||||
final Vec3 pos = source.getEyePosition(partialTicks);
|
||||
final Vec3 reachVec = source.getViewVector(partialTicks).scale(reach);
|
||||
final AABB box = source.getBoundingBox().expandTowards(reachVec).inflate(1);
|
||||
return rayTraceEntities(source, pos, pos.add(reachVec), box, e -> !e.isSpectator() && e.isPickable(), maxSqDist);
|
||||
}
|
||||
|
||||
public static EntityHitResult rayTraceEntities(final Entity source, final Vec3 start, final Vec3 end, final AABB box, final Predicate<Entity> predicate, final double maxSqDistance)
|
||||
{
|
||||
final Level world = source.level;
|
||||
double targetDistance = maxSqDistance;
|
||||
Entity target = null;
|
||||
Vec3 targetHitPos = null;
|
||||
for (final Entity current : world.getEntities(source, box, predicate))
|
||||
{
|
||||
final AABB currentBox = current.getBoundingBox().inflate(current.getPickRadius());
|
||||
final Optional<Vec3> currentHit = currentBox.clip(start, end);
|
||||
if (currentBox.contains(start))
|
||||
{
|
||||
if (targetDistance >= 0)
|
||||
{
|
||||
target = current;
|
||||
targetHitPos = currentHit.orElse(start);
|
||||
targetDistance = 0;
|
||||
}
|
||||
}
|
||||
else if (currentHit.isPresent())
|
||||
{
|
||||
final Vec3 currentHitPos = currentHit.get();
|
||||
final double currentDistance = start.distanceToSqr(currentHitPos);
|
||||
if (currentDistance < targetDistance || targetDistance == 0)
|
||||
{
|
||||
if (current.getRootVehicle() == source.getRootVehicle())
|
||||
{
|
||||
if (targetDistance == 0)
|
||||
{
|
||||
target = current;
|
||||
targetHitPos = currentHitPos;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
target = current;
|
||||
targetHitPos = currentHitPos;
|
||||
targetDistance = currentDistance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return target == null ? null : new EntityHitResult(target, targetHitPos);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package carpet.script.utils;
|
||||
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
//import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.script.external.Vanilla;
|
||||
//import net.fabricmc.api.EnvType;
|
||||
//import net.fabricmc.api.Environment;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
@@ -59,7 +60,7 @@ public class WorldTools
|
||||
}
|
||||
return region.hasChunk(chpos);
|
||||
}
|
||||
final Path regionsFolder = ((MinecraftServerInterface) world.getServer()).getCMSession().getDimensionPath(world.dimension()).resolve("region");
|
||||
final Path regionsFolder = Vanilla.MinecraftServer_storageSource(world.getServer()).getDimensionPath(world.dimension()).resolve("region");
|
||||
final Path regionPath = regionsFolder.resolve(currentRegionName);
|
||||
if (!regionPath.toFile().exists())
|
||||
{
|
||||
@@ -169,7 +170,7 @@ public class WorldTools
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
private static class NoopWorldGenerationProgressListener implements ChunkProgressListener
|
||||
{
|
||||
@Override
|
||||
@@ -182,7 +183,7 @@ public class WorldTools
|
||||
{
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
//@Environment(EnvType.CLIENT)
|
||||
@Override
|
||||
public void start()
|
||||
{
|
||||
@@ -195,4 +196,6 @@ public class WorldTools
|
||||
}
|
||||
|
||||
public static final ChunkProgressListener NOOP_LISTENER = new NoopWorldGenerationProgressListener();
|
||||
|
||||
*/
|
||||
}
|
||||
Reference in new issue
Block a user