Migrate the Carpet codebase to Mojang Mappings

This commit is contained in:
altrisi committed 2022-01-24 20:33:16 +01:00
1 parent a1a2488bc3
commit 06af9ce8b1
346 files changed
+8353 -8492

No files matched your search

+208 -210
View File
@@ -1,290 +1,288 @@
package carpet.utils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.block.MapColor;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.ai.NoPenaltyTargeting;
import net.minecraft.entity.ai.goal.WanderAroundGoal;
import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.entity.mob.PathAwareEntity;
import net.minecraft.entity.mob.ZombifiedPiglinEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.text.BaseText;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.LightType;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.ai.goal.RandomStrollGoal;
import net.minecraft.world.entity.ai.util.DefaultRandomPos;
import net.minecraft.world.entity.monster.ZombifiedPiglin;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.Vec3;
public class BlockInfo
{
public static final Map<BlockSoundGroup, String> soundName = new HashMap<BlockSoundGroup, String>() {{
put(BlockSoundGroup.WOOD, "wood" );
put(BlockSoundGroup.GRAVEL, "gravel");
put(BlockSoundGroup.GRASS, "grass" );
put(BlockSoundGroup.LILY_PAD, "lily_pad");
put(BlockSoundGroup.STONE, "stone" );
put(BlockSoundGroup.METAL, "metal" );
put(BlockSoundGroup.GLASS , "glass" );
put(BlockSoundGroup.WOOL , "wool" );
put(BlockSoundGroup.SAND , "sand" );
put(BlockSoundGroup.SNOW , "snow" );
put(BlockSoundGroup.POWDER_SNOW , "powder_snow" );
put(BlockSoundGroup.LADDER, "ladder");
put(BlockSoundGroup.ANVIL , "anvil" );
put(BlockSoundGroup.SLIME , "slime" );
put(BlockSoundGroup.HONEY , "honey" );
put(BlockSoundGroup.WET_GRASS , "sea_grass" );
put(BlockSoundGroup.CORAL , "coral" );
put(BlockSoundGroup.BAMBOO , "bamboo" );
put(BlockSoundGroup.BAMBOO_SAPLING , "shoots" );
put(BlockSoundGroup.SCAFFOLDING , "scaffolding" );
put(BlockSoundGroup.SWEET_BERRY_BUSH , "berry" );
put(BlockSoundGroup.CROP , "crop" );
put(BlockSoundGroup.STEM , "stem" );
put(BlockSoundGroup.VINE , "vine" );
put(BlockSoundGroup.NETHER_WART , "wart" );
put(BlockSoundGroup.LANTERN , "lantern" );
put(BlockSoundGroup.NETHER_STEM, "fungi_stem");
put(BlockSoundGroup.NYLIUM, "nylium");
put(BlockSoundGroup.FUNGUS, "fungus");
put(BlockSoundGroup.ROOTS, "roots");
put(BlockSoundGroup.SHROOMLIGHT, "shroomlight");
put(BlockSoundGroup.WEEPING_VINES, "weeping_vine");
put(BlockSoundGroup.WEEPING_VINES_LOW_PITCH, "twisting_vine");
put(BlockSoundGroup.SOUL_SAND, "soul_sand");
put(BlockSoundGroup.SOUL_SOIL, "soul_soil");
put(BlockSoundGroup.BASALT, "basalt");
put(BlockSoundGroup.WART_BLOCK, "wart");
put(BlockSoundGroup.NETHERRACK, "netherrack");
put(BlockSoundGroup.NETHER_BRICKS, "nether_bricks");
put(BlockSoundGroup.NETHER_SPROUTS, "nether_sprouts");
put(BlockSoundGroup.NETHER_ORE, "nether_ore");
put(BlockSoundGroup.BONE, "bone");
put(BlockSoundGroup.NETHERITE, "netherite");
put(BlockSoundGroup.ANCIENT_DEBRIS, "ancient_debris");
put(BlockSoundGroup.LODESTONE, "lodestone");
put(BlockSoundGroup.CHAIN, "chain");
put(BlockSoundGroup.NETHER_GOLD_ORE, "nether_gold_ore");
put(BlockSoundGroup.GILDED_BLACKSTONE, "gilded_blackstone");
put(BlockSoundGroup.CANDLE, "candle");
put(BlockSoundGroup.AMETHYST_BLOCK, "amethyst");
put(BlockSoundGroup.AMETHYST_CLUSTER, "amethyst_cluster");
put(BlockSoundGroup.SMALL_AMETHYST_BUD, "small_amethyst_bud");
put(BlockSoundGroup.MEDIUM_AMETHYST_BUD, "medium_amethyst_bud");
put(BlockSoundGroup.LARGE_AMETHYST_BUD, "large_amethyst_bud");
public static final Map<SoundType, String> soundName = new HashMap<SoundType, String>() {{
put(SoundType.WOOD, "wood" );
put(SoundType.GRAVEL, "gravel");
put(SoundType.GRASS, "grass" );
put(SoundType.LILY_PAD, "lily_pad");
put(SoundType.STONE, "stone" );
put(SoundType.METAL, "metal" );
put(SoundType.GLASS , "glass" );
put(SoundType.WOOL , "wool" );
put(SoundType.SAND , "sand" );
put(SoundType.SNOW , "snow" );
put(SoundType.POWDER_SNOW , "powder_snow" );
put(SoundType.LADDER, "ladder");
put(SoundType.ANVIL , "anvil" );
put(SoundType.SLIME_BLOCK , "slime" );
put(SoundType.HONEY_BLOCK , "honey" );
put(SoundType.WET_GRASS , "sea_grass" );
put(SoundType.CORAL_BLOCK , "coral" );
put(SoundType.BAMBOO , "bamboo" );
put(SoundType.BAMBOO_SAPLING , "shoots" );
put(SoundType.SCAFFOLDING , "scaffolding" );
put(SoundType.SWEET_BERRY_BUSH , "berry" );
put(SoundType.CROP , "crop" );
put(SoundType.HARD_CROP , "stem" );
put(SoundType.VINE , "vine" );
put(SoundType.NETHER_WART , "wart" );
put(SoundType.LANTERN , "lantern" );
put(SoundType.STEM, "fungi_stem");
put(SoundType.NYLIUM, "nylium");
put(SoundType.FUNGUS, "fungus");
put(SoundType.ROOTS, "roots");
put(SoundType.SHROOMLIGHT, "shroomlight");
put(SoundType.WEEPING_VINES, "weeping_vine");
put(SoundType.TWISTING_VINES, "twisting_vine");
put(SoundType.SOUL_SAND, "soul_sand");
put(SoundType.SOUL_SOIL, "soul_soil");
put(SoundType.BASALT, "basalt");
put(SoundType.WART_BLOCK, "wart");
put(SoundType.NETHERRACK, "netherrack");
put(SoundType.NETHER_BRICKS, "nether_bricks");
put(SoundType.NETHER_SPROUTS, "nether_sprouts");
put(SoundType.NETHER_ORE, "nether_ore");
put(SoundType.BONE_BLOCK, "bone");
put(SoundType.NETHERITE_BLOCK, "netherite");
put(SoundType.ANCIENT_DEBRIS, "ancient_debris");
put(SoundType.LODESTONE, "lodestone");
put(SoundType.CHAIN, "chain");
put(SoundType.NETHER_GOLD_ORE, "nether_gold_ore");
put(SoundType.GILDED_BLACKSTONE, "gilded_blackstone");
put(SoundType.CANDLE, "candle");
put(SoundType.AMETHYST, "amethyst");
put(SoundType.AMETHYST_CLUSTER, "amethyst_cluster");
put(SoundType.SMALL_AMETHYST_BUD, "small_amethyst_bud");
put(SoundType.MEDIUM_AMETHYST_BUD, "medium_amethyst_bud");
put(SoundType.LARGE_AMETHYST_BUD, "large_amethyst_bud");
put(BlockSoundGroup.TUFF, "tuff");
put(BlockSoundGroup.CALCITE, "calcite");
put(BlockSoundGroup.DRIPSTONE_BLOCK, "dripstone");
put(BlockSoundGroup.POINTED_DRIPSTONE, "pointed_dripstone");
put(BlockSoundGroup.COPPER, "copper");
put(BlockSoundGroup.CAVE_VINES, "cave_vine");
put(BlockSoundGroup.SPORE_BLOSSOM, "spore_blossom");
put(BlockSoundGroup.AZALEA, "azalea");
put(BlockSoundGroup.FLOWERING_AZALEA, "flowering_azalea");
put(BlockSoundGroup.MOSS_CARPET, "moss_carpet");
put(BlockSoundGroup.MOSS_BLOCK, "moss");
put(BlockSoundGroup.BIG_DRIPLEAF, "big_dripleaf");
put(BlockSoundGroup.SMALL_DRIPLEAF, "small_dripleaf");
put(BlockSoundGroup.ROOTED_DIRT, "rooted_dirt");
put(BlockSoundGroup.HANGING_ROOTS, "hanging_roots");
put(BlockSoundGroup.AZALEA_LEAVES, "azalea_leaves");
put(BlockSoundGroup.SCULK_SENSOR, "sculk_sensor");
put(BlockSoundGroup.GLOW_LICHEN, "glow_lichen");
put(BlockSoundGroup.DEEPSLATE, "deepslate");
put(BlockSoundGroup.DEEPSLATE_BRICKS, "deepslate_bricks");
put(BlockSoundGroup.DEEPSLATE_TILES, "deepslate_tiles");
put(BlockSoundGroup.POLISHED_DEEPSLATE, "polished_deepslate");
put(SoundType.TUFF, "tuff");
put(SoundType.CALCITE, "calcite");
put(SoundType.DRIPSTONE_BLOCK, "dripstone");
put(SoundType.POINTED_DRIPSTONE, "pointed_dripstone");
put(SoundType.COPPER, "copper");
put(SoundType.CAVE_VINES, "cave_vine");
put(SoundType.SPORE_BLOSSOM, "spore_blossom");
put(SoundType.AZALEA, "azalea");
put(SoundType.FLOWERING_AZALEA, "flowering_azalea");
put(SoundType.MOSS_CARPET, "moss_carpet");
put(SoundType.MOSS, "moss");
put(SoundType.BIG_DRIPLEAF, "big_dripleaf");
put(SoundType.SMALL_DRIPLEAF, "small_dripleaf");
put(SoundType.ROOTED_DIRT, "rooted_dirt");
put(SoundType.HANGING_ROOTS, "hanging_roots");
put(SoundType.AZALEA_LEAVES, "azalea_leaves");
put(SoundType.SCULK_SENSOR, "sculk_sensor");
put(SoundType.GLOW_LICHEN, "glow_lichen");
put(SoundType.DEEPSLATE, "deepslate");
put(SoundType.DEEPSLATE_BRICKS, "deepslate_bricks");
put(SoundType.DEEPSLATE_TILES, "deepslate_tiles");
put(SoundType.POLISHED_DEEPSLATE, "polished_deepslate");
}};
public static final Map<MapColor, String> mapColourName = new HashMap<MapColor, String>() {{
put(MapColor.CLEAR , "air" );
put(MapColor.PALE_GREEN , "grass" );
put(MapColor.PALE_YELLOW , "sand" );
put(MapColor.WHITE_GRAY , "wool" );
put(MapColor.BRIGHT_RED , "tnt" );
put(MapColor.PALE_PURPLE , "ice" );
put(MapColor.IRON_GRAY , "iron" );
put(MapColor.DARK_GREEN , "foliage" );
put(MapColor.WHITE , "snow" );
put(MapColor.LIGHT_BLUE_GRAY , "clay" );
put(MapColor.DIRT_BROWN , "dirt" );
put(MapColor.STONE_GRAY , "stone" );
put(MapColor.WATER_BLUE , "water" );
put(MapColor.OAK_TAN , "wood" );
put(MapColor.OFF_WHITE , "quartz" );
put(MapColor.ORANGE , "adobe" );
put(MapColor.MAGENTA , "magenta" );
put(MapColor.LIGHT_BLUE, "light_blue");
put(MapColor.YELLOW , "yellow" );
put(MapColor.LIME , "lime" );
put(MapColor.PINK , "pink" );
put(MapColor.GRAY , "gray" );
put(MapColor.LIGHT_GRAY, "light_gray");
put(MapColor.CYAN , "cyan" );
put(MapColor.PURPLE , "purple" );
put(MapColor.BLUE , "blue" );
put(MapColor.BROWN , "brown" );
put(MapColor.GREEN , "green" );
put(MapColor.RED , "red" );
put(MapColor.BLACK , "black" );
put(MapColor.GOLD , "gold" );
put(MapColor.DIAMOND_BLUE , "diamond" );
put(MapColor.LAPIS_BLUE , "lapis" );
put(MapColor.EMERALD_GREEN , "emerald" );
put(MapColor.SPRUCE_BROWN , "obsidian" );
put(MapColor.DARK_RED , "netherrack"); //TODO fix these
put(MapColor.TERRACOTTA_WHITE , "white_terracotta" );
put(MapColor.TERRACOTTA_ORANGE , "orange_terracotta" );
put(MapColor.TERRACOTTA_MAGENTA , "magenta_terracotta" );
put(MapColor.TERRACOTTA_LIGHT_BLUE, "light_blue_terracotta" );
put(MapColor.TERRACOTTA_YELLOW , "yellow_terracotta" );
put(MapColor.TERRACOTTA_LIME , "lime_terracotta" );
put(MapColor.TERRACOTTA_PINK , "pink_terracotta" );
put(MapColor.TERRACOTTA_GRAY , "gray_terracotta" );
put(MapColor.TERRACOTTA_LIGHT_GRAY, "light_gray_terracotta" );
put(MapColor.TERRACOTTA_CYAN , "cyan_terracotta" );
put(MapColor.TERRACOTTA_PURPLE , "purple_terracotta" );
put(MapColor.TERRACOTTA_BLUE , "blue_terracotta" );
put(MapColor.TERRACOTTA_BROWN , "brown_terracotta" );
put(MapColor.TERRACOTTA_GREEN , "green_terracotta" );
put(MapColor.TERRACOTTA_RED , "red_terracotta" );
put(MapColor.TERRACOTTA_BLACK , "black_terracotta" );
put(MapColor.DULL_RED , "crimson_nylium" );
put(MapColor.DULL_PINK , "crimson_stem" );
put(MapColor.DARK_CRIMSON , "crimson_hyphae" );
put(MapColor.TEAL , "warped_nylium" );
put(MapColor.DARK_AQUA , "warped_stem" );
put(MapColor.DARK_DULL_PINK , "warped_hyphae" );
put(MapColor.BRIGHT_TEAL , "warped_wart" );
put(MapColor.DEEPSLATE_GRAY , "deepslate" );
put(MapColor.RAW_IRON_PINK , "raw_iron" );
put(MapColor.LICHEN_GREEN , "glow_lichen" );
public static final Map<MaterialColor, String> mapColourName = new HashMap<MaterialColor, String>() {{
put(MaterialColor.NONE , "air" );
put(MaterialColor.GRASS , "grass" );
put(MaterialColor.SAND , "sand" );
put(MaterialColor.WOOL , "wool" );
put(MaterialColor.FIRE , "tnt" );
put(MaterialColor.ICE , "ice" );
put(MaterialColor.METAL , "iron" );
put(MaterialColor.PLANT , "foliage" );
put(MaterialColor.SNOW , "snow" );
put(MaterialColor.CLAY , "clay" );
put(MaterialColor.DIRT , "dirt" );
put(MaterialColor.STONE , "stone" );
put(MaterialColor.WATER , "water" );
put(MaterialColor.WOOD , "wood" );
put(MaterialColor.QUARTZ , "quartz" );
put(MaterialColor.COLOR_ORANGE , "adobe" );
put(MaterialColor.COLOR_MAGENTA , "magenta" );
put(MaterialColor.COLOR_LIGHT_BLUE, "light_blue");
put(MaterialColor.COLOR_YELLOW , "yellow" );
put(MaterialColor.COLOR_LIGHT_GREEN , "lime" );
put(MaterialColor.COLOR_PINK , "pink" );
put(MaterialColor.COLOR_GRAY , "gray" );
put(MaterialColor.COLOR_LIGHT_GRAY, "light_gray");
put(MaterialColor.COLOR_CYAN , "cyan" );
put(MaterialColor.COLOR_PURPLE , "purple" );
put(MaterialColor.COLOR_BLUE , "blue" );
put(MaterialColor.COLOR_BROWN , "brown" );
put(MaterialColor.COLOR_GREEN , "green" );
put(MaterialColor.COLOR_RED , "red" );
put(MaterialColor.COLOR_BLACK , "black" );
put(MaterialColor.GOLD , "gold" );
put(MaterialColor.DIAMOND , "diamond" );
put(MaterialColor.LAPIS , "lapis" );
put(MaterialColor.EMERALD , "emerald" );
put(MaterialColor.PODZOL , "obsidian" );
put(MaterialColor.NETHER , "netherrack"); //TODO fix these
put(MaterialColor.TERRACOTTA_WHITE , "white_terracotta" );
put(MaterialColor.TERRACOTTA_ORANGE , "orange_terracotta" );
put(MaterialColor.TERRACOTTA_MAGENTA , "magenta_terracotta" );
put(MaterialColor.TERRACOTTA_LIGHT_BLUE, "light_blue_terracotta" );
put(MaterialColor.TERRACOTTA_YELLOW , "yellow_terracotta" );
put(MaterialColor.TERRACOTTA_LIGHT_GREEN , "lime_terracotta" );
put(MaterialColor.TERRACOTTA_PINK , "pink_terracotta" );
put(MaterialColor.TERRACOTTA_GRAY , "gray_terracotta" );
put(MaterialColor.TERRACOTTA_LIGHT_GRAY, "light_gray_terracotta" );
put(MaterialColor.TERRACOTTA_CYAN , "cyan_terracotta" );
put(MaterialColor.TERRACOTTA_PURPLE , "purple_terracotta" );
put(MaterialColor.TERRACOTTA_BLUE , "blue_terracotta" );
put(MaterialColor.TERRACOTTA_BROWN , "brown_terracotta" );
put(MaterialColor.TERRACOTTA_GREEN , "green_terracotta" );
put(MaterialColor.TERRACOTTA_RED , "red_terracotta" );
put(MaterialColor.TERRACOTTA_BLACK , "black_terracotta" );
put(MaterialColor.CRIMSON_NYLIUM , "crimson_nylium" );
put(MaterialColor.CRIMSON_STEM , "crimson_stem" );
put(MaterialColor.CRIMSON_HYPHAE , "crimson_hyphae" );
put(MaterialColor.WARPED_NYLIUM , "warped_nylium" );
put(MaterialColor.WARPED_STEM , "warped_stem" );
put(MaterialColor.WARPED_HYPHAE , "warped_hyphae" );
put(MaterialColor.WARPED_WART_BLOCK , "warped_wart" );
put(MaterialColor.DEEPSLATE , "deepslate" );
put(MaterialColor.RAW_IRON , "raw_iron" );
put(MaterialColor.GLOW_LICHEN , "glow_lichen" );
}};
public static final Map<Material, String> materialName = new HashMap<Material, String>() {{
put(Material.AIR , "air" );
put(Material.STRUCTURE_VOID , "void" );
put(Material.STRUCTURAL_AIR , "void" );
put(Material.PORTAL , "portal" );
put(Material.CARPET , "carpet" );
put(Material.CLOTH_DECORATION , "carpet" );
put(Material.PLANT , "plant" );
put(Material.UNDERWATER_PLANT, "water_plant" );
put(Material.WATER_PLANT, "water_plant" );
put(Material.REPLACEABLE_PLANT, "vegetation" );
put(Material.NETHER_SHOOTS, "nether_shoots" );
put(Material.REPLACEABLE_UNDERWATER_PLANT, "sea_grass" );
put(Material.REPLACEABLE_FIREPROOF_PLANT, "nether_shoots" );
put(Material.REPLACEABLE_WATER_PLANT, "sea_grass" );
put(Material.WATER , "water" );
put(Material.BUBBLE_COLUMN , "bubble_column");
put(Material.LAVA , "lava" );
put(Material.SNOW_LAYER , "snow_layer" );
put(Material.TOP_SNOW , "snow_layer" );
put(Material.FIRE , "fire" );
put(Material.DECORATION , "decoration" );
put(Material.COBWEB , "cobweb" );
put(Material.WEB , "cobweb" );
put(Material.SCULK , "sculk" );
put(Material.REDSTONE_LAMP , "redstone_lamp");
put(Material.ORGANIC_PRODUCT, "clay" );
put(Material.SOIL , "dirt" );
put(Material.SOLID_ORGANIC , "grass" );
put(Material.DENSE_ICE , "packed_ice" );
put(Material.AGGREGATE , "sand" );
put(Material.BUILDABLE_GLASS , "redstone_lamp");
put(Material.CLAY, "clay" );
put(Material.DIRT , "dirt" );
put(Material.GRASS , "grass" );
put(Material.ICE_SOLID , "packed_ice" );
put(Material.SAND , "sand" );
put(Material.SPONGE , "sponge" );
put(Material.SHULKER_BOX , "shulker" );
put(Material.SHULKER_SHELL , "shulker" );
put(Material.WOOD , "wood" );
put(Material.NETHER_WOOD , "nether_wood" );
put(Material.BAMBOO_SAPLING , "shoots" );
put(Material.BAMBOO , "bamboo" );
put(Material.WOOL , "wool" );
put(Material.TNT , "tnt" );
put(Material.EXPLOSIVE , "tnt" );
put(Material.LEAVES , "leaves" );
put(Material.GLASS , "glass" );
put(Material.ICE , "ice" );
put(Material.CACTUS , "cactus" );
put(Material.STONE , "stone" );
put(Material.METAL , "metal" );
put(Material.SNOW_BLOCK , "snow" );
put(Material.REPAIR_STATION , "anvil" );
put(Material.SNOW , "snow" );
put(Material.HEAVY_METAL , "anvil" );
put(Material.BARRIER , "barrier" );
put(Material.PISTON , "piston" );
put(Material.MOSS_BLOCK , "moss" );
put(Material.GOURD , "gourd" );
put(Material.MOSS , "moss" );
put(Material.VEGETABLE , "gourd" );
put(Material.EGG , "dragon_egg" );
put(Material.CAKE , "cake" );
put(Material.AMETHYST , "amethyst" );
put(Material.POWDER_SNOW , "powder_snow");
}};
public static List<BaseText> blockInfo(BlockPos pos, ServerWorld world)
public static List<BaseComponent> blockInfo(BlockPos pos, ServerLevel world)
{
BlockState state = world.getBlockState(pos);
Material material = state.getMaterial();
Block block = state.getBlock();
String metastring = "";
for (net.minecraft.state.property.Property<?> iproperty : state.getProperties())
for (net.minecraft.world.level.block.state.properties.Property<?> iproperty : state.getProperties())
{
metastring += ", "+iproperty.getName() + '='+state.get(iproperty);
metastring += ", "+iproperty.getName() + '='+state.getValue(iproperty);
}
List<BaseText> lst = new ArrayList<>();
List<BaseComponent> lst = new ArrayList<>();
lst.add(Messenger.s(""));
lst.add(Messenger.s("====================================="));
lst.add(Messenger.s(String.format("Block info for %s%s (id %d%s):",Registry.BLOCK.getId(block),metastring, Registry.BLOCK.getRawId(block), metastring )));
lst.add(Messenger.s(String.format("Block info for %s%s (id %d%s):",Registry.BLOCK.getKey(block),metastring, Registry.BLOCK.getId(block), metastring )));
lst.add(Messenger.s(String.format(" - Material: %s", materialName.get(material))));
lst.add(Messenger.s(String.format(" - Map colour: %s", mapColourName.get(state.getMapColor(world, pos)))));
lst.add(Messenger.s(String.format(" - Sound type: %s", soundName.get(block.getSoundGroup(state)))));
lst.add(Messenger.s(String.format(" - Sound type: %s", soundName.get(block.getSoundType(state)))));
lst.add(Messenger.s(""));
lst.add(Messenger.s(String.format(" - Full block: %s", state.isFullCube(world, pos)))); // isFullCube() )));
lst.add(Messenger.s(String.format(" - Normal cube: %s", state.isSolidBlock(world, pos)))); //isNormalCube()))); isSimpleFullBlock
lst.add(Messenger.s(String.format(" - Full block: %s", state.isCollisionShapeFullBlock(world, pos)))); // isFullCube() )));
lst.add(Messenger.s(String.format(" - Normal cube: %s", state.isRedstoneConductor(world, pos)))); //isNormalCube()))); isSimpleFullBlock
lst.add(Messenger.s(String.format(" - Is liquid: %s", material.isLiquid())));
lst.add(Messenger.s(""));
lst.add(Messenger.s(String.format(" - Light in: %d, above: %d",
Math.max(world.getLightLevel(LightType.BLOCK, pos),world.getLightLevel(LightType.SKY, pos)) ,
Math.max(world.getLightLevel(LightType.BLOCK, pos.up()),world.getLightLevel(LightType.SKY, pos.up())))));
lst.add(Messenger.s(String.format(" - Brightness in: %.2f, above: %.2f", world.getBrightness(pos), world.getBrightness(pos.up()))));
Math.max(world.getBrightness(LightLayer.BLOCK, pos),world.getBrightness(LightLayer.SKY, pos)) ,
Math.max(world.getBrightness(LightLayer.BLOCK, pos.above()),world.getBrightness(LightLayer.SKY, pos.above())))));
lst.add(Messenger.s(String.format(" - Brightness in: %.2f, above: %.2f", world.getBrightness(pos), world.getBrightness(pos.above()))));
lst.add(Messenger.s(String.format(" - Is opaque: %s", material.isSolid() )));
//lst.add(Messenger.s(String.format(" - Light opacity: %d", state.getOpacity(world,pos))));
lst.add(Messenger.s(String.format(" - Blocks light: %s", state.getMaterial().blocksLight())));
lst.add(Messenger.s(String.format(" - Blocks light: %s", state.getMaterial().isSolidBlocking())));
//lst.add(Messenger.s(String.format(" - Emitted light: %d", state.getLightValue())));
//lst.add(Messenger.s(String.format(" - Picks neighbour light value: %s", state.useNeighborBrightness(world, pos))));
lst.add(Messenger.s(""));
lst.add(Messenger.s(String.format(" - Causes suffocation: %s", state.shouldSuffocate(world, pos)))); //canSuffocate
lst.add(Messenger.s(String.format(" - Blocks movement on land: %s", !state.canPathfindThrough(world,pos, NavigationType.LAND))));
lst.add(Messenger.s(String.format(" - Blocks movement in air: %s", !state.canPathfindThrough(world,pos, NavigationType.AIR))));
lst.add(Messenger.s(String.format(" - Blocks movement in liquids: %s", !state.canPathfindThrough(world,pos, NavigationType.WATER))));
lst.add(Messenger.s(String.format(" - Can burn: %s", material.isBurnable())));
lst.add(Messenger.s(String.format(" - Causes suffocation: %s", state.isSuffocating(world, pos)))); //canSuffocate
lst.add(Messenger.s(String.format(" - Blocks movement on land: %s", !state.isPathfindable(world,pos, PathComputationType.LAND))));
lst.add(Messenger.s(String.format(" - Blocks movement in air: %s", !state.isPathfindable(world,pos, PathComputationType.AIR))));
lst.add(Messenger.s(String.format(" - Blocks movement in liquids: %s", !state.isPathfindable(world,pos, PathComputationType.WATER))));
lst.add(Messenger.s(String.format(" - Can burn: %s", material.isFlammable())));
lst.add(Messenger.s(String.format(" - Requires a tool: %s", !material.isReplaceable()))); //?maybe
lst.add(Messenger.s(String.format(" - Hardness: %.2f", state.getHardness(world, pos))));
lst.add(Messenger.s(String.format(" - Blast resistance: %.2f", block.getBlastResistance())));
lst.add(Messenger.s(String.format(" - Ticks randomly: %s", block.hasRandomTicks(state))));
lst.add(Messenger.s(String.format(" - Hardness: %.2f", state.getDestroySpeed(world, pos))));
lst.add(Messenger.s(String.format(" - Blast resistance: %.2f", block.getExplosionResistance())));
lst.add(Messenger.s(String.format(" - Ticks randomly: %s", block.isRandomlyTicking(state))));
lst.add(Messenger.s(""));
lst.add(Messenger.s(String.format(" - Can provide power: %s", state.emitsRedstonePower())));
lst.add(Messenger.s(String.format(" - Strong power level: %d", world.getReceivedStrongRedstonePower(pos))));
lst.add(Messenger.s(String.format(" - Redstone power level: %d", world.getReceivedRedstonePower(pos))));
lst.add(Messenger.s(String.format(" - Can provide power: %s", state.isSignalSource())));
lst.add(Messenger.s(String.format(" - Strong power level: %d", world.getDirectSignalTo(pos))));
lst.add(Messenger.s(String.format(" - Redstone power level: %d", world.getBestNeighborSignal(pos))));
lst.add(Messenger.s(""));
lst.add(wander_chances(pos.up(), world));
lst.add(wander_chances(pos.above(), world));
return lst;
}
private static BaseText wander_chances(BlockPos pos, ServerWorld worldIn)
private static BaseComponent wander_chances(BlockPos pos, ServerLevel worldIn)
{
PathAwareEntity creature = new ZombifiedPiglinEntity(EntityType.ZOMBIFIED_PIGLIN, worldIn);
creature.initialize(worldIn, worldIn.getLocalDifficulty(pos), SpawnReason.NATURAL, null, null);
creature.refreshPositionAndAngles(pos, 0.0F, 0.0F);
WanderAroundGoal wander = new WanderAroundGoal(creature, 0.8D);
PathfinderMob creature = new ZombifiedPiglin(EntityType.ZOMBIFIED_PIGLIN, worldIn);
creature.finalizeSpawn(worldIn, worldIn.getCurrentDifficultyAt(pos), MobSpawnType.NATURAL, null, null);
creature.moveTo(pos, 0.0F, 0.0F);
RandomStrollGoal wander = new RandomStrollGoal(creature, 0.8D);
int success = 0;
for (int i=0; i<1000; i++)
{
Vec3d vec = NoPenaltyTargeting.find(creature, 10, 7); // TargetFinder.findTarget(creature, 10, 7);
Vec3 vec = DefaultRandomPos.getPos(creature, 10, 7); // TargetFinder.findTarget(creature, 10, 7);
if (vec == null)
{
continue;
@@ -297,7 +295,7 @@ public class BlockInfo
int i;
for (i=1;i<30*20*60; i++) //*60 used to be 5 hours, limited to 30 mins
{
if (wander.canStart())
if (wander.canUse())
{
break;
}
+38 -38
View File
@@ -2,16 +2,16 @@ package carpet.utils;
import it.unimi.dsi.fastutil.objects.Object2LongMap;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import org.apache.commons.lang3.tuple.Pair;
import java.util.Comparator;
@@ -22,11 +22,11 @@ import java.util.stream.Collectors;
public class CarpetProfiler
{
private static final Map<String, Long> SECTION_STATS = new HashMap<>();
private static final Object2LongMap<Pair<World,Object>> ENTITY_TIMES = new Object2LongOpenHashMap<>();
private static final Object2LongMap<Pair<World,Object>> ENTITY_COUNT = new Object2LongOpenHashMap<>();
private static final Object2LongMap<Pair<Level,Object>> ENTITY_TIMES = new Object2LongOpenHashMap<>();
private static final Object2LongMap<Pair<Level,Object>> ENTITY_COUNT = new Object2LongOpenHashMap<>();
private static ServerCommandSource currentRequester = null;
private static CommandSourceStack currentRequester = null;
public static int tick_health_requested = 0;
private static int tick_health_elapsed = 0;
private static TYPE test_type = TYPE.NONE; //1 for ticks, 2 for entities
@@ -50,15 +50,15 @@ public class CarpetProfiler
TILEENTITY
}
public static record ProfilerToken(TYPE type, Object section, long start, World world)
public static record ProfilerToken(TYPE type, Object section, long start, Level world)
{
public ProfilerToken(TYPE type, Object section, World world)
public ProfilerToken(TYPE type, Object section, Level world)
{
this(type, section, System.nanoTime(), world);
}
}
public static void prepare_tick_report(ServerCommandSource source, int ticks)
public static void prepare_tick_report(CommandSourceStack source, int ticks)
{
//maybe add so it only spams the sending player, but honestly - all may want to see it
SECTION_STATS.clear();
@@ -74,11 +74,11 @@ public class CarpetProfiler
{
SECTION_STATS.put(section, 0L);
}
for (RegistryKey<World> level : source.getServer().getWorldRegistryKeys())
for (ResourceKey<Level> level : source.getServer().levelKeys())
{
for (String section : SECTIONS)
{
SECTION_STATS.put(level.getValue() + "." + section, 0L);
SECTION_STATS.put(level.location() + "." + section, 0L);
}
}
@@ -88,7 +88,7 @@ public class CarpetProfiler
currentRequester = source;
}
public static void prepare_entity_report(ServerCommandSource source, int ticks)
public static void prepare_entity_report(CommandSourceStack source, int ticks)
{
//maybe add so it only spams the sending player, but honestly - all may want to see it
SECTION_STATS.clear();
@@ -102,21 +102,21 @@ public class CarpetProfiler
currentRequester = source;
}
public static ProfilerToken start_section(World world, String name, TYPE type)
public static ProfilerToken start_section(Level world, String name, TYPE type)
{
if (tick_health_requested == 0L || test_type != TYPE.GENERAL || current_tick_start == 0)
return null;
return new ProfilerToken(type, name, world);
}
public static ProfilerToken start_entity_section(World world, Entity e, TYPE type)
public static ProfilerToken start_entity_section(Level world, Entity e, TYPE type)
{
if (tick_health_requested == 0L || test_type != TYPE.ENTITY || current_tick_start == 0)
return null;
return new ProfilerToken(type, e.getType(), world);
}
public static ProfilerToken start_block_entity_section(World world, BlockEntity be, TYPE type)
public static ProfilerToken start_block_entity_section(Level world, BlockEntity be, TYPE type)
{
if (tick_health_requested == 0L || test_type != TYPE.ENTITY || current_tick_start == 0)
return null;
@@ -130,10 +130,10 @@ public class CarpetProfiler
long end_time = System.nanoTime();
if (tok.type == TYPE.GENERAL)
{
World world = tok.world;
Level world = tok.world;
String current_section = (world == null) ?
(String) tok.section :
String.format("%s.%s%s", world.getRegistryKey().getValue(), tok.section, world.isClient ? " (Client)" : "");
String.format("%s.%s%s", world.dimension().location(), tok.section, world.isClientSide ? " (Client)" : "");
SECTION_STATS.put(current_section, SECTION_STATS.getOrDefault(current_section, 0L) + end_time - tok.start);
}
}
@@ -143,7 +143,7 @@ public class CarpetProfiler
if (tick_health_requested == 0L || test_type != TYPE.ENTITY || current_tick_start == 0 || tok == null)
return;
long end_time = System.nanoTime();
Pair<World,Object> section = Pair.of(tok.world, tok.section);
Pair<Level,Object> section = Pair.of(tok.world, tok.section);
ENTITY_TIMES.put(section, ENTITY_TIMES.getOrDefault(section, 0L) + end_time - tok.start);
ENTITY_COUNT.put(section, ENTITY_COUNT.getOrDefault(section, 0L) + 1);
}
@@ -216,9 +216,9 @@ public class CarpetProfiler
}
}
for (RegistryKey<World> dim : server.getWorldRegistryKeys())
for (ResourceKey<Level> dim : server.levelKeys())
{
Identifier dimensionId = dim.getValue();
ResourceLocation dimensionId = dim.location();
boolean hasSomethin = false;
for (String section : SECTIONS)
{
@@ -253,23 +253,23 @@ public class CarpetProfiler
Messenger.m(currentRequester, String.format("gi The Rest, whatever that might be: %.3fms", divider * rest));
}
private static String sectionName(Pair<World,Object> section)
private static String sectionName(Pair<Level,Object> section)
{
Identifier id;
ResourceLocation id;
if (section.getValue() instanceof EntityType)
{
id = Registry.ENTITY_TYPE.getId((EntityType<?>) section.getValue());
id = Registry.ENTITY_TYPE.getKey((EntityType<?>) section.getValue());
}
else
{
id = Registry.BLOCK_ENTITY_TYPE.getId((BlockEntityType<?>) section.getValue());
id = Registry.BLOCK_ENTITY_TYPE.getKey((BlockEntityType<?>) section.getValue());
}
String name = "minecraft".equals(id.getNamespace())?id.getPath():id.toString();
if (section.getKey().isClient)
if (section.getKey().isClientSide)
{
name += " (client)";
}
Identifier dimkey = section.getKey().getRegistryKey().getValue();
ResourceLocation dimkey = section.getKey().dimension().location();
String dim = "minecraft".equals(dimkey.getNamespace())?dimkey.getPath():dimkey.toString();
return name+" in "+dim;
}
@@ -286,11 +286,11 @@ public class CarpetProfiler
SECTION_STATS.remove("tick");
Messenger.m(currentRequester, "wb Top 10 counts:");
int total = 0;
for (Object2LongMap.Entry<Pair<World, Object>> sectionEntry : ENTITY_COUNT.object2LongEntrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList()))
for (Object2LongMap.Entry<Pair<Level, Object>> sectionEntry : ENTITY_COUNT.object2LongEntrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList()))
{
if (++total > 10) break;
Pair<World,Object> section = sectionEntry.getKey();
boolean cli = section.getKey().isClient;
Pair<Level,Object> section = sectionEntry.getKey();
boolean cli = section.getKey().isClientSide;
Messenger.m(currentRequester, String.format(
"%s - %s: ", cli?"gi":"w",
sectionName(section)),
@@ -300,11 +300,11 @@ public class CarpetProfiler
}
Messenger.m(currentRequester, "wb Top 10 CPU hogs:");
total = 0;
for (Object2LongMap.Entry<Pair<World,Object>> sectionEntry : ENTITY_TIMES.object2LongEntrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList()))
for (Object2LongMap.Entry<Pair<Level,Object>> sectionEntry : ENTITY_TIMES.object2LongEntrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList()))
{
if (++total > 10) break;
Pair<World,Object> section = sectionEntry.getKey();
boolean cli = section.getKey().isClient;
Pair<Level,Object> section = sectionEntry.getKey();
boolean cli = section.getKey().isClientSide;
Messenger.m(currentRequester, String.format(
"%s - %s: ", cli?"gi":"w",
sectionName(section)),
@@ -1,32 +1,31 @@
package carpet.utils;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.text.BaseText;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.Vec3;
public class DistanceCalculator
{
public static final HashMap<String, Vec3d> START_POINT_STORAGE = new HashMap<>();
public static final HashMap<String, Vec3> START_POINT_STORAGE = new HashMap<>();
public static boolean hasStartingPoint(ServerCommandSource source)
public static boolean hasStartingPoint(CommandSourceStack source)
{
return START_POINT_STORAGE.containsKey(source.getName());
return START_POINT_STORAGE.containsKey(source.getTextName());
}
public static List<BaseText> findDistanceBetweenTwoPoints(Vec3d pos1, Vec3d pos2)
public static List<BaseComponent> findDistanceBetweenTwoPoints(Vec3 pos1, Vec3 pos2)
{
double dx = MathHelper.abs((float)pos1.x-(float)pos2.x);
double dy = MathHelper.abs((float)pos1.y-(float)pos2.y);
double dz = MathHelper.abs((float)pos1.z-(float)pos2.z);
double dx = Mth.abs((float)pos1.x-(float)pos2.x);
double dy = Mth.abs((float)pos1.y-(float)pos2.y);
double dz = Mth.abs((float)pos1.z-(float)pos2.z);
double manhattan = dx+dy+dz;
double spherical = Math.sqrt(dx*dx + dy*dy + dz*dz);
double cylindrical = Math.sqrt(dx*dx + dz*dz);
List<BaseText> res = new ArrayList<>();
List<BaseComponent> res = new ArrayList<>();
res.add(Messenger.c("w Distance between ",
Messenger.tp("c",pos1),"w and ",
Messenger.tp("c",pos2),"w :"));
@@ -36,29 +35,29 @@ public class DistanceCalculator
return res;
}
public static int distance(ServerCommandSource source, Vec3d pos1, Vec3d pos2)
public static int distance(CommandSourceStack source, Vec3 pos1, Vec3 pos2)
{
Messenger.send(source, findDistanceBetweenTwoPoints(pos1, pos2));
return 1;
}
public static int setStart(ServerCommandSource source, Vec3d pos)
public static int setStart(CommandSourceStack source, Vec3 pos)
{
START_POINT_STORAGE.put(source.getName(), pos);
START_POINT_STORAGE.put(source.getTextName(), pos);
Messenger.m(source,"gi Initial point set to: ", Messenger.tp("g",pos));
return 1;
}
public static int setEnd(ServerCommandSource source, Vec3d pos)
public static int setEnd(CommandSourceStack source, Vec3 pos)
{
if ( !hasStartingPoint(source) )
{
START_POINT_STORAGE.put(source.getName(), pos);
Messenger.m(source,"gi There was no initial point for "+source.getName());
START_POINT_STORAGE.put(source.getTextName(), pos);
Messenger.m(source,"gi There was no initial point for "+source.getTextName());
Messenger.m(source,"gi Initial point set to: ", Messenger.tp("g",pos));
return 0;
}
Messenger.send(source, findDistanceBetweenTwoPoints( START_POINT_STORAGE.get(source.getName()), pos));
Messenger.send(source, findDistanceBetweenTwoPoints( START_POINT_STORAGE.get(source.getTextName()), pos));
return 1;
}
}
+77 -77
View File
@@ -1,20 +1,20 @@
package carpet.utils;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.BaseText;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Style;
import net.minecraft.text.TextColor;
import net.minecraft.util.Util;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.Formatting;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextColor;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -34,30 +34,30 @@ public class Messenger
public enum CarpetFormatting
{
ITALIC ('i', (s, f) -> s.withItalic(true)),
STRIKE ('s', (s, f) -> s.withFormatting(Formatting.STRIKETHROUGH)),
UNDERLINE ('u', (s, f) -> s.withFormatting(Formatting.UNDERLINE)),
STRIKE ('s', (s, f) -> s.applyFormat(ChatFormatting.STRIKETHROUGH)),
UNDERLINE ('u', (s, f) -> s.applyFormat(ChatFormatting.UNDERLINE)),
BOLD ('b', (s, f) -> s.withBold(true)),
OBFUSCATE ('o', (s, f) -> s.withFormatting(Formatting.OBFUSCATED)),
OBFUSCATE ('o', (s, f) -> s.applyFormat(ChatFormatting.OBFUSCATED)),
WHITE ('w', (s, f) -> s.withColor(Formatting.WHITE)),
YELLOW ('y', (s, f) -> s.withColor(Formatting.YELLOW)),
LIGHT_PURPLE('m', (s, f) -> s.withColor(Formatting.LIGHT_PURPLE)), // magenta
RED ('r', (s, f) -> s.withColor(Formatting.RED)),
AQUA ('c', (s, f) -> s.withColor(Formatting.AQUA)), // cyan
GREEN ('l', (s, f) -> s.withColor(Formatting.GREEN)), // lime
BLUE ('t', (s, f) -> s.withColor(Formatting.BLUE)), // light blue, teal
DARK_GRAY ('f', (s, f) -> s.withColor(Formatting.DARK_GRAY)),
GRAY ('g', (s, f) -> s.withColor(Formatting.GRAY)),
GOLD ('d', (s, f) -> s.withColor(Formatting.GOLD)),
DARK_PURPLE ('p', (s, f) -> s.withColor(Formatting.DARK_PURPLE)), // purple
DARK_RED ('n', (s, f) -> s.withColor(Formatting.DARK_RED)), // brown
DARK_AQUA ('q', (s, f) -> s.withColor(Formatting.DARK_AQUA)),
DARK_GREEN ('e', (s, f) -> s.withColor(Formatting.DARK_GREEN)),
DARK_BLUE ('v', (s, f) -> s.withColor(Formatting.DARK_BLUE)), // navy
BLACK ('k', (s, f) -> s.withColor(Formatting.BLACK)),
WHITE ('w', (s, f) -> s.withColor(ChatFormatting.WHITE)),
YELLOW ('y', (s, f) -> s.withColor(ChatFormatting.YELLOW)),
LIGHT_PURPLE('m', (s, f) -> s.withColor(ChatFormatting.LIGHT_PURPLE)), // magenta
RED ('r', (s, f) -> s.withColor(ChatFormatting.RED)),
AQUA ('c', (s, f) -> s.withColor(ChatFormatting.AQUA)), // cyan
GREEN ('l', (s, f) -> s.withColor(ChatFormatting.GREEN)), // lime
BLUE ('t', (s, f) -> s.withColor(ChatFormatting.BLUE)), // light blue, teal
DARK_GRAY ('f', (s, f) -> s.withColor(ChatFormatting.DARK_GRAY)),
GRAY ('g', (s, f) -> s.withColor(ChatFormatting.GRAY)),
GOLD ('d', (s, f) -> s.withColor(ChatFormatting.GOLD)),
DARK_PURPLE ('p', (s, f) -> s.withColor(ChatFormatting.DARK_PURPLE)), // purple
DARK_RED ('n', (s, f) -> s.withColor(ChatFormatting.DARK_RED)), // brown
DARK_AQUA ('q', (s, f) -> s.withColor(ChatFormatting.DARK_AQUA)),
DARK_GREEN ('e', (s, f) -> s.withColor(ChatFormatting.DARK_GREEN)),
DARK_BLUE ('v', (s, f) -> s.withColor(ChatFormatting.DARK_BLUE)), // navy
BLACK ('k', (s, f) -> s.withColor(ChatFormatting.BLACK)),
COLOR ('#', (s, f) -> {
TextColor color = TextColor.parse("#"+f);
TextColor color = TextColor.parseColor("#"+f);
return color == null ? s : s.withColor(color);
}, s -> {
Matcher m = colorExtract.matcher(s);
@@ -88,7 +88,7 @@ public class Messenger
public static Style parseStyle(String style)
{
Style myStyle= Style.EMPTY.withColor(Formatting.WHITE);
Style myStyle= Style.EMPTY.withColor(ChatFormatting.WHITE);
for (CarpetFormatting cf: CarpetFormatting.values()) myStyle = cf.apply(style, myStyle);
return myStyle;
}
@@ -101,7 +101,7 @@ public class Messenger
if (actual > reference) color = "m";
return color;
}
public static String creatureTypeColor(SpawnGroup type)
public static String creatureTypeColor(MobCategory type)
{
return switch (type)
{
@@ -114,11 +114,11 @@ public class Messenger
};
}
private static BaseText getChatComponentFromDesc(String message, BaseText previousMessage)
private static BaseComponent getChatComponentFromDesc(String message, BaseComponent previousMessage)
{
if (message.equalsIgnoreCase(""))
{
return new LiteralText("");
return new TextComponent("");
}
if (Character.isWhitespace(message.charAt(0)))
{
@@ -133,12 +133,12 @@ public class Messenger
str = message.substring(limit+1);
}
if (previousMessage == null) {
BaseText text = new LiteralText(str);
BaseComponent text = new TextComponent(str);
text.setStyle(parseStyle(desc));
return text;
}
Style previousStyle = previousMessage.getStyle();
BaseText ret = previousMessage;
BaseComponent ret = previousMessage;
previousMessage.setStyle(switch (desc.charAt(0)) {
case '?' -> previousStyle.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, message.substring(1)));
case '!' -> previousStyle.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, message.substring(1)));
@@ -146,31 +146,31 @@ public class Messenger
case '@' -> previousStyle.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, message.substring(1)));
case '&' -> previousStyle.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, message.substring(1)));
default -> { // Create a new component
ret = new LiteralText(str);
ret = new TextComponent(str);
ret.setStyle(parseStyle(desc));
yield previousStyle; // no op for the previous style
}
});
return ret;
}
public static BaseText tp(String desc, Vec3d pos) { return tp(desc, pos.x, pos.y, pos.z); }
public static BaseText tp(String desc, BlockPos pos) { return tp(desc, pos.getX(), pos.getY(), pos.getZ()); }
public static BaseText tp(String desc, double x, double y, double z) { return tp(desc, (float)x, (float)y, (float)z);}
public static BaseText tp(String desc, float x, float y, float z)
public static BaseComponent tp(String desc, Vec3 pos) { return tp(desc, pos.x, pos.y, pos.z); }
public static BaseComponent tp(String desc, BlockPos pos) { return tp(desc, pos.getX(), pos.getY(), pos.getZ()); }
public static BaseComponent tp(String desc, double x, double y, double z) { return tp(desc, (float)x, (float)y, (float)z);}
public static BaseComponent tp(String desc, float x, float y, float z)
{
return getCoordsTextComponent(desc, x, y, z, false);
}
public static BaseText tp(String desc, int x, int y, int z)
public static BaseComponent tp(String desc, int x, int y, int z)
{
return getCoordsTextComponent(desc, (float)x, (float)y, (float)z, true);
}
/// to be continued
public static BaseText dbl(String style, double double_value)
public static BaseComponent dbl(String style, double double_value)
{
return c(String.format("%s %.1f",style,double_value),String.format("^w %f",double_value));
}
public static BaseText dbls(String style, double ... doubles)
public static BaseComponent dbls(String style, double ... doubles)
{
StringBuilder str = new StringBuilder(style + " [ ");
String prefix = "";
@@ -182,7 +182,7 @@ public class Messenger
str.append(" ]");
return c(str.toString());
}
public static BaseText dblf(String style, double ... doubles)
public static BaseComponent dblf(String style, double ... doubles)
{
StringBuilder str = new StringBuilder(style + " [ ");
String prefix = "";
@@ -194,7 +194,7 @@ public class Messenger
str.append(" ]");
return c(str.toString());
}
public static BaseText dblt(String style, double ... doubles)
public static BaseComponent dblt(String style, double ... doubles)
{
List<Object> components = new ArrayList<>();
components.add(style+" [ ");
@@ -212,7 +212,7 @@ public class Messenger
return c(components.toArray(new Object[0]));
}
private static BaseText getCoordsTextComponent(String style, float x, float y, float z, boolean isInt)
private static BaseComponent getCoordsTextComponent(String style, float x, float y, float z, boolean isInt)
{
String text;
String command;
@@ -230,33 +230,33 @@ public class Messenger
}
//message source
public static void m(ServerCommandSource source, Object ... fields)
public static void m(CommandSourceStack source, Object ... fields)
{
if (source != null)
source.sendFeedback(Messenger.c(fields),source.getServer() != null && source.getServer().getWorld(World.OVERWORLD) != null); //OW
source.sendSuccess(Messenger.c(fields),source.getServer() != null && source.getServer().getLevel(Level.OVERWORLD) != null); //OW
}
public static void m(PlayerEntity player, Object ... fields)
public static void m(Player player, Object ... fields)
{
player.sendSystemMessage(Messenger.c(fields), Util.NIL_UUID);
player.sendMessage(Messenger.c(fields), Util.NIL_UUID);
}
/*
composes single line, multicomponent message, and returns as one chat messagge
*/
public static BaseText c(Object ... fields)
public static BaseComponent c(Object ... fields)
{
BaseText message = new LiteralText("");
BaseText previousComponent = null;
BaseComponent message = new TextComponent("");
BaseComponent previousComponent = null;
for (Object o: fields)
{
if (o instanceof BaseText)
if (o instanceof BaseComponent)
{
message.append((BaseText)o);
previousComponent = (BaseText)o;
message.append((BaseComponent)o);
previousComponent = (BaseComponent)o;
continue;
}
String txt = o.toString();
BaseText comp = getChatComponentFromDesc(txt, previousComponent);
BaseComponent comp = getChatComponentFromDesc(txt, previousComponent);
if (comp != previousComponent) message.append(comp);
previousComponent = comp;
}
@@ -265,13 +265,13 @@ public class Messenger
//simple text
public static BaseText s(String text)
public static BaseComponent s(String text)
{
return s(text,"");
}
public static BaseText s(String text, String style)
public static BaseComponent s(String text, String style)
{
BaseText message = new LiteralText(text);
BaseComponent message = new TextComponent(text);
message.setStyle(parseStyle(style));
return message;
}
@@ -279,13 +279,13 @@ public class Messenger
public static void send(PlayerEntity player, Collection<BaseText> lines)
public static void send(Player player, Collection<BaseComponent> lines)
{
lines.forEach(message -> player.sendSystemMessage(message, Util.NIL_UUID));
lines.forEach(message -> player.sendMessage(message, Util.NIL_UUID));
}
public static void send(ServerCommandSource source, Collection<BaseText> lines)
public static void send(CommandSourceStack source, Collection<BaseComponent> lines)
{
lines.stream().forEachOrdered((s) -> source.sendFeedback(s, false));
lines.stream().forEachOrdered((s) -> source.sendSuccess(s, false));
}
@@ -293,21 +293,21 @@ public class Messenger
{
if (server == null)
LOG.error("Message not delivered: "+message);
server.sendSystemMessage(new LiteralText(message), Util.NIL_UUID);
BaseText txt = c("gi "+message);
for (PlayerEntity entityplayer : server.getPlayerManager().getPlayerList())
server.sendMessage(new TextComponent(message), Util.NIL_UUID);
BaseComponent txt = c("gi "+message);
for (Player entityplayer : server.getPlayerList().getPlayers())
{
entityplayer.sendSystemMessage(txt, Util.NIL_UUID);
entityplayer.sendMessage(txt, Util.NIL_UUID);
}
}
public static void print_server_message(MinecraftServer server, BaseText message)
public static void print_server_message(MinecraftServer server, BaseComponent message)
{
if (server == null)
LOG.error("Message not delivered: "+message.getString());
server.sendSystemMessage(message, Util.NIL_UUID);
for (PlayerEntity entityplayer : server.getPlayerManager().getPlayerList())
server.sendMessage(message, Util.NIL_UUID);
for (Player entityplayer : server.getPlayerList().getPlayers())
{
entityplayer.sendSystemMessage(message, Util.NIL_UUID);
entityplayer.sendMessage(message, Util.NIL_UUID);
}
}
}
+19 -23
View File
@@ -2,23 +2,19 @@ package carpet.utils;
import carpet.CarpetServer;
import com.google.common.collect.Sets;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.tag.FluidTags;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.Registry;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.phys.Vec3;
public class MobAI
{
@@ -31,7 +27,7 @@ public class MobAI
public static boolean isTracking(Entity e, TrackingType type)
{
if (e.getEntityWorld().isClient())
if (e.getCommandSenderWorld().isClientSide())
return false;
Set<TrackingType> currentTrackers = aiTrackers.get(e.getType());
if (currentTrackers == null)
@@ -42,9 +38,9 @@ public class MobAI
public static void clearTracking(EntityType<? extends Entity> etype)
{
aiTrackers.remove(etype);
for(ServerWorld world : CarpetServer.minecraft_server.getWorlds() )
for(ServerLevel world : CarpetServer.minecraft_server.getAllLevels() )
{
for (Entity e: world.getEntitiesByType(etype, Entity::hasCustomName))
for (Entity e: world.getEntities(etype, Entity::hasCustomName))
{
e.setCustomNameVisible(false);
e.setCustomName(null);
@@ -65,7 +61,7 @@ public class MobAI
{
types.addAll(type.types);
}
return types.stream().map(t -> Registry.ENTITY_TYPE.getId(t).getPath()).collect(Collectors.toList());
return types.stream().map(t -> Registry.ENTITY_TYPE.getKey(t).getPath()).collect(Collectors.toList());
}
public static List<String> availableFor(EntityType<?> entityType)
@@ -105,19 +101,19 @@ public class MobAI
*/
public static void genericJump(Entity e)
{
if (!e.isOnGround() && !e.isInsideWaterOrBubbleColumn() && !e.isInLava()) return;
float m = e.world.getBlockState(e.getBlockPos()).getBlock().getJumpVelocityMultiplier();
float g = e.world.getBlockState(new BlockPos(e.getX(), e.getBoundingBox().minY - 0.5000001D, e.getZ())).getBlock().getJumpVelocityMultiplier();
if (!e.isOnGround() && !e.isInWaterOrBubble() && !e.isInLava()) return;
float m = e.level.getBlockState(e.blockPosition()).getBlock().getJumpFactor();
float g = e.level.getBlockState(new BlockPos(e.getX(), e.getBoundingBox().minY - 0.5000001D, e.getZ())).getBlock().getJumpFactor();
float jumpVelocityMultiplier = (double) m == 1.0D ? g : m;
float jumpStrength = (0.42F * jumpVelocityMultiplier);
Vec3d vec3d = e.getVelocity();
e.setVelocity(vec3d.x, jumpStrength, vec3d.z);
Vec3 vec3d = e.getDeltaMovement();
e.setDeltaMovement(vec3d.x, jumpStrength, vec3d.z);
if (e.isSprinting())
{
float u = e.getYaw() * 0.017453292F; // yaw
e.setVelocity(e.getVelocity().add((-MathHelper.sin(g) * 0.2F), 0.0D, (MathHelper.cos(u) * 0.2F)));
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.velocityDirty = true;
e.hasImpulse = true;
}
}
@@ -1,26 +1,24 @@
package carpet.utils;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material;
import net.minecraft.block.BlockState;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.SpawnRestriction;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.mob.WaterCreatureEntity;
import net.minecraft.entity.mob.AmbientEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.mob.Monster;
import net.minecraft.entity.passive.PassiveEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.SpawnHelper;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.SpawnSettings;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.AgeableMob;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.SpawnPlacements;
import net.minecraft.world.entity.ambient.AmbientCreature;
import net.minecraft.world.entity.animal.WaterAnimal;
import net.minecraft.world.entity.monster.Enemy;
import net.minecraft.world.level.NaturalSpawner;
import net.minecraft.world.level.biome.MobSpawnSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
public class PerimeterDiagnostics
{
@@ -35,11 +33,11 @@ public class PerimeterDiagnostics
samples = new ArrayList<>();
}
}
private SpawnSettings.SpawnEntry sle;
private ServerWorld worldServer;
private SpawnGroup ctype;
private MobEntity el;
private PerimeterDiagnostics(ServerWorld server, SpawnGroup ctype, MobEntity el)
private MobSpawnSettings.SpawnerData sle;
private ServerLevel worldServer;
private MobCategory ctype;
private Mob el;
private PerimeterDiagnostics(ServerLevel server, MobCategory ctype, Mob el)
{
this.sle = null;
this.worldServer = server;
@@ -47,7 +45,7 @@ public class PerimeterDiagnostics
this.el = el;
}
public static Result countSpots(ServerWorld worldserver, BlockPos epos, MobEntity el)
public static Result countSpots(ServerLevel worldserver, BlockPos epos, Mob el)
{
BlockPos pos;
//List<BlockPos> samples = new ArrayList<BlockPos>();
@@ -62,35 +60,35 @@ public class PerimeterDiagnostics
//int specific_spawns = 0;
boolean add_water = false;
boolean add_ground = false;
SpawnGroup ctype = null;
MobCategory ctype = null;
if (el != null)
{
if (el instanceof WaterCreatureEntity)
if (el instanceof WaterAnimal)
{
add_water = true;
ctype = SpawnGroup.WATER_CREATURE;
ctype = MobCategory.WATER_CREATURE;
}
else if (el instanceof PassiveEntity)
else if (el instanceof AgeableMob)
{
add_ground = true;
ctype = SpawnGroup.CREATURE;
ctype = MobCategory.CREATURE;
}
else if (el instanceof Monster)
else if (el instanceof Enemy)
{
add_ground = true;
ctype = SpawnGroup.MONSTER;
ctype = MobCategory.MONSTER;
}
else if (el instanceof AmbientEntity)
else if (el instanceof AmbientCreature)
{
ctype = SpawnGroup.AMBIENT;
ctype = MobCategory.AMBIENT;
}
}
PerimeterDiagnostics diagnostic = new PerimeterDiagnostics(worldserver,ctype,el);
EntityType type = EntityType.ZOMBIE;
if (el != null) type = el.getType();
int minY = worldserver.getBottomY();
int maxY = worldserver.getTopY();
int minY = worldserver.getMinBuildHeight();
int maxY = worldserver.getMaxBuildHeight();
for (int x = -128; x <= 128; ++x)
{
for (int z = -128; z <= 128; ++z)
@@ -113,10 +111,10 @@ public class PerimeterDiagnostics
pos = new BlockPos(eX+x, y, eZ+z);
BlockState iblockstate = worldserver.getBlockState(pos);
BlockState iblockstate_down = worldserver.getBlockState(pos.down());
BlockState iblockstate_up = worldserver.getBlockState(pos.up());
BlockState iblockstate_down = worldserver.getBlockState(pos.below());
BlockState iblockstate_up = worldserver.getBlockState(pos.above());
if ( iblockstate.getMaterial() == Material.WATER && iblockstate_down.getMaterial() == Material.WATER && !iblockstate_up.isSolidBlock(worldserver, pos)) // isSimpleFUllBLock
if ( iblockstate.getMaterial() == Material.WATER && iblockstate_down.getMaterial() == Material.WATER && !iblockstate_up.isRedstoneConductor(worldserver, pos)) // isSimpleFUllBLock
{
result.liquid++;
if (add_water && diagnostic.check_entity_spawn(pos))
@@ -130,11 +128,11 @@ public class PerimeterDiagnostics
}
else
{
if (iblockstate_down.isSolidBlock(worldserver, pos)) // isSimpleFUllBLock
if (iblockstate_down.isRedstoneConductor(worldserver, pos)) // isSimpleFUllBLock
{
Block block = iblockstate_down.getBlock();
boolean flag = block != Blocks.BEDROCK && block != Blocks.BARRIER;
if( flag && SpawnHelper.isClearForSpawn(worldserver, pos, iblockstate, iblockstate.getFluidState(), type) && SpawnHelper.isClearForSpawn(worldserver, pos.up(), iblockstate_up, iblockstate_up.getFluidState(), type))
if( flag && NaturalSpawner.isValidEmptySpawnBlock(worldserver, pos, iblockstate, iblockstate.getFluidState(), type) && NaturalSpawner.isValidEmptySpawnBlock(worldserver, pos.above(), iblockstate_up, iblockstate_up.getFluidState(), type))
{
result.ground ++;
if (add_ground && diagnostic.check_entity_spawn(pos))
@@ -161,10 +159,10 @@ public class PerimeterDiagnostics
private boolean check_entity_spawn(BlockPos pos)
{
if (sle == null || !worldServer.getChunkManager().getChunkGenerator().getEntitySpawnList(worldServer.getBiome(pos), worldServer.getStructureAccessor(), ctype, pos).getEntries().contains(sle))
if (sle == null || !worldServer.getChunkSource().getGenerator().getMobsAt(worldServer.getBiome(pos), worldServer.structureFeatureManager(), ctype, pos).unwrap().contains(sle))
{
sle = null;
for (SpawnSettings.SpawnEntry sle: worldServer.getChunkManager().getChunkGenerator().getEntitySpawnList(worldServer.getBiome(pos), worldServer.getStructureAccessor(), ctype, pos).getEntries())
for (MobSpawnSettings.SpawnerData sle: worldServer.getChunkSource().getGenerator().getMobsAt(worldServer.getBiome(pos), worldServer.structureFeatureManager(), ctype, pos).unwrap())
{
if (el.getType() == sle.type)
{
@@ -172,20 +170,20 @@ public class PerimeterDiagnostics
break;
}
}
if (sle == null || !worldServer.getChunkManager().getChunkGenerator().getEntitySpawnList(worldServer.getBiome(pos), worldServer.getStructureAccessor(), ctype, pos).getEntries().contains(sle))
if (sle == null || !worldServer.getChunkSource().getGenerator().getMobsAt(worldServer.getBiome(pos), worldServer.structureFeatureManager(), ctype, pos).unwrap().contains(sle))
{
return false;
}
}
SpawnRestriction.Location spt = SpawnRestriction.getLocation(sle.type);
SpawnPlacements.Type spt = SpawnPlacements.getPlacementType(sle.type);
if (SpawnHelper.canSpawn(spt, worldServer, pos, sle.type))
if (NaturalSpawner.isSpawnPositionOk(spt, worldServer, pos, sle.type))
{
el.refreshPositionAndAngles((float)pos.getX() + 0.5F, (float)pos.getY(), (float)pos.getZ()+0.5F, 0.0F, 0.0F);
return el.canSpawn(worldServer) && el.canSpawn(worldServer, SpawnReason.NATURAL) &&
SpawnRestriction.canSpawn(el.getType(),(ServerWorld)el.getEntityWorld(), SpawnReason.NATURAL, el.getBlockPos(), el.getEntityWorld().random) &&
worldServer.isSpaceEmpty(el); // check collision rules once they stop fiddling with them after 1.14.1
el.moveTo((float)pos.getX() + 0.5F, (float)pos.getY(), (float)pos.getZ()+0.5F, 0.0F, 0.0F);
return el.checkSpawnObstruction(worldServer) && el.checkSpawnRules(worldServer, MobSpawnType.NATURAL) &&
SpawnPlacements.checkSpawnRules(el.getType(),(ServerLevel)el.getCommandSenderWorld(), MobSpawnType.NATURAL, el.blockPosition(), el.getCommandSenderWorld().random) &&
worldServer.noCollision(el); // check collision rules once they stop fiddling with them after 1.14.1
}
return false;
}
+5 -5
View File
@@ -2,15 +2,15 @@ package carpet.utils;
import carpet.fakes.ChunkTicketManagerInterface;
import carpet.fakes.ServerChunkManagerInterface;
import net.minecraft.server.world.ChunkTicketManager;
import net.minecraft.server.world.ServerChunkManager;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.server.level.DistanceManager;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.world.level.ChunkPos;
public class SpawnChunks
{
public static void changeSpawnChunks(ServerChunkManager chunkManager, ChunkPos pos, int size)
public static void changeSpawnChunks(ServerChunkCache chunkManager, ChunkPos pos, int size)
{
ChunkTicketManager ticketManager = ((ServerChunkManagerInterface)chunkManager).getCMTicketManager();
DistanceManager ticketManager = ((ServerChunkManagerInterface)chunkManager).getCMTicketManager();
((ChunkTicketManagerInterface)ticketManager).changeSpawnChunks(pos, size);
}
}
+124 -125
View File
@@ -4,35 +4,34 @@ import carpet.CarpetSettings;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2LongMap;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.Entity;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnRestriction;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.passive.OcelotEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tag.BlockTags;
import net.minecraft.text.BaseText;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.DyeColor;
import net.minecraft.util.TypeFilter;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.Heightmap;
import net.minecraft.world.SpawnHelper;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.SpawnSettings;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.NetherFortressFeature;
import net.minecraft.world.gen.feature.StructureFeature;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.SpawnPlacements;
import net.minecraft.world.entity.animal.Ocelot;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.NaturalSpawner;
import net.minecraft.world.level.StructureFeatureManager;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.MobSpawnSettings;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.entity.EntityTypeTest;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.feature.NetherFortressFeature;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.Nullable;
@@ -50,31 +49,31 @@ public class SpawnReporter
public static boolean mock_spawns = false;
public static Long track_spawns = 0L;
public static final HashMap<RegistryKey<World>, Integer> chunkCounts = new HashMap<>();
public static final HashMap<ResourceKey<Level>, Integer> chunkCounts = new HashMap<>();
public static final HashMap<Pair<RegistryKey<World>, SpawnGroup>, Object2LongMap<EntityType>> spawn_stats = new HashMap<>();
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, Object2LongMap<EntityType>> spawn_stats = new HashMap<>();
public static double mobcap_exponent = 0.0D;
public static final HashMap<Pair<RegistryKey<World>, SpawnGroup>, Long> spawn_attempts = new HashMap<>();
public static final HashMap<Pair<RegistryKey<World>, SpawnGroup>, Long> overall_spawn_ticks = new HashMap<>();
public static final HashMap<Pair<RegistryKey<World>, SpawnGroup>, Long> spawn_ticks_full = new HashMap<>();
public static final HashMap<Pair<RegistryKey<World>, SpawnGroup>, Long> spawn_ticks_fail = new HashMap<>();
public static final HashMap<Pair<RegistryKey<World>, SpawnGroup>, Long> spawn_ticks_succ = new HashMap<>();
public static final HashMap<Pair<RegistryKey<World>, SpawnGroup>, Long> spawn_ticks_spawns = new HashMap<>();
public static final HashMap<Pair<RegistryKey<World>, SpawnGroup>, Long> spawn_cap_count = new HashMap<>();
public static final HashMap<Pair<RegistryKey<World>, SpawnGroup>, EvictingQueue<Pair<EntityType, BlockPos>>> spawned_mobs = new HashMap<>();
public static final HashMap<SpawnGroup, Integer> spawn_tries = new HashMap<>();
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, Long> spawn_attempts = new HashMap<>();
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, Long> overall_spawn_ticks = new HashMap<>();
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, Long> spawn_ticks_full = new HashMap<>();
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, Long> spawn_ticks_fail = new HashMap<>();
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, Long> spawn_ticks_succ = new HashMap<>();
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, Long> spawn_ticks_spawns = new HashMap<>();
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, Long> spawn_cap_count = new HashMap<>();
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, EvictingQueue<Pair<EntityType, BlockPos>>> spawned_mobs = new HashMap<>();
public static final HashMap<MobCategory, Integer> spawn_tries = new HashMap<>();
public static BlockPos lower_spawning_limit = null;
public static BlockPos upper_spawning_limit = null;
// in case game gets each thread for each world - these need to belong to workd.
public static HashMap<SpawnGroup, Long> local_spawns = null; // per world
public static HashSet<SpawnGroup> first_chunk_marker = null;
public static HashMap<MobCategory, Long> local_spawns = null; // per world
public static HashSet<MobCategory> first_chunk_marker = null;
static {
reset_spawn_stats(null, true);
}
public static void registerSpawn(MobEntity mob, SpawnGroup cat, BlockPos pos)
public static void registerSpawn(Mob mob, MobCategory cat, BlockPos pos)
{
if (lower_spawning_limit != null)
{
@@ -86,13 +85,13 @@ public class SpawnReporter
return;
}
}
Pair<RegistryKey<World>, SpawnGroup> key = Pair.of(mob.world.getRegistryKey(), cat);
Pair<ResourceKey<Level>, MobCategory> key = Pair.of(mob.level.dimension(), cat);
long count = spawn_stats.get(key).getOrDefault(mob.getType(), 0L);
spawn_stats.get(key).put(mob.getType(), count + 1);
spawned_mobs.get(key).put(Pair.of(mob.getType(), pos));
if (!local_spawns.containsKey(cat))
{
CarpetSettings.LOG.error("Rogue spawn detected for category "+cat.getName()+" for mob "+mob.getType().getName().getString()+". If you see this message let carpet peeps know about it on github issues.");
CarpetSettings.LOG.error("Rogue spawn detected for category "+cat.getName()+" for mob "+mob.getType().getDescription().getString()+". If you see this message let carpet peeps know about it on github issues.");
local_spawns.put(cat, 0L);
}
local_spawns.put(cat, local_spawns.get(cat)+1);
@@ -104,15 +103,15 @@ public class SpawnReporter
return MAGIC_NUMBER / (Math.pow(2.0,(SpawnReporter.mobcap_exponent/4)));
}*/
public static List<BaseText> printMobcapsForDimension(ServerWorld world, boolean multiline)
public static List<BaseComponent> printMobcapsForDimension(ServerLevel world, boolean multiline)
{
RegistryKey<World> dim = world.getRegistryKey();
String name = dim.getValue().getPath();
List<BaseText> lst = new ArrayList<>();
ResourceKey<Level> dim = world.dimension();
String name = dim.location().getPath();
List<BaseComponent> lst = new ArrayList<>();
if (multiline)
lst.add(Messenger.s(String.format("Mobcaps for %s:",name)));
SpawnHelper.Info lastSpawner = world.getChunkManager().getSpawnInfo();
Object2IntMap<SpawnGroup> dimCounts = lastSpawner.getGroupToCount();
NaturalSpawner.SpawnState lastSpawner = world.getChunkSource().getLastSpawnState();
Object2IntMap<MobCategory> dimCounts = lastSpawner.getMobCategoryCounts();
int chunkcount = chunkCounts.getOrDefault(dim, -1);
if (dimCounts == null || chunkcount < 0)
{
@@ -121,10 +120,10 @@ public class SpawnReporter
}
List<String> shortCodes = new ArrayList<>();
for (SpawnGroup enumcreaturetype : SpawnGroup.values())
for (MobCategory enumcreaturetype : MobCategory.values())
{
int cur = dimCounts.getOrDefault(enumcreaturetype, -1);
int max = (int)(chunkcount * ((double)enumcreaturetype.getCapacity() / MAGIC_NUMBER)); // from ServerChunkManager.CHUNKS_ELIGIBLE_FOR_SPAWNING
int max = (int)(chunkcount * ((double)enumcreaturetype.getMaxInstancesPerChunk() / MAGIC_NUMBER)); // from ServerChunkManager.CHUNKS_ELIGIBLE_FOR_SPAWNING
String color = Messenger.heatmap_color(cur, max);
String mobColor = Messenger.creatureTypeColor(enumcreaturetype);
if (multiline)
@@ -159,9 +158,9 @@ public class SpawnReporter
return lst;
}
public static List<BaseText> recent_spawns(World world, SpawnGroup creature_type)
public static List<BaseComponent> recent_spawns(Level world, MobCategory creature_type)
{
List<BaseText> lst = new ArrayList<>();
List<BaseComponent> lst = new ArrayList<>();
if ((track_spawns == 0L))
{
lst.add(Messenger.s("Spawn tracking not started"));
@@ -170,12 +169,12 @@ public class SpawnReporter
String type_code = creature_type.getName();
lst.add(Messenger.s(String.format("Recent %s spawns:",type_code)));
for (Pair<EntityType, BlockPos> pair : spawned_mobs.get(Pair.of(world.getRegistryKey(), creature_type)).keySet()) // getDImTYpe
for (Pair<EntityType, BlockPos> pair : spawned_mobs.get(Pair.of(world.dimension(), creature_type)).keySet()) // getDImTYpe
{
lst.add( Messenger.c(
"w - ",
Messenger.tp("wb",pair.getRight()),
String.format("w : %s", pair.getLeft().getName().getString())
String.format("w : %s", pair.getLeft().getDescription().getString())
));
}
@@ -187,9 +186,9 @@ public class SpawnReporter
}
public static List<BaseText> show_mobcaps(BlockPos pos, ServerWorld worldIn)
public static List<BaseComponent> show_mobcaps(BlockPos pos, ServerLevel worldIn)
{
DyeColor under = WoolTool.getWoolColorAtPosition(worldIn, pos.down());
DyeColor under = WoolTool.getWoolColorAtPosition(worldIn, pos.below());
if (under == null)
{
if (track_spawns > 0L)
@@ -201,7 +200,7 @@ public class SpawnReporter
return printMobcapsForDimension(worldIn, true );
}
}
SpawnGroup creature_type = get_type_code_from_wool_code(under);
MobCategory creature_type = get_type_code_from_wool_code(under);
if (creature_type != null)
{
if (track_spawns > 0L)
@@ -226,52 +225,52 @@ public class SpawnReporter
}
public static SpawnGroup get_type_code_from_wool_code(DyeColor color)
public static MobCategory get_type_code_from_wool_code(DyeColor color)
{
switch (color)
{
case RED:
return SpawnGroup.MONSTER;
return MobCategory.MONSTER;
case GREEN:
return SpawnGroup.CREATURE;
return MobCategory.CREATURE;
case BLUE:
return SpawnGroup.WATER_CREATURE;
return MobCategory.WATER_CREATURE;
case BROWN:
return SpawnGroup.AMBIENT;
return MobCategory.AMBIENT;
case CYAN:
return SpawnGroup.WATER_AMBIENT;
return MobCategory.WATER_AMBIENT;
default:
return null;
}
}
public static SpawnGroup get_creature_type_from_code(String type_code)
public static MobCategory get_creature_type_from_code(String type_code)
{
if ("hostile".equalsIgnoreCase(type_code))
{
return SpawnGroup.MONSTER;
return MobCategory.MONSTER;
}
else if ("passive".equalsIgnoreCase(type_code))
{
return SpawnGroup.CREATURE;
return MobCategory.CREATURE;
}
else if ("water".equalsIgnoreCase(type_code))
{
return SpawnGroup.WATER_CREATURE;
return MobCategory.WATER_CREATURE;
}
else if ("fish".equalsIgnoreCase(type_code))
{
return SpawnGroup.WATER_AMBIENT;
return MobCategory.WATER_AMBIENT;
}
else if ("ambient".equalsIgnoreCase(type_code))
{
return SpawnGroup.AMBIENT;
return MobCategory.AMBIENT;
}
return null;
}
public static String get_type_string(SpawnGroup type)
public static String get_type_string(MobCategory type)
{
return String.format("%s", type);
}
@@ -281,22 +280,22 @@ public class SpawnReporter
return get_type_string(get_creature_type_from_code(str));
}
public static List<BaseText> printEntitiesByType(SpawnGroup cat, World worldIn, boolean all) //Class<?> entityType)
public static List<BaseComponent> printEntitiesByType(MobCategory cat, Level worldIn, boolean all) //Class<?> entityType)
{
List<BaseText> lst = new ArrayList<>();
List<BaseComponent> lst = new ArrayList<>();
lst.add( Messenger.s(String.format("Loaded entities for %s class:", get_type_string(cat))));
for (Entity entity : ((ServerWorld)worldIn).getEntitiesByType(TypeFilter.instanceOf(Entity.class), (e) -> e.getType().getSpawnGroup()==cat))
for (Entity entity : ((ServerLevel)worldIn).getEntities(EntityTypeTest.forClass(Entity.class), (e) -> e.getType().getCategory()==cat))
{
boolean persistent = entity instanceof MobEntity && ( ((MobEntity) entity).isPersistent() || ((MobEntity) entity).cannotDespawn());
boolean persistent = entity instanceof Mob && ( ((Mob) entity).isPersistenceRequired() || ((Mob) entity).requiresCustomPersistence());
if (!all && persistent)
continue;
EntityType type = entity.getType();
BlockPos pos = entity.getBlockPos();
BlockPos pos = entity.blockPosition();
lst.add( Messenger.c(
"w - ",
Messenger.tp(persistent?"gb":"wb",pos),
String.format(persistent?"g : %s":"w : %s", type.getName().getString())
String.format(persistent?"g : %s":"w : %s", type.getDescription().getString())
));
}
@@ -321,15 +320,15 @@ public class SpawnReporter
spawn_stats.clear();
spawned_mobs.clear();
for (SpawnGroup enumcreaturetype : SpawnGroup.values())
for (MobCategory enumcreaturetype : MobCategory.values())
{
if (full)
{
spawn_tries.put(enumcreaturetype, 1);
}
if (server != null) for (RegistryKey<World> dim : server.getWorldRegistryKeys())
if (server != null) for (ResourceKey<Level> dim : server.levelKeys())
{
Pair<RegistryKey<World>, SpawnGroup> key = Pair.of(dim, enumcreaturetype);
Pair<ResourceKey<Level>, MobCategory> key = Pair.of(dim, enumcreaturetype);
overall_spawn_ticks.put(key, 0L);
spawn_attempts.put(key, 0L);
spawn_ticks_full.put(key, 0L);
@@ -344,16 +343,16 @@ public class SpawnReporter
track_spawns = 0L;
}
private static String getWorldCode(RegistryKey<World> world)
private static String getWorldCode(ResourceKey<Level> world)
{
if (world == World.OVERWORLD) return "";
return "("+world.getValue().getPath().toUpperCase(Locale.ROOT).replace("THE_","").charAt(0)+")";
if (world == Level.OVERWORLD) return "";
return "("+world.location().getPath().toUpperCase(Locale.ROOT).replace("THE_","").charAt(0)+")";
}
public static List<BaseText> tracking_report(World worldIn)
public static List<BaseComponent> tracking_report(Level worldIn)
{
List<BaseText> report = new ArrayList<>();
List<BaseComponent> report = new ArrayList<>();
if (track_spawns == 0L)
{
report.add(Messenger.c(
@@ -362,20 +361,20 @@ public class SpawnReporter
"w ' to enable"));
return report;
}
long duration = (long) worldIn.getServer().getTicks() - track_spawns;
long duration = (long) worldIn.getServer().getTickCount() - track_spawns;
report.add(Messenger.c("bw --------------------"));
String simulated = mock_spawns?"[SIMULATED] ":"";
String location = (lower_spawning_limit != null)?String.format("[in (%d, %d, %d)x(%d, %d, %d)]",
lower_spawning_limit.getX(),lower_spawning_limit.getY(),lower_spawning_limit.getZ(),
upper_spawning_limit.getX(),upper_spawning_limit.getY(),upper_spawning_limit.getZ() ):"";
report.add(Messenger.s(String.format("%sSpawn statistics %s: for %.1f min", simulated, location, (duration/72000.0)*60)));
for (SpawnGroup enumcreaturetype : SpawnGroup.values())
for (MobCategory enumcreaturetype : MobCategory.values())
{
//String type_code = String.format("%s", enumcreaturetype);
boolean there_are_mobs_to_list = false;
for (RegistryKey<World> dim : worldIn.getServer().getWorldRegistryKeys()) //String world_code: new String[] {"", " (N)", " (E)"})
for (ResourceKey<Level> dim : worldIn.getServer().levelKeys()) //String world_code: new String[] {"", " (N)", " (E)"})
{
Pair<RegistryKey<World>, SpawnGroup> code = Pair.of(dim, enumcreaturetype);
Pair<ResourceKey<Level>, MobCategory> code = Pair.of(dim, enumcreaturetype);
if (spawn_ticks_spawns.get(code) > 0L)
{
there_are_mobs_to_list = true;
@@ -392,7 +391,7 @@ public class SpawnReporter
for (EntityType type: spawn_stats.get(code).keySet())
{
report.add(Messenger.s(String.format(" - %s: %d spawns, %d per hour",
type.getName().getString(),
type.getDescription().getString(),
spawn_stats.get(code).getLong(type),
(72000 * spawn_stats.get(code).getLong(type)/duration ))));
}
@@ -406,20 +405,20 @@ public class SpawnReporter
public static void killEntity(LivingEntity entity)
{
if (entity.hasVehicle())
if (entity.isPassenger())
{
entity.getVehicle().discard();
}
if (entity.hasPassengers())
if (entity.isVehicle())
{
for (Entity e: entity.getPassengerList())
for (Entity e: entity.getPassengers())
{
e.discard();
}
}
if (entity instanceof OcelotEntity)
if (entity instanceof Ocelot)
{
for (Entity e: entity.getEntityWorld().getOtherEntities(entity, entity.getBoundingBox()))
for (Entity e: entity.getCommandSenderWorld().getEntities(entity, entity.getBoundingBox()))
{
e.discard();
}
@@ -428,39 +427,39 @@ public class SpawnReporter
}
// yeeted from SpawnHelper - temporary fix
private static List<SpawnSettings.SpawnEntry> getSpawnEntries(ServerWorld world, StructureAccessor structureAccessor, ChunkGenerator chunkGenerator, SpawnGroup spawnGroup, BlockPos pos, @Nullable Biome biome) {
return SpawnHelper.shouldUseNetherFortressSpawns(pos, world, spawnGroup, structureAccessor) ? NetherFortressFeature.MONSTER_SPAWNS.getEntries() : chunkGenerator.getEntitySpawnList(biome != null ? biome : world.getBiome(pos), structureAccessor, spawnGroup, pos).getEntries();
private static List<MobSpawnSettings.SpawnerData> getSpawnEntries(ServerLevel world, StructureFeatureManager structureAccessor, ChunkGenerator chunkGenerator, MobCategory spawnGroup, BlockPos pos, @Nullable Biome biome) {
return NaturalSpawner.isInNetherFortressBounds(pos, world, spawnGroup, structureAccessor) ? NetherFortressFeature.FORTRESS_ENEMIES.unwrap() : chunkGenerator.getMobsAt(biome != null ? biome : world.getBiome(pos), structureAccessor, spawnGroup, pos).unwrap();
}
public static List<BaseText> report(BlockPos pos, ServerWorld worldIn)
public static List<BaseComponent> report(BlockPos pos, ServerLevel worldIn)
{
List<BaseText> rep = new ArrayList<>();
List<BaseComponent> rep = new ArrayList<>();
int x = pos.getX(); int y = pos.getY(); int z = pos.getZ();
Chunk chunk = worldIn.getChunk(pos);
int lc = chunk.sampleHeightmap(Heightmap.Type.WORLD_SURFACE, x, z) + 1;
String where = String.format((y >= lc) ? "%d blocks above it." : "%d blocks below it.", MathHelper.abs(y-lc));
ChunkAccess chunk = worldIn.getChunk(pos);
int lc = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, x, z) + 1;
String where = String.format((y >= lc) ? "%d blocks above it." : "%d blocks below it.", Mth.abs(y-lc));
if (y == lc) where = "right at it.";
rep.add(Messenger.s(String.format("Maximum spawn Y value for (%+d, %+d) is %d. You are "+where, x, z, lc )));
rep.add(Messenger.s("Spawns:"));
for (SpawnGroup enumcreaturetype : SpawnGroup.values())
for (MobCategory enumcreaturetype : MobCategory.values())
{
String type_code = String.format("%s", enumcreaturetype).substring(0, 3);
List<SpawnSettings.SpawnEntry> lst = getSpawnEntries(worldIn, worldIn.getStructureAccessor(), worldIn.getChunkManager().getChunkGenerator(), enumcreaturetype, pos, worldIn.getBiome(pos) );// ((ChunkGenerator)worldIn.getChunkManager().getChunkGenerator()).getEntitySpawnList(, worldIn.getStructureAccessor(), enumcreaturetype, pos);
List<MobSpawnSettings.SpawnerData> lst = getSpawnEntries(worldIn, worldIn.structureFeatureManager(), worldIn.getChunkSource().getGenerator(), enumcreaturetype, pos, worldIn.getBiome(pos) );// ((ChunkGenerator)worldIn.getChunkManager().getChunkGenerator()).getEntitySpawnList(, worldIn.getStructureAccessor(), enumcreaturetype, pos);
if (lst != null && !lst.isEmpty())
{
for (SpawnSettings.SpawnEntry spawnEntry : lst)
for (MobSpawnSettings.SpawnerData spawnEntry : lst)
{
if (SpawnRestriction.getLocation(spawnEntry.type)==null)
if (SpawnPlacements.getPlacementType(spawnEntry.type)==null)
continue; // vanilla bug
boolean canspawn = SpawnHelper.canSpawn(SpawnRestriction.getLocation(spawnEntry.type), worldIn, pos, spawnEntry.type);
boolean canspawn = NaturalSpawner.isSpawnPositionOk(SpawnPlacements.getPlacementType(spawnEntry.type), worldIn, pos, spawnEntry.type);
int will_spawn = -1;
boolean fits;
boolean fits1;
MobEntity mob;
Mob mob;
try
{
mob = (MobEntity) spawnEntry.type.create(worldIn);
mob = (Mob) spawnEntry.type.create(worldIn);
}
catch (Exception exception)
{
@@ -478,32 +477,32 @@ public class SpawnReporter
{
float f = (float)x + 0.5F;
float f1 = (float)z + 0.5F;
mob.refreshPositionAndAngles((double)f, (double)y, (double)f1, worldIn.random.nextFloat() * 360.0F, 0.0F);
fits1 = worldIn.isSpaceEmpty(mob);
mob.moveTo((double)f, (double)y, (double)f1, worldIn.random.nextFloat() * 360.0F, 0.0F);
fits1 = worldIn.noCollision(mob);
EntityType etype = mob.getType();
for (int i = 0; i < 20; ++i)
{
if (
SpawnRestriction.canSpawn(etype,worldIn, SpawnReason.NATURAL, pos, worldIn.random) &&
SpawnHelper.canSpawn(SpawnRestriction.getLocation(etype), worldIn, pos, etype) &&
mob.canSpawn(worldIn, SpawnReason.NATURAL)
SpawnPlacements.checkSpawnRules(etype,worldIn, MobSpawnType.NATURAL, pos, worldIn.random) &&
NaturalSpawner.isSpawnPositionOk(SpawnPlacements.getPlacementType(etype), worldIn, pos, etype) &&
mob.checkSpawnRules(worldIn, MobSpawnType.NATURAL)
// && mob.canSpawn(worldIn) // entity collisions // mostly - except ocelots
)
{
if (etype == EntityType.OCELOT)
{
BlockState blockState = worldIn.getBlockState(pos.down());
if ((pos.getY() < worldIn.getSeaLevel()) || !(blockState.isOf(Blocks.GRASS_BLOCK) || blockState.isIn(BlockTags.LEAVES))) {
BlockState blockState = worldIn.getBlockState(pos.below());
if ((pos.getY() < worldIn.getSeaLevel()) || !(blockState.is(Blocks.GRASS_BLOCK) || blockState.is(BlockTags.LEAVES))) {
continue;
}
}
will_spawn += 1;
}
}
mob.initialize(worldIn, worldIn.getLocalDifficulty(mob.getBlockPos()), SpawnReason.NATURAL, null, null);
mob.finalizeSpawn(worldIn, worldIn.getCurrentDifficultyAt(mob.blockPosition()), MobSpawnType.NATURAL, null, null);
// the code invokes onInitialSpawn after getCanSpawHere
fits = fits1 && worldIn.isSpaceEmpty(mob);
fits = fits1 && worldIn.noCollision(mob);
if (fits)
{
fits_true = true;
@@ -517,7 +516,7 @@ public class SpawnReporter
try
{
mob = (MobEntity) spawnEntry.type.create(worldIn);
mob = (Mob) spawnEntry.type.create(worldIn);
}
catch (Exception exception)
{
@@ -527,14 +526,14 @@ public class SpawnReporter
}
}
String creature_name = mob.getType().getName().getString();
String pack_size = String.format("%d", mob.getLimitPerChunk());//String.format("%d-%d", animal.minGroupCount, animal.maxGroupCount);
int weight = spawnEntry.getWeight().getValue();
String creature_name = mob.getType().getDescription().getString();
String pack_size = String.format("%d", mob.getMaxSpawnClusterSize());//String.format("%d-%d", animal.minGroupCount, animal.maxGroupCount);
int weight = spawnEntry.getWeight().asInt();
if (canspawn)
{
String c = (fits_true && will_spawn>0)?"e":"gi";
rep.add(Messenger.c(
String.format("%s %s: %s (%d:%d-%d/%d), can: ",c,type_code,creature_name,weight,spawnEntry.minGroupSize, spawnEntry.maxGroupSize, mob.getLimitPerChunk()),
String.format("%s %s: %s (%d:%d-%d/%d), can: ",c,type_code,creature_name,weight,spawnEntry.minCount, spawnEntry.maxCount, mob.getMaxSpawnClusterSize()),
"l YES",
c+" , fit: ",
((fits_true && fits_false)?"y YES and NO":(fits_true?"l YES":"r NO")),
@@ -544,7 +543,7 @@ public class SpawnReporter
}
else
{
rep.add(Messenger.c(String.format("gi %s: %s (%d:%d-%d/%d), can: ",type_code,creature_name,weight,spawnEntry.minGroupSize, spawnEntry.maxGroupSize, mob.getLimitPerChunk()), "n NO"));
rep.add(Messenger.c(String.format("gi %s: %s (%d:%d-%d/%d), can: ",type_code,creature_name,weight,spawnEntry.minCount, spawnEntry.maxCount, mob.getMaxSpawnClusterSize()), "n NO"));
}
killEntity(mob);
}
+2 -2
View File
@@ -6,7 +6,6 @@ import carpet.CarpetSettings;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import net.minecraft.server.command.ServerCommandSource;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
@@ -14,6 +13,7 @@ import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import net.minecraft.commands.CommandSourceStack;
public class Translations
{
@@ -55,7 +55,7 @@ public class Translations
}
public static void updateLanguage(ServerCommandSource source)
public static void updateLanguage(CommandSourceStack source)
{
if (CarpetSettings.language.equalsIgnoreCase("none"))
{
+41 -42
View File
@@ -2,21 +2,20 @@ package carpet.utils;
import carpet.CarpetSettings;
import carpet.helpers.HopperCounter;
import net.minecraft.block.Material;
import net.minecraft.block.MapColor;
import net.minecraft.block.BlockState;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.DyeColor;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.text.BaseText;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.phys.Vec3;
/**
* A series of utility functions and variables for dealing predominantly with hopper counters and determining which counter
@@ -28,36 +27,36 @@ public class WoolTool
* A map of the {@link MaterialColor} to the {@link DyeColor} which is used in {@link WoolTool#getWoolColorAtPosition}
* to get the colour of wool at a position.
*/
private static final HashMap<MapColor,DyeColor> Material2Dye = new HashMap<>();
private static final HashMap<MaterialColor,DyeColor> Material2Dye = new HashMap<>();
/**
* A map of all the wool colours to their respective colours in the {@link Messenger#m} format so the name of the counter
* gets printed in colour.
*/
public static final HashMap<MapColor,String> Material2DyeName = new HashMap<MapColor, String>(){{
put(MapColor.WHITE, "w ");
put(MapColor.ORANGE, "#F9801D ");
put(MapColor.MAGENTA, "m ");
put(MapColor.LIGHT_BLUE, "t ");
put(MapColor.YELLOW, "y ");
put(MapColor.LIME, "l ");
put(MapColor.PINK, "#FFACCB ");
put(MapColor.GRAY, "f ");
put(MapColor.LIGHT_GRAY, "g ");
put(MapColor.CYAN, "c ");
put(MapColor.PURPLE, "p ");
put(MapColor.BLUE, "v ");
put(MapColor.BROWN, "#835432 ");
put(MapColor.GREEN, "e ");
put(MapColor.RED, "r ");
put(MapColor.BLACK, "k ");
public static final HashMap<MaterialColor,String> Material2DyeName = new HashMap<MaterialColor, String>(){{
put(MaterialColor.SNOW, "w ");
put(MaterialColor.COLOR_ORANGE, "#F9801D ");
put(MaterialColor.COLOR_MAGENTA, "m ");
put(MaterialColor.COLOR_LIGHT_BLUE, "t ");
put(MaterialColor.COLOR_YELLOW, "y ");
put(MaterialColor.COLOR_LIGHT_GREEN, "l ");
put(MaterialColor.COLOR_PINK, "#FFACCB ");
put(MaterialColor.COLOR_GRAY, "f ");
put(MaterialColor.COLOR_LIGHT_GRAY, "g ");
put(MaterialColor.COLOR_CYAN, "c ");
put(MaterialColor.COLOR_PURPLE, "p ");
put(MaterialColor.COLOR_BLUE, "v ");
put(MaterialColor.COLOR_BROWN, "#835432 ");
put(MaterialColor.COLOR_GREEN, "e ");
put(MaterialColor.COLOR_RED, "r ");
put(MaterialColor.COLOR_BLACK, "k ");
}};
static
{
for (DyeColor color: DyeColor.values())
{
Material2Dye.put(color.getMapColor(),color);
Material2Dye.put(color.getMaterialColor(),color);
}
}
@@ -68,7 +67,7 @@ public class WoolTool
* <li>Green - Prints the contents of the counter of the colour of wool underneath the carpet</li>
* </ul>
*/
public static void carpetPlacedAction(DyeColor color, PlayerEntity placer, BlockPos pos, ServerWorld worldIn)
public static void carpetPlacedAction(DyeColor color, Player placer, BlockPos pos, ServerLevel worldIn)
{
if (!CarpetSettings.carpets)
{
@@ -88,23 +87,23 @@ public class WoolTool
case BROWN:
if (!"false".equals(CarpetSettings.commandDistance))
{
ServerCommandSource source = placer.getCommandSource();
if (!DistanceCalculator.hasStartingPoint(source) || placer.isSneaking()) {
DistanceCalculator.setStart(source, Vec3d.of(pos) ); // zero padded pos
CommandSourceStack source = placer.createCommandSourceStack();
if (!DistanceCalculator.hasStartingPoint(source) || placer.isShiftKeyDown()) {
DistanceCalculator.setStart(source, Vec3.atLowerCornerOf(pos) ); // zero padded pos
}
else {
DistanceCalculator.setEnd(source, Vec3d.of(pos));
DistanceCalculator.setEnd(source, Vec3.atLowerCornerOf(pos));
}
}
break;
case GRAY:
if (!"false".equals(CarpetSettings.commandInfo))
Messenger.send(placer, BlockInfo.blockInfo(pos.down(), worldIn));
Messenger.send(placer, BlockInfo.blockInfo(pos.below(), worldIn));
break;
case GREEN:
if (CarpetSettings.hopperCounters)
{
DyeColor under = getWoolColorAtPosition(worldIn, pos.down());
DyeColor under = getWoolColorAtPosition(worldIn, pos.below());
if (under == null) return;
HopperCounter counter = HopperCounter.getCounter(under.toString());
if (counter != null)
@@ -114,12 +113,12 @@ public class WoolTool
case RED:
if (CarpetSettings.hopperCounters)
{
DyeColor under = getWoolColorAtPosition(worldIn, pos.down());
DyeColor under = getWoolColorAtPosition(worldIn, pos.below());
if (under == null) return;
HopperCounter counter = HopperCounter.getCounter(under.toString());
if (counter == null) return;
counter.reset(placer.getServer());
List<BaseText> res = new ArrayList<>();
List<BaseComponent> res = new ArrayList<>();
res.add(Messenger.s(String.format("%s counter reset",under.toString())));
Messenger.send(placer, res);
}
@@ -130,10 +129,10 @@ public class WoolTool
/**
* Gets the colour of wool at the position, for hoppers to be able to decide whether to add their items to the global counter.
*/
public static DyeColor getWoolColorAtPosition(World worldIn, BlockPos pos)
public static DyeColor getWoolColorAtPosition(Level worldIn, BlockPos pos)
{
BlockState state = worldIn.getBlockState(pos);
if (state.getMaterial() != Material.WOOL || !state.isSolidBlock(worldIn, pos)) //isSimpleFullBlock
if (state.getMaterial() != Material.WOOL || !state.isRedstoneConductor(worldIn, pos)) //isSimpleFullBlock
return null;
return Material2Dye.get(state.getMapColor(worldIn, pos));
}