22w16b with massive Component changes

This commit is contained in:
gnembon committed 2022-04-21 00:26:39 +02:00
1 parent 8101abb431
commit 746c8548e9
31 files changed
+153 -162

No files matched your search

+4 -4
View File
@@ -5,7 +5,7 @@ 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.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobSpawnType;
@@ -221,7 +221,7 @@ public class BlockInfo
entry(Material.POWDER_SNOW , "powder_snow")
);
public static List<BaseComponent> blockInfo(BlockPos pos, ServerLevel world)
public static List<Component> blockInfo(BlockPos pos, ServerLevel world)
{
BlockState state = world.getBlockState(pos);
Material material = state.getMaterial();
@@ -231,7 +231,7 @@ public class BlockInfo
{
metastring += ", "+iproperty.getName() + '='+state.getValue(iproperty);
}
List<BaseComponent> lst = new ArrayList<>();
List<Component> 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.getKey(block),metastring, Registry.BLOCK.getId(block), metastring )));
@@ -272,7 +272,7 @@ public class BlockInfo
return lst;
}
private static BaseComponent wander_chances(BlockPos pos, ServerLevel worldIn)
private static Component wander_chances(BlockPos pos, ServerLevel worldIn)
{
PathfinderMob creature = new ZombifiedPiglin(EntityType.ZOMBIFIED_PIGLIN, worldIn);
creature.finalizeSpawn(worldIn, worldIn.getCurrentDifficultyAt(pos), MobSpawnType.NATURAL, null, null);
@@ -4,7 +4,7 @@ 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.network.chat.Component;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.Vec3;
@@ -17,7 +17,7 @@ public class DistanceCalculator
return START_POINT_STORAGE.containsKey(source.getTextName());
}
public static List<BaseComponent> findDistanceBetweenTwoPoints(Vec3 pos1, Vec3 pos2)
public static List<Component> findDistanceBetweenTwoPoints(Vec3 pos1, Vec3 pos2)
{
double dx = Mth.abs((float)pos1.x-(float)pos2.x);
double dy = Mth.abs((float)pos1.y-(float)pos2.y);
@@ -25,7 +25,7 @@ public class DistanceCalculator
double manhattan = dx+dy+dz;
double spherical = Math.sqrt(dx*dx + dy*dy + dz*dz);
double cylindrical = Math.sqrt(dx*dx + dz*dz);
List<BaseComponent> res = new ArrayList<>();
List<Component> res = new ArrayList<>();
res.add(Messenger.c("w Distance between ",
Messenger.tp("c",pos1),"w and ",
Messenger.tp("c",pos2),"w :"));
+32 -32
View File
@@ -4,12 +4,12 @@ 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.Component;
import net.minecraft.network.chat.MutableComponent;
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.entity.MobCategory;
import net.minecraft.world.entity.player.Player;
@@ -114,11 +114,11 @@ public class Messenger
};
}
private static BaseComponent getChatComponentFromDesc(String message, BaseComponent previousMessage)
private static MutableComponent getChatComponentFromDesc(String message, MutableComponent previousMessage)
{
if (message.equalsIgnoreCase(""))
{
return new TextComponent("");
return Component.literal("");
}
if (Character.isWhitespace(message.charAt(0)))
{
@@ -133,12 +133,12 @@ public class Messenger
str = message.substring(limit+1);
}
if (previousMessage == null) {
BaseComponent text = new TextComponent(str);
MutableComponent text = Component.literal(str);
text.setStyle(parseStyle(desc));
return text;
}
Style previousStyle = previousMessage.getStyle();
BaseComponent ret = previousMessage;
MutableComponent 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 TextComponent(str);
ret = Component.literal(str);
ret.setStyle(parseStyle(desc));
yield previousStyle; // no op for the previous style
}
});
return ret;
}
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)
public static Component tp(String desc, Vec3 pos) { return tp(desc, pos.x, pos.y, pos.z); }
public static Component tp(String desc, BlockPos pos) { return tp(desc, pos.getX(), pos.getY(), pos.getZ()); }
public static Component tp(String desc, double x, double y, double z) { return tp(desc, (float)x, (float)y, (float)z);}
public static Component tp(String desc, float x, float y, float z)
{
return getCoordsTextComponent(desc, x, y, z, false);
}
public static BaseComponent tp(String desc, int x, int y, int z)
public static Component tp(String desc, int x, int y, int z)
{
return getCoordsTextComponent(desc, (float)x, (float)y, (float)z, true);
}
/// to be continued
public static BaseComponent dbl(String style, double double_value)
public static Component dbl(String style, double double_value)
{
return c(String.format("%s %.1f",style,double_value),String.format("^w %f",double_value));
}
public static BaseComponent dbls(String style, double ... doubles)
public static Component 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 BaseComponent dblf(String style, double ... doubles)
public static Component 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 BaseComponent dblt(String style, double ... doubles)
public static Component 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 BaseComponent getCoordsTextComponent(String style, float x, float y, float z, boolean isInt)
private static Component getCoordsTextComponent(String style, float x, float y, float z, boolean isInt)
{
String text;
String command;
@@ -243,20 +243,20 @@ public class Messenger
/*
composes single line, multicomponent message, and returns as one chat messagge
*/
public static BaseComponent c(Object ... fields)
public static Component c(Object ... fields)
{
BaseComponent message = new TextComponent("");
BaseComponent previousComponent = null;
MutableComponent message = Component.literal("");
MutableComponent previousComponent = null;
for (Object o: fields)
{
if (o instanceof BaseComponent)
if (o instanceof MutableComponent)
{
message.append((BaseComponent)o);
previousComponent = (BaseComponent)o;
message.append((MutableComponent)o);
previousComponent = (MutableComponent)o;
continue;
}
String txt = o.toString();
BaseComponent comp = getChatComponentFromDesc(txt, previousComponent);
MutableComponent comp = getChatComponentFromDesc(txt, previousComponent);
if (comp != previousComponent) message.append(comp);
previousComponent = comp;
}
@@ -265,13 +265,13 @@ public class Messenger
//simple text
public static BaseComponent s(String text)
public static Component s(String text)
{
return s(text,"");
}
public static BaseComponent s(String text, String style)
public static Component s(String text, String style)
{
BaseComponent message = new TextComponent(text);
MutableComponent message = Component.literal(text);
message.setStyle(parseStyle(style));
return message;
}
@@ -279,11 +279,11 @@ public class Messenger
public static void send(Player player, Collection<BaseComponent> lines)
public static void send(Player player, Collection<Component> lines)
{
lines.forEach(message -> player.sendMessage(message, Util.NIL_UUID));
}
public static void send(CommandSourceStack source, Collection<BaseComponent> lines)
public static void send(CommandSourceStack source, Collection<Component> lines)
{
lines.stream().forEachOrdered((s) -> source.sendSuccess(s, false));
}
@@ -293,14 +293,14 @@ public class Messenger
{
if (server == null)
LOG.error("Message not delivered: "+message);
server.sendMessage(new TextComponent(message), Util.NIL_UUID);
BaseComponent txt = c("gi "+message);
server.sendMessage(Component.literal(message), Util.NIL_UUID);
Component txt = c("gi "+message);
for (Player entityplayer : server.getPlayerList().getPlayers())
{
entityplayer.sendMessage(txt, Util.NIL_UUID);
}
}
public static void print_server_message(MinecraftServer server, BaseComponent message)
public static void print_server_message(MinecraftServer server, Component message)
{
if (server == null)
LOG.error("Message not delivered: "+message.getString());
+12 -12
View File
@@ -7,7 +7,7 @@ import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
@@ -104,11 +104,11 @@ public class SpawnReporter
return MAGIC_NUMBER / (Math.pow(2.0,(SpawnReporter.mobcap_exponent/4)));
}*/
public static List<BaseComponent> printMobcapsForDimension(ServerLevel world, boolean multiline)
public static List<Component> printMobcapsForDimension(ServerLevel world, boolean multiline)
{
ResourceKey<Level> dim = world.dimension();
String name = dim.location().getPath();
List<BaseComponent> lst = new ArrayList<>();
List<Component> lst = new ArrayList<>();
if (multiline)
lst.add(Messenger.s(String.format("Mobcaps for %s:",name)));
NaturalSpawner.SpawnState lastSpawner = world.getChunkSource().getLastSpawnState();
@@ -159,9 +159,9 @@ public class SpawnReporter
return lst;
}
public static List<BaseComponent> recent_spawns(Level world, MobCategory creature_type)
public static List<Component> recent_spawns(Level world, MobCategory creature_type)
{
List<BaseComponent> lst = new ArrayList<>();
List<Component> lst = new ArrayList<>();
if ((track_spawns == 0L))
{
lst.add(Messenger.s("Spawn tracking not started"));
@@ -187,7 +187,7 @@ public class SpawnReporter
}
public static List<BaseComponent> show_mobcaps(BlockPos pos, ServerLevel worldIn)
public static List<Component> show_mobcaps(BlockPos pos, ServerLevel worldIn)
{
DyeColor under = WoolTool.getWoolColorAtPosition(worldIn, pos.below());
if (under == null)
@@ -281,9 +281,9 @@ public class SpawnReporter
return get_type_string(get_creature_type_from_code(str));
}
public static List<BaseComponent> printEntitiesByType(MobCategory cat, Level worldIn, boolean all) //Class<?> entityType)
public static List<Component> printEntitiesByType(MobCategory cat, Level worldIn, boolean all) //Class<?> entityType)
{
List<BaseComponent> lst = new ArrayList<>();
List<Component> lst = new ArrayList<>();
lst.add( Messenger.s(String.format("Loaded entities for %s class:", get_type_string(cat))));
for (Entity entity : ((ServerLevel)worldIn).getEntities(EntityTypeTest.forClass(Entity.class), (e) -> e.getType().getCategory()==cat))
{
@@ -350,10 +350,10 @@ public class SpawnReporter
return "("+world.location().getPath().toUpperCase(Locale.ROOT).replace("THE_","").charAt(0)+")";
}
public static List<BaseComponent> tracking_report(Level worldIn)
public static List<Component> tracking_report(Level worldIn)
{
List<BaseComponent> report = new ArrayList<>();
List<Component> report = new ArrayList<>();
if (track_spawns == 0L)
{
report.add(Messenger.c(
@@ -439,9 +439,9 @@ public class SpawnReporter
}
}
public static List<BaseComponent> report(BlockPos pos, ServerLevel worldIn)
public static List<Component> report(BlockPos pos, ServerLevel worldIn)
{
List<BaseComponent> rep = new ArrayList<>();
List<Component> rep = new ArrayList<>();
int x = pos.getX(); int y = pos.getY(); int z = pos.getZ();
ChunkAccess chunk = worldIn.getChunk(pos);
int lc = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, x, z) + 1;
+2 -2
View File
@@ -7,7 +7,7 @@ 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.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.DyeColor;
@@ -118,7 +118,7 @@ public class WoolTool
HopperCounter counter = HopperCounter.getCounter(under.toString());
if (counter == null) return;
counter.reset(placer.getServer());
List<BaseComponent> res = new ArrayList<>();
List<Component> res = new ArrayList<>();
res.add(Messenger.s(String.format("%s counter reset",under.toString())));
Messenger.send(placer, res);
}