Merge branch 'basic_systems'

# Conflicts:
#	src/main/java/carpet/commands/SpawnCommand.java
#	src/main/java/carpet/helpers/CtrlQCrafting.javax
#	src/main/java/carpet/utils/HUDController.java
#	src/main/java/carpet/utils/SpawnReporter.java
#	src/main/resources/carpet.mixins.json
This commit is contained in:
gnembon committed 2019-05-13 01:51:36 -03:00
commit 5109263fd8
48 files changed
+6071 -54

No files matched your search

+239
View File
@@ -0,0 +1,239 @@
package carpet.utils;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnType;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.block.Material;
import net.minecraft.block.MaterialColor;
import net.minecraft.block.BlockState;
import net.minecraft.entity.mob.MobEntityWithAi;
import net.minecraft.entity.ai.goal.WanderAroundGoal;
import net.minecraft.entity.ai.PathfindingUtil;
import net.minecraft.entity.mob.ZombiePigmanEntity;
import net.minecraft.block.BlockPlacementEnvironment;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.Registry;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BlockInfo
{
public static Map<BlockSoundGroup, String> soundName = new HashMap<BlockSoundGroup, String>() {{
put(BlockSoundGroup.WOOD, "wood" );
put(BlockSoundGroup.GRAVEL, "gravel");
put(BlockSoundGroup.GRASS, "grass" );
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.LADDER, "ladder");
put(BlockSoundGroup.ANVIL , "anvil" );
put(BlockSoundGroup.SLIME , "slime" );
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.field_18852 , "gourd" );
put(BlockSoundGroup.NETHER_WART , "wart" );
put(BlockSoundGroup.LANTERN , "lantern" );
}};
public static Map<MaterialColor, String> mapColourName = new HashMap<MaterialColor, String>() {{
put(MaterialColor.AIR , "air" );
put(MaterialColor.GRASS , "grass" );
put(MaterialColor.SAND , "sand" );
put(MaterialColor.WEB , "wool" );
put(MaterialColor.LAVA , "tnt" );
put(MaterialColor.ICE , "ice" );
put(MaterialColor.IRON , "iron" );
put(MaterialColor.FOLIAGE , "foliage" );
put(MaterialColor.WHITE , "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.ORANGE , "adobe" );
put(MaterialColor.MAGENTA , "magenta" );
put(MaterialColor.LIGHT_BLUE, "light_blue");
put(MaterialColor.YELLOW , "yellow" );
put(MaterialColor.LIME , "lime" );
put(MaterialColor.PINK , "pink" );
put(MaterialColor.GRAY , "gray" );
put(MaterialColor.LIGHT_GRAY, "light_gray");
put(MaterialColor.CYAN , "cyan" );
put(MaterialColor.PURPLE , "purple" );
put(MaterialColor.BLUE , "blue" );
put(MaterialColor.BROWN , "brown" );
put(MaterialColor.GREEN , "green" );
put(MaterialColor.RED , "red" );
put(MaterialColor.BLACK , "black" );
put(MaterialColor.GOLD , "gold" );
put(MaterialColor.DIAMOND , "diamond" );
put(MaterialColor.LAPIS , "lapis" );
put(MaterialColor.EMERALD , "emerald" );
put(MaterialColor.SPRUCE , "obsidian" );
put(MaterialColor.NETHER, "netherrack"); //TODO fix these
put(MaterialColor.WHITE_TERRACOTTA , "white_terracotta" );
put(MaterialColor.ORANGE_TERRACOTTA , "orange_terracotta" );
put(MaterialColor.MAGENTA_TERRACOTTA , "magenta_terracotta" );
put(MaterialColor.LIGHT_BLUE_TERRACOTTA, "light_blue_terracotta" );
put(MaterialColor.YELLOW_TERRACOTTA , "yellow_terracotta" );
put(MaterialColor.LIME_TERRACOTTA , "lime_terracotta" );
put(MaterialColor.PINK_TERRACOTTA , "pink_terracotta" );
put(MaterialColor.GRAY_TERRACOTTA , "gray_terracotta" );
put(MaterialColor.LIGHT_GRAY_TERRACOTTA, "light_gray_terracotta" );
put(MaterialColor.CYAN_TERRACOTTA , "cyan_terracotta" );
put(MaterialColor.PURPLE_TERRACOTTA , "purple_terracotta" );
put(MaterialColor.BLUE_TERRACOTTA , "blue_terracotta" );
put(MaterialColor.BROWN_TERRACOTTA , "brown_terracotta" );
put(MaterialColor.GREEN_TERRACOTTA , "green_terracotta" );
put(MaterialColor.RED_TERRACOTTA , "red_terracotta" );
put(MaterialColor.BLACK_TERRACOTTA , "black_terracotta" );
}};
public static Map<Material, String> materialName = new HashMap<Material, String>() {{
put(Material.AIR , "air" );
put(Material.STRUCTURE_VOID , "void" );
put(Material.PORTAL , "portal" );
put(Material.CARPET , "carpet" );
put(Material.PLANT , "plant" );
put(Material.UNDERWATER_PLANT , "water_plant" );
put(Material.REPLACEABLE_PLANT , "vine" );
put(Material.SEAGRASS , "sea_grass" );
put(Material.WATER , "water" );
put(Material.BUBBLE_COLUMN , "bubble_column");
put(Material.LAVA , "lava" );
put(Material.SNOW , "snow_layer" );
put(Material.FIRE , "fire" );
put(Material.PART , "redstone_bits");
put(Material.COBWEB , "cobweb" );
put(Material.REDSTONE_LAMP , "redstone_lamp");
put(Material.CLAY , "clay" );
put(Material.EARTH , "dirt" );
put(Material.ORGANIC , "grass" );
put(Material.PACKED_ICE , "packed_ice" );
put(Material.SAND , "sand" );
put(Material.SPONGE , "sponge" );
put(Material.SHULKER_BOX , "wood" );
put(Material.WOOD , "wool" ); // fix these
put(Material.BAMBOO_SAPLING , "shoots" );
put(Material.BAMBOO , "bamboo" );
put(Material.TNT , "tnt" );
put(Material.LEAVES , "leaves" );
put(Material.GLASS , "glass" );
put(Material.ICE , "ice" );
put(Material.CACTUS , "cactus" );
put(Material.STONE , "stone" );
put(Material.METAL , "iron" );
put(Material.SNOW_BLOCK , "snow" );
put(Material.ANVIL , "anvil" );
put(Material.BARRIER , "barrier" );
put(Material.PISTON , "piston" );
put(Material.UNUSED_PLANT , "coral" );
put(Material.PUMPKIN , "gourd" );
put(Material.DRAGON_EGG , "dragon_egg" );
put(Material.CAKE , "cake" );
}};
public static List<BaseComponent> blockInfo(BlockPos pos, World 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())
{
metastring += ", "+iproperty.getName() + '='+state.get(iproperty);
}
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(" - Material: %s", materialName.get(material))));
lst.add(Messenger.s(String.format(" - Map colour: %s", mapColourName.get(state.getTopMaterialColor(world, pos)))));
lst.add(Messenger.s(String.format(" - Sound type: %s", soundName.get(block.getSoundGroup(state)))));
lst.add(Messenger.s(""));
//lst.add(Messenger.s(String.format(" - Full block: %s", block.isShapeFullCube()))); // isFullCube() )));
lst.add(Messenger.s(String.format(" - Normal cube: %s", state.isSimpleFullBlock(world, pos)))); //isNormalCube())));
lst.add(Messenger.s(String.format(" - Is liquid: %s", material.isLiquid())));
lst.add(Messenger.s(String.format(" - Is solid: %s", material.isSolid())));
lst.add(Messenger.s(""));
lst.add(Messenger.s(String.format(" - Light in: %d, above: %d", world.getLightLevel(pos), world.getLightLevel(pos.up()))));
lst.add(Messenger.s(String.format(" - Brightness in: %.2f, above: %.2f", world.getBrightness(pos), world.getBrightness(pos.up()))));
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.propagatesSkylightDown(world, pos))));
//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.canSuffocate(world, pos))));
lst.add(Messenger.s(String.format(" - Blocks movement on land: %s", !state.canPlaceAtSide(world,pos, BlockPlacementEnvironment.LAND))));
lst.add(Messenger.s(String.format(" - Blocks movement in air: %s", !state.canPlaceAtSide(world,pos, BlockPlacementEnvironment.AIR))));
lst.add(Messenger.s(String.format(" - Blocks movement in liquids: %s", !state.canPlaceAtSide(world,pos, BlockPlacementEnvironment.WATER))));
lst.add(Messenger.s(String.format(" - Can burn: %s", material.isBurnable())));
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(""));
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(""));
lst.add(wander_chances(pos.up(), world));
return lst;
}
private static BaseComponent wander_chances(BlockPos pos, World worldIn)
{
MobEntityWithAi creature = new ZombiePigmanEntity(EntityType.ZOMBIE_PIGMAN, worldIn);
creature.initialize(worldIn, worldIn.getLocalDifficulty(pos), SpawnType.NATURAL, null, null);
creature.setPositionAndAngles(pos.getX()+0.5F, pos.getY(), pos.getZ()+0.5F, 0.0F, 0.0F);
WanderAroundGoal wander = new WanderAroundGoal(creature, 0.8D);
int success = 0;
for (int i=0; i<1000; i++)
{
Vec3d vec = PathfindingUtil.findTarget(creature, 10, 7);
if (vec == null)
{
continue;
}
success++;
}
long total_ticks = 0;
for (int trie=0; trie<1000; trie++)
{
int i;
for (i=1;i<30*20*60; i++) //*60 used to be 5 hours, limited to 30 mins
{
if (wander.canStart())
{
break;
}
}
total_ticks += 3*i;
}
creature.remove();
long total_time = (total_ticks)/1000/20;
return Messenger.s(String.format(" - Wander chance above: %.1f%%%%\n - Average standby above: %s",
(100.0F*success)/1000,
((total_time>5000)?"INFINITY":(Long.toString(total_time)+" s"))
));
}
}
@@ -0,0 +1,372 @@
package carpet.utils;
import carpet.CarpetSettings;
import net.minecraft.entity.Entity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.util.registry.Registry;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class CarpetProfiler
{
private static final HashMap<String, Long> time_repo = new HashMap<>();
public static int tick_health_requested = 0;
private static int tick_health_elapsed = 0;
private static int test_type = 0; //1 for ticks, 2 for entities;
private static String current_section = null;
private static long current_section_start = 0;
private static long current_tick_start = 0;
private static String [] GENERAL_SECTIONS = {"Network", "Autosave"};
private static String [] DIMENSIONS = {"Overworld","The End","The Nether"};
private static String [] SECTIONS = {"Spawning","Blocks","Entities","Tile Entities","Entities(client)","Tile Entities(client)","Villages"};
public static void prepare_tick_report(int ticks)
{
//maybe add so it only spams the sending player, but honestly - all may want to see it
time_repo.clear();
test_type = 1;
time_repo.put("tick",0L);
time_repo.put("Network",0L);
time_repo.put("Autosave",0L);
for (String section: GENERAL_SECTIONS)
{
time_repo.put(section,0L);
}
for (String level: DIMENSIONS)
{
for (String section: SECTIONS)
{
time_repo.put(level+"."+section,0L);
}
}
tick_health_elapsed = ticks;
tick_health_requested = ticks;
current_tick_start = 0L;
current_section_start = 0L;
current_section = null;
}
public static void start_section(String dimension, String name)
{
if (tick_health_requested == 0L || test_type != 1)
{
return;
}
if (current_tick_start == 0L)
{
return;
}
if (current_section != null)
{
end_current_section();
}
String key = name;
if (dimension != null)
{
key = dimension+"."+name;
}
current_section = key;
current_section_start = System.nanoTime();
}
public static class ProfilerToken
{
public String section;
public long start;
public ProfilerToken(String name, long start)
{
this.section = name;
this.start = start;
}
}
public static ProfilerToken start_section_concurrent(String dimension, String name, boolean isRemote)
{
if (tick_health_requested == 0L || test_type != 1)
{
return null;
}
if (current_tick_start == 0L)
{
return null;
}
String key = name;
if (dimension != null)
{
key = dimension+"."+name;
}
if (isRemote) key += "(client)";
long time = System.nanoTime();
return new ProfilerToken(key, time);
}
public static ProfilerToken start_entity_section(String dimension, Entity e)
{
if (tick_health_requested == 0L || test_type != 2)
{
return null;
}
if (current_tick_start == 0L)
{
return null;
}
String section = dimension+"."+ Registry.ENTITY_TYPE.getId(e.getType()).toString().replaceFirst("minecraft:","");
if (e.getEntityWorld().isClient)
section += "(client)";
long section_start = System.nanoTime();
return new ProfilerToken(section, section_start);
}
public static ProfilerToken start_tileentity_section(String dimension, BlockEntity e)
{
if (tick_health_requested == 0L || test_type != 2)
{
return null;
}
if (current_tick_start == 0L)
{
return null;
}
String section = dimension+"."+ BlockEntityType.getId(e.getType()).toString().replaceFirst("minecraft:","");
if (e.getWorld() == null)
section += "??";
else if (e.getWorld().isClient)
section += "(client)";
long section_start = System.nanoTime();
return new ProfilerToken(section, section_start);
}
public static void end_current_section()
{
if (tick_health_requested == 0L || test_type != 1)
{
return;
}
long end_time = System.nanoTime();
if (current_tick_start == 0L)
{
return;
}
if (current_section == null)
{
CarpetSettings.LOG.error("finishing section that hasn't started");
return;
}
//CarpetSettings.LOG.error("finishing section "+current_section);
time_repo.put(current_section,time_repo.get(current_section)+end_time-current_section_start);
current_section = null;
current_section_start = 0;
}
public static void end_current_section_concurrent(ProfilerToken tok)
{
if (tick_health_requested == 0L || test_type != 1)
{
return;
}
long end_time = System.nanoTime();
if (current_tick_start == 0L)
{
return;
}
if (tok == null)
{
CarpetSettings.LOG.error("finishing section that hasn't started");
return;
}
//CarpetSettings.LOG.error("finishing section "+current_section);
time_repo.put(tok.section,time_repo.get(tok.section)+end_time-tok.start);
}
public static void end_current_entity_section(ProfilerToken tok)
{
if (tick_health_requested == 0L || test_type != 2)
{
return;
}
long end_time = System.nanoTime();
if (current_tick_start == 0L)
{
return;
}
if (tok == null)
{
CarpetSettings.LOG.error("finishing entity/TE section that hasn't started");
return;
}
String time_section = "t."+tok.section;
String count_section = "c."+tok.section;
time_repo.put(time_section,time_repo.getOrDefault(time_section,0L)+end_time-tok.start);
time_repo.put(count_section,time_repo.getOrDefault(count_section,0L)+1);
}
public static void start_tick_profiling()
{
current_tick_start = System.nanoTime();
}
public static void end_tick_profiling(MinecraftServer server)
{
if (current_tick_start == 0L)
{
return;
}
time_repo.put("tick",time_repo.get("tick")+System.nanoTime()-current_tick_start);
tick_health_elapsed --;
//CarpetSettings.LOG.error("tick count current at "+time_repo.get("tick"));
if (tick_health_elapsed <= 0)
{
finalize_tick_report(server);
}
}
public static void finalize_tick_report(MinecraftServer server)
{
if (test_type == 1)
{
finalize_tick_report_for_time(server);
}
if (test_type == 2)
{
finalize_tick_report_for_entities(server);
}
cleanup_tick_report();
}
public static void cleanup_tick_report()
{
time_repo.clear();
time_repo.put("tick",0L);
test_type = 0;
tick_health_elapsed = 0;
tick_health_requested = 0;
current_tick_start = 0L;
current_section_start = 0L;
current_section = null;
}
public static void finalize_tick_report_for_time(MinecraftServer server)
{
//print stats
long total_tick_time = time_repo.get("tick");
double divider = 1.0D/tick_health_requested/1000000;
Messenger.print_server_message(server, String.format("Average tick time: %.3fms",divider*total_tick_time));
long accumulated = 0L;
for (String section: GENERAL_SECTIONS)
{
double amount = divider*time_repo.get(section);
if (amount > 0.01)
{
accumulated += time_repo.get(section);
Messenger.print_server_message(server, String.format("%s: %.3fms", section, amount));
}
}
for (String dimension: DIMENSIONS)
{
boolean hasSomethin = false;
for (String section: SECTIONS)
{
double amount = divider*time_repo.get(dimension+"."+section);
if (amount > 0.01)
{
hasSomethin = true;
break;
}
}
if (!(hasSomethin))
{
continue;
}
Messenger.print_server_message(server, dimension+":");
for (String section: SECTIONS)
{
double amount = divider*time_repo.get(dimension+"."+section);
if (amount > 0.01)
{
if (!(section.endsWith("(client)")))
accumulated += time_repo.get(dimension+"."+section);
Messenger.print_server_message(server, String.format(" - %s: %.3fms", section, amount));
}
}
}
long rest = total_tick_time-accumulated;
Messenger.print_server_message(server, String.format("The Rest, whatever that might be: %.3fms",divider*rest));
}
public static void finalize_tick_report_for_entities(MinecraftServer server)
{
//print stats
long total_tick_time = time_repo.get("tick");
double divider = 1.0D/tick_health_requested/1000000;
double divider_1 = 1.0D/(tick_health_requested-1)/1000000;
Messenger.print_server_message(server, String.format("Average tick time: %.3fms",divider*total_tick_time));
time_repo.remove("tick");
Messenger.print_server_message(server, "Top 10 counts:");
int total = 0;
for ( Map.Entry<String, Long> entry : time_repo.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList()) )
{
if (entry.getKey().startsWith("t."))
{
continue;
}
total++;
if (total > 10)
{
continue;
}
String[] parts = entry.getKey().split("\\.");
String dim = parts[1];
String name = parts[2];
int penalty = name.endsWith("(client)") ? 1 :0;
Messenger.print_server_message(server, String.format(" - %s in %s: %.3f",name, dim, 1.0D*entry.getValue()/(tick_health_requested-penalty)));
}
Messenger.print_server_message(server, "Top 10 grossing:");
total = 0;
for ( Map.Entry<String, Long> entry : time_repo.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList()) )
{
if (entry.getKey().startsWith("c."))
{
continue;
}
total++;
if (total > 10)
{
continue;
}
String[] parts = entry.getKey().split("\\.");
String dim = parts[1];
String name = parts[2];
double applicableDivider = name.endsWith("(client)") ? divider :divider_1;
Messenger.print_server_message(server, String.format(" - %s in %s: %.3fms",name, dim, applicableDivider*entry.getValue()));
}
}
public static void prepare_entity_report(int ticks)
{
//maybe add so it only spams the sending player, but honestly - all may want to see it
time_repo.clear();
time_repo.put("tick",0L);
test_type = 2;
tick_health_elapsed = ticks;
tick_health_requested = ticks;
current_tick_start = 0L;
current_section_start = 0L;
current_section = null;
}
}
@@ -0,0 +1,64 @@
package carpet.utils;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.network.chat.BaseComponent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class DistanceCalculator
{
public static final HashMap<String, Vec3d> START_POINT_STORAGE = new HashMap<>();
public static boolean hasStartingPoint(ServerCommandSource source)
{
return START_POINT_STORAGE.containsKey(source.getName());
}
public static List<BaseComponent> findDistanceBetweenTwoPoints(Vec3d pos1, Vec3d 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 manhattan = dx+dy+dz;
double spherical = MathHelper.sqrt(dx*dx + dy*dy + dz*dz);
double cylindrical = MathHelper.sqrt(dx*dx + dz*dz);
List<BaseComponent> res = new ArrayList<>();
res.add(Messenger.c("w Distance between ",
Messenger.tp("c",pos1),"w and ",
Messenger.tp("c",pos2),"w :"));
res.add(Messenger.c("w - Manhattan: ", String.format("wb %.1f", manhattan)));
res.add(Messenger.c("w - Spherical: ", String.format("wb %.2f", spherical)));
res.add(Messenger.c("w - Cylindrical: ", String.format("wb %.2f", cylindrical)));
return res;
}
public static int distance(ServerCommandSource source, Vec3d pos1, Vec3d pos2)
{
Messenger.send(source, findDistanceBetweenTwoPoints(pos1, pos2));
return 1;
}
public static int setStart(ServerCommandSource source, Vec3d pos)
{
START_POINT_STORAGE.put(source.getName(), pos);
Messenger.m(source,"gi Initial point set to: ", Messenger.tp("g",pos));
return 1;
}
public static int setEnd(ServerCommandSource source, Vec3d pos)
{
if ( !hasStartingPoint(source) )
{
START_POINT_STORAGE.put(source.getName(), pos);
Messenger.m(source,"gi There was no initial point for "+source.getName());
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));
return 1;
}
}
+101
View File
@@ -0,0 +1,101 @@
package carpet.utils;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
// not really needed anymore
public class EntityInfo
{
private static String makeTime(long ticks)
{
long secs = ticks/20;
if (secs < 60)
{
return String.format("%d\"", secs);
}
if (secs < 60*60)
{
return String.format("%d'%d\"", secs/60, secs%60);
}
return String.format("%dh%d'%d\"", secs/60/60, (secs % (60*60))/60,(secs % (60*60))%60 );
}
private static String display_item(ItemStack item)
{
if (item == null)
{
return null;
}
if (item.isEmpty()) // func_190926_b()
{
return null;
} // func_190916_E()
String stackname = item.getAmount()>1?String.format("%dx%s",item.getAmount(), item.getDisplayName().getString()):item.getDisplayName().getString();
if (item.isDamaged())
{
stackname += String.format(" %d/%d", item.getMaxUseTime()-item.getDamage(), item.getMaxUseTime());
}
if (item.hasEnchantments())
{
stackname += " ( ";
Map<Enchantment, Integer> enchants = EnchantmentHelper.getEnchantments(item);
for (Enchantment e: enchants.keySet())
{
int level = enchants.get(e);
String enstring = e.getTextComponent(level).getString();
stackname += enstring+" ";
}
stackname += ")";
}
return stackname;
}
public static String entity_short_string(Entity e)
{
if (e == null)
{
return "None";
}
return String.format("%s at [%.1f, %.1f, %.1f]",e.getDisplayName().getString(), e.x, e.y, e.y);
}
private static double get_speed(double internal)
{
return 43.1*internal;
}
private static double get_horse_speed_percent(double internal)
{
double min = 0.45*0.25;
double max = (0.45+0.9)*0.25;
return 100*(internal-min)/(max-min);
}
private static double get_horse_jump(double x)
{
return -0.1817584952 * x*x*x + 3.689713992 * x*x + 2.128599134 * x - 0.343930367;
}
private static double get_horse_jump_percent(double internal)
{
double min = 0.4;
double max = 1.0;
return 100*(internal-min)/(max-min);
}
public static List<BaseComponent> entityInfo(Entity e, World source_world)
{
List<BaseComponent> lst = new ArrayList<>();
lst.add(Messenger.s("w Use /data get entity command"));
return lst;
}
}
@@ -0,0 +1,13 @@
package carpet.utils;
import java.util.LinkedHashMap;
import java.util.Map;
public class EvictingQueue<K,V> extends LinkedHashMap<K,V>
{
@Override
protected boolean removeEldestEntry(Map.Entry<K, V> eldest)
{
return this.size() > 10;
}
}
@@ -0,0 +1,184 @@
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.EntityCategory;
import net.minecraft.entity.SpawnRestriction;
import net.minecraft.entity.SpawnType;
import net.minecraft.entity.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 java.util.ArrayList;
import java.util.List;
public class PerimeterDiagnostics
{
public static class Result
{
public int liquid;
public int ground;
public int specific;
public List<BlockPos> samples;
Result()
{
samples = new ArrayList<>();
}
}
private Biome.SpawnEntry sle;
private ServerWorld worldServer;
private EntityCategory ctype;
private MobEntity el;
private PerimeterDiagnostics(ServerWorld server, EntityCategory ctype, MobEntity el)
{
this.sle = null;
this.worldServer = server;
this.ctype = ctype;
this.el = el;
}
public static Result countSpots(ServerWorld worldserver, BlockPos epos, MobEntity el)
{
BlockPos pos;
//List<BlockPos> samples = new ArrayList<BlockPos>();
//if (el != null) CarpetSettings.LOG.error(String.format("Got %s to check",el.toString()));
int eY = epos.getY();
int eX = epos.getX();
int eZ = epos.getZ();
Result result = new Result();
//int ground_spawns = 0;
//int liquid_spawns = 0;
//int specific_spawns = 0;
boolean add_water = false;
boolean add_ground = false;
EntityCategory ctype = null;
if (el != null)
{
if (el instanceof WaterCreatureEntity)
{
add_water = true;
ctype = EntityCategory.WATER_CREATURE;
}
else if (el instanceof PassiveEntity)
{
add_ground = true;
ctype = EntityCategory.CREATURE;
}
else if (el instanceof Monster)
{
add_ground = true;
ctype = EntityCategory.MONSTER;
}
else if (el instanceof AmbientEntity)
{
ctype = EntityCategory.AMBIENT;
}
}
PerimeterDiagnostics diagnostic = new PerimeterDiagnostics(worldserver,ctype,el);
for (int x = -128; x <= 128; ++x)
{
for (int z = -128; z <= 128; ++z)
{
if (x*x + z*z > 128*128) // cut out a cyllinder first
{
continue;
}
for (int y= 0; y < 256; ++y)
{
if ((Math.abs(y-eY)>128) )
{
continue;
}
int distsq = (x)*(x)+(eY-y)*(eY-y)+(z)*(z);
if (distsq > 128*128 || distsq < 24*24)
{
continue;
}
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());
if ( iblockstate.getMaterial() == Material.WATER && iblockstate_down.getMaterial() == Material.WATER && !iblockstate_up.isSimpleFullBlock(worldserver, pos))
{
result.liquid++;
if (add_water && diagnostic.check_entity_spawn(pos))
{
result.specific++;
if (result.samples.size() < 10)
{
result.samples.add(pos);
}
}
}
else
{
if (iblockstate_down.isSimpleFullBlock(worldserver, pos))
{
Block block = iblockstate_down.getBlock();
boolean flag = block != Blocks.BEDROCK && block != Blocks.BARRIER;
if( flag && SpawnHelper.isClearForSpawn(worldserver, pos, iblockstate, iblockstate.getFluidState()) && SpawnHelper.isClearForSpawn(worldserver, pos.up(), iblockstate_up, iblockstate_up.getFluidState()))
{
result.ground ++;
if (add_ground && diagnostic.check_entity_spawn(pos))
{
result.specific++;
if (result.samples.size() < 10)
{
result.samples.add(pos);
}
}
}
}
}
}
}
}
//ashMap<String,Integer> result= new HashMap<>();
//result.put("Potential in-water spawning spaces", liquid_spawns);
//result.put("Potential on-ground spawning spaces", ground_spawns);
//if (el != null) result.put(String.format("%s spawning spaces",el.getDisplayName().getUnformattedText()),specific_spawns);
return result;
}
private boolean check_entity_spawn(BlockPos pos)
{
if (sle == null || !worldServer.getChunkManager().getChunkGenerator().getEntitySpawnList(ctype, pos).contains(sle))
{
sle = null;
for (Biome.SpawnEntry sle: worldServer.getChunkManager().getChunkGenerator().getEntitySpawnList(ctype, pos))
{
if (el.getType() == sle.type)
{
this.sle = sle;
break;
}
}
if (sle == null || !worldServer.getChunkManager().getChunkGenerator().getEntitySpawnList(ctype, pos).contains(sle))
{
return false;
}
}
SpawnRestriction.Location spt = SpawnRestriction.getLocation(sle.type);
if (SpawnHelper.canSpawn(spt, worldServer, pos, sle.type))
{
el.setPositionAndAngles((float)pos.getX() + 0.5F, (float)pos.getY(), (float)pos.getZ()+0.5F, 0.0F, 0.0F);
return el.canSpawn(worldServer) && el.canSpawn(worldServer, SpawnType.NATURAL) && worldServer.doesNotCollide(el); // check collision rules once they stop fiddling with them after 1.14.1
}
return false;
}
}
+102
View File
@@ -0,0 +1,102 @@
package carpet.utils;
import carpet.CarpetSettings;
import carpet.helpers.HopperCounter;
import net.minecraft.block.Material;
import net.minecraft.block.MaterialColor;
import net.minecraft.block.BlockState;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.DyeColor;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class WoolTool
{
private static final HashMap<MaterialColor,DyeColor> Material2Dye = new HashMap<>();
static
{
for (DyeColor color: DyeColor.values())
{
Material2Dye.put(color.getMaterialColor(),color);
}
}
public static void carpetPlacedAction(DyeColor color, PlayerEntity placer, BlockPos pos, World worldIn)
{
if (!CarpetSettings.getBool("carpets"))
{
return;
}
switch (color)
{
case PINK:
if (CarpetSettings.getBool("commandSpawn"))
Messenger.send(placer, SpawnReporter.report(pos, worldIn));
break;
case BLACK:
if (CarpetSettings.getBool("commandSpawn"))
Messenger.send(placer, SpawnReporter.show_mobcaps(pos, worldIn));
break;
case BROWN:
if (CarpetSettings.getBool("commandDistance"))
{
ServerCommandSource source = placer.getCommandSource();
if (!DistanceCalculator.hasStartingPoint(source) || placer.isSneaking()) {
DistanceCalculator.setStart(source, new Vec3d(pos));
}
else {
DistanceCalculator.setEnd(source, new Vec3d(pos));
}
}
break;
case GRAY:
if (CarpetSettings.getBool("commandInfo"))
Messenger.send(placer, BlockInfo.blockInfo(pos.down(), worldIn));
break;
case YELLOW:
if (CarpetSettings.getBool("commandInfo"))
Messenger.m(placer, "r use data get entity command");
//EntityInfo.issue_entity_info(placer);
break;
case GREEN:
if (CarpetSettings.getBool("hopperCounters"))
{
DyeColor under = getWoolColorAtPosition(worldIn, pos.down());
if (under == null) return;
HopperCounter counter = HopperCounter.getCounter(under.toString());
if (counter != null)
Messenger.send(placer, counter.format(worldIn.getServer(), false, false));
}
break;
case RED:
if (CarpetSettings.getBool("hopperCounters"))
{
DyeColor under = getWoolColorAtPosition(worldIn, pos.down());
if (under == null) return;
HopperCounter counter = HopperCounter.getCounter(under.toString());
if (counter == null) return;
counter.reset(placer.getServer());
List<BaseComponent> res = new ArrayList<>();
res.add(Messenger.s(String.format("%s counter reset",under.toString())));
Messenger.send(placer, res);
}
break;
}
}
public static DyeColor getWoolColorAtPosition(World worldIn, BlockPos pos)
{
BlockState state = worldIn.getBlockState(pos);
if (state.getMaterial() != Material.WOOL || !state.isSimpleFullBlock(worldIn, pos))
return null;
return Material2Dye.get(state.getTopMaterialColor(worldIn, pos));
}
}