Fix more warnings and do some small optimizations (#1356)
* Fix more warnings and do some small optimizations * Fix more warnings in ValueConversions * Clean up some decompiler names and fix an unnecessary transformation around commands * Use (way) more compact data structure for slot map * Minor tweaks Such as map directly in the collector * I hate vanilla javac Revert map changes in latest commit
This commit is contained in:
1 parent
e4dc080657
commit
f18cfb09d2
18 files changed
+116
-139
No files matched your search
@@ -15,7 +15,6 @@ import carpet.script.EntityEventsGroup;
|
||||
import carpet.script.argument.Vector3Argument;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.utils.InputValidator;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
@@ -302,25 +301,25 @@ public class EntityValue extends Value
|
||||
|
||||
EntityClassDescriptor(EntityType<?> type, Predicate<? super Entity> predicate, Stream<EntityType<?>> types)
|
||||
{
|
||||
this(type, predicate, types.collect(Collectors.toList()));
|
||||
this(type, predicate, types.toList());
|
||||
}
|
||||
|
||||
EntityClassDescriptor(EntityTypeTest<Entity, ?> type, Predicate<? super Entity> predicate, Stream<EntityType<?>> types)
|
||||
{
|
||||
this(type, predicate, types.collect(Collectors.toList()));
|
||||
this(type, predicate, types.toList());
|
||||
}
|
||||
|
||||
public final static Map<String, EntityClassDescriptor> byName = new HashMap<String, EntityClassDescriptor>() {{
|
||||
List<EntityType<?>> allTypes = Registry.ENTITY_TYPE.stream().collect(Collectors.toList());
|
||||
public final static Map<String, EntityClassDescriptor> byName = new HashMap<>() {{
|
||||
List<EntityType<?>> allTypes = Registry.ENTITY_TYPE.stream().toList();
|
||||
// nonliving types
|
||||
Set<EntityType<?>> projectiles = Sets.newHashSet(
|
||||
Set<EntityType<?>> projectiles = Set.of(
|
||||
EntityType.ARROW, EntityType.DRAGON_FIREBALL, EntityType.FIREWORK_ROCKET,
|
||||
EntityType.FIREBALL, EntityType.LLAMA_SPIT, EntityType.SMALL_FIREBALL,
|
||||
EntityType.SNOWBALL, EntityType.SPECTRAL_ARROW, EntityType.EGG,
|
||||
EntityType.ENDER_PEARL, EntityType.EXPERIENCE_BOTTLE, EntityType.POTION,
|
||||
EntityType.TRIDENT, EntityType.WITHER_SKULL, EntityType.FISHING_BOBBER, EntityType.SHULKER_BULLET
|
||||
);
|
||||
Set<EntityType<?>> deads = Sets.newHashSet(
|
||||
Set<EntityType<?>> deads = Set.of(
|
||||
EntityType.AREA_EFFECT_CLOUD, EntityType.MARKER, EntityType.BOAT, EntityType.END_CRYSTAL,
|
||||
EntityType.EVOKER_FANGS, EntityType.EXPERIENCE_ORB, EntityType.EYE_OF_ENDER,
|
||||
EntityType.FALLING_BLOCK, EntityType.ITEM, EntityType.ITEM_FRAME, EntityType.GLOW_ITEM_FRAME,
|
||||
@@ -328,28 +327,28 @@ public class EntityValue extends Value
|
||||
EntityType.TNT, EntityType.ARMOR_STAND, EntityType.CHEST_BOAT
|
||||
|
||||
);
|
||||
Set<EntityType<?>> minecarts = Sets.newHashSet(
|
||||
Set<EntityType<?>> minecarts = Set.of(
|
||||
EntityType.MINECART, EntityType.CHEST_MINECART, EntityType.COMMAND_BLOCK_MINECART,
|
||||
EntityType.FURNACE_MINECART, EntityType.HOPPER_MINECART,
|
||||
EntityType.SPAWNER_MINECART, EntityType.TNT_MINECART
|
||||
);
|
||||
// living mob groups - non-defeault
|
||||
Set<EntityType<?>> undeads = Sets.newHashSet(
|
||||
Set<EntityType<?>> undeads = Set.of(
|
||||
EntityType.STRAY, EntityType.SKELETON, EntityType.WITHER_SKELETON,
|
||||
EntityType.ZOMBIE, EntityType.DROWNED, EntityType.ZOMBIE_VILLAGER,
|
||||
EntityType.ZOMBIE_HORSE, EntityType.SKELETON_HORSE, EntityType.PHANTOM,
|
||||
EntityType.WITHER, EntityType.ZOGLIN, EntityType.HUSK, EntityType.ZOMBIFIED_PIGLIN
|
||||
|
||||
);
|
||||
Set<EntityType<?>> arthropods = Sets.newHashSet(
|
||||
Set<EntityType<?>> arthropods = Set.of(
|
||||
EntityType.BEE, EntityType.ENDERMITE, EntityType.SILVERFISH, EntityType.SPIDER,
|
||||
EntityType.CAVE_SPIDER
|
||||
);
|
||||
Set<EntityType<?>> aquatique = Sets.newHashSet(
|
||||
Set<EntityType<?>> aquatique = Set.of(
|
||||
EntityType.GUARDIAN, EntityType.TURTLE, EntityType.COD, EntityType.DOLPHIN, EntityType.PUFFERFISH,
|
||||
EntityType.SALMON, EntityType.SQUID, EntityType.TROPICAL_FISH
|
||||
);
|
||||
Set<EntityType<?>> illagers = Sets.newHashSet(
|
||||
Set<EntityType<?>> illagers = Set.of(
|
||||
EntityType.PILLAGER, EntityType.ILLUSIONER, EntityType.VINDICATOR, EntityType.EVOKER,
|
||||
EntityType.RAVAGER, EntityType.WITCH
|
||||
);
|
||||
|
||||
@@ -516,7 +516,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
}
|
||||
try
|
||||
{
|
||||
CollectionTag<?> targetList = (CollectionTag) target;
|
||||
CollectionTag<?> targetList = (CollectionTag<?>) target;
|
||||
if (!targetList.addTag(index < 0 ? targetList.size() + index + 1 : index, newElement.copy()))
|
||||
return false;
|
||||
modified = true;
|
||||
|
||||
@@ -5,6 +5,8 @@ import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.exception.ThrowStatement;
|
||||
import carpet.script.exception.Throwables;
|
||||
import carpet.utils.BlockInfo;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import net.minecraft.advancements.critereon.MinMaxBounds;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.GlobalPos;
|
||||
@@ -55,12 +57,6 @@ public class ValueConversions
|
||||
return ListValue.of(new NumericValue(pos.getX()), new NumericValue(pos.getY()), new NumericValue(pos.getZ()));
|
||||
}
|
||||
|
||||
public static Value ofOptional(BlockPos pos)
|
||||
{
|
||||
if (pos == null) return Value.NULL;
|
||||
return ListValue.of(new NumericValue(pos.getX()), new NumericValue(pos.getY()), new NumericValue(pos.getZ()));
|
||||
}
|
||||
|
||||
public static Value of(Vec3 vec)
|
||||
{
|
||||
return ListValue.of(new NumericValue(vec.x), new NumericValue(vec.y), new NumericValue(vec.z));
|
||||
@@ -275,17 +271,17 @@ public class ValueConversions
|
||||
{
|
||||
v = new ArrayList(((Set) v));
|
||||
}
|
||||
if (v instanceof List l)
|
||||
if (v instanceof List<?> l)
|
||||
{
|
||||
if (l.isEmpty()) return ListValue.of();
|
||||
Object el = l.get(0);
|
||||
if (el instanceof Entity)
|
||||
{
|
||||
return ListValue.wrap((List<Value>) l.stream().map(o -> new EntityValue((Entity)o)).collect(Collectors.toList()));
|
||||
return ListValue.wrap(l.stream().map(o -> new EntityValue((Entity)o)).collect(Collectors.toList()));
|
||||
}
|
||||
if (el instanceof GlobalPos)
|
||||
{
|
||||
return ListValue.wrap((List<Value>) l.stream().map(o -> of((GlobalPos) o)).collect(Collectors.toList()));
|
||||
return ListValue.wrap(l.stream().map(o -> of((GlobalPos) o)).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
return Value.NULL;
|
||||
@@ -350,49 +346,53 @@ public class ValueConversions
|
||||
throw new InternalExpressionException("Unknown property type: "+p.getName());
|
||||
}
|
||||
|
||||
record SlotParam(/* Nullable */ String type, int id) {
|
||||
public ListValue build() {
|
||||
return ListValue.of(StringValue.of(type), new NumericValue(id));
|
||||
}
|
||||
}
|
||||
|
||||
private static final Map<Integer, ListValue> slotIdsToSlotParams = new HashMap<Integer, ListValue>() {{
|
||||
private static final Int2ObjectMap<SlotParam> slotIdsToSlotParams = new Int2ObjectOpenHashMap<>() {{
|
||||
int n;
|
||||
//covers blocks, player hotbar and inventory, and all default inventories
|
||||
for(n = 0; n < 54; ++n) {
|
||||
put(n, ListValue.of(Value.NULL, NumericValue.of(n)));
|
||||
put(n, new SlotParam(null, n));
|
||||
}
|
||||
for(n = 0; n < 27; ++n) {
|
||||
put(200+n, ListValue.of(StringValue.of("enderchest"), NumericValue.of(n)));
|
||||
put(200 + n, new SlotParam("enderchest", n));
|
||||
}
|
||||
|
||||
// villager
|
||||
for(n = 0; n < 8; ++n) {
|
||||
put(300+n, ListValue.of(Value.NULL, NumericValue.of(n)));
|
||||
put(300 + n, new SlotParam(null, n));
|
||||
}
|
||||
|
||||
// horse, llamas, donkeys, etc.
|
||||
// two first slots are for saddle and armour
|
||||
for(n = 0; n < 15; ++n) {
|
||||
put(500+n, ListValue.of(Value.NULL, NumericValue.of(n+2)));
|
||||
put(500 + n, new SlotParam(null, n + 2));
|
||||
}
|
||||
Value equipment = StringValue.of("equipment");
|
||||
// weapon main hand
|
||||
put(98, ListValue.of(equipment, NumericValue.of(0)));
|
||||
put(98, new SlotParam("equipment", 0));
|
||||
// offhand
|
||||
put(99, ListValue.of(equipment, NumericValue.of(5)));
|
||||
put(99, new SlotParam("equipment", 5));
|
||||
// feet, legs, chest, head
|
||||
for(n = 0; n < 4; ++n) {
|
||||
put(100+n, ListValue.of(equipment, NumericValue.of(n+1)));
|
||||
put(100 + n, new SlotParam("equipment", n + 1));
|
||||
}
|
||||
//horse defaults saddle
|
||||
put(400, ListValue.of(Value.NULL, NumericValue.of(0)));
|
||||
put(400, new SlotParam(null, 0));
|
||||
// armor
|
||||
put(401, ListValue.of(Value.NULL, NumericValue.of(1)));
|
||||
put(401, new SlotParam(null, 1));
|
||||
// chest itself on the donkey is wierd - use NBT to alter that.
|
||||
//hashMap.put("horse.chest", 499);
|
||||
}};
|
||||
|
||||
public static Value ofVanillaSlotResult(int itemSlot)
|
||||
{
|
||||
Value ret = slotIdsToSlotParams.get(itemSlot);
|
||||
if (ret == null) return ListValue.of(Value.NULL, NumericValue.of(itemSlot));
|
||||
return ret;
|
||||
SlotParam ret = slotIdsToSlotParams.get(itemSlot);
|
||||
if (ret == null) return ListValue.of(Value.NULL, new NumericValue(itemSlot));
|
||||
return ret.build();
|
||||
}
|
||||
|
||||
public static Value ofBlockPredicate(RegistryAccess registryAccess, Predicate<BlockInWorld> blockPredicate)
|
||||
|
||||
Reference in new issue
Block a user