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
+107
-130
No files matched your search
@@ -28,13 +28,13 @@ public class CounterCommand
|
||||
CarpetSettings.hopperCounters);
|
||||
|
||||
literalargumentbuilder.
|
||||
then((Commands.literal("reset").executes( (p_198489_1_)->
|
||||
resetCounter(p_198489_1_.getSource(), null))));
|
||||
then((Commands.literal("reset").executes( (context)->
|
||||
resetCounter(context.getSource(), null))));
|
||||
for (DyeColor enumDyeColor: DyeColor.values())
|
||||
{
|
||||
String color = enumDyeColor.toString();
|
||||
literalargumentbuilder.
|
||||
then((Commands.literal(color).executes( (p_198489_1_)-> displayCounter(p_198489_1_.getSource(), color, false))));
|
||||
then((Commands.literal(color).executes( (context)-> displayCounter(context.getSource(), color, false))));
|
||||
literalargumentbuilder.then(Commands.literal(color).
|
||||
then(Commands.literal("reset").executes((context) ->
|
||||
resetCounter(context.getSource(), color))));
|
||||
|
||||
@@ -35,7 +35,7 @@ public class MobAICommand
|
||||
executes( (c) -> {
|
||||
MobAI.startTracking(
|
||||
Registry.ENTITY_TYPE.get(EntitySummonArgument.getSummonableEntity(c, "entity type")),
|
||||
MobAI.TrackingType.byName(StringArgumentType.getString(c, "aspect"))
|
||||
MobAI.TrackingType.valueOf(StringArgumentType.getString(c, "aspect").toUpperCase())
|
||||
);
|
||||
return 1;
|
||||
})));
|
||||
|
||||
@@ -6,7 +6,6 @@ import carpet.fakes.ServerPlayerEntityInterface;
|
||||
import carpet.patches.EntityPlayerMPFake;
|
||||
import carpet.settings.SettingsManager;
|
||||
import carpet.utils.Messenger;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
@@ -35,9 +34,10 @@ import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.minecraft.commands.Commands.argument;
|
||||
import static net.minecraft.commands.Commands.literal;
|
||||
@@ -51,8 +51,7 @@ public class PlayerCommand
|
||||
{
|
||||
final String[] gamemodeStrings = Arrays.stream(GameType.values())
|
||||
.map(GameType::getName)
|
||||
.collect(Collectors.toList())
|
||||
.toArray(new String[]{});
|
||||
.toArray(String[]::new);
|
||||
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = literal("player")
|
||||
.requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandPlayer))
|
||||
.then(argument("player", StringArgumentType.word())
|
||||
@@ -143,7 +142,7 @@ public class PlayerCommand
|
||||
|
||||
private static Collection<String> getPlayers(CommandSourceStack source)
|
||||
{
|
||||
Set<String> players = Sets.newLinkedHashSet(Arrays.asList("Steve", "Alex"));
|
||||
Set<String> players = new LinkedHashSet<>(List.of("Steve", "Alex"));
|
||||
players.addAll(source.getOnlinePlayerNames());
|
||||
return players;
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ public class FeatureGenerator
|
||||
private static Thing simpleTree(TreeConfiguration config)
|
||||
{
|
||||
//config.ignoreFluidCheck();
|
||||
return simplePlop(new ConfiguredFeature(Feature.TREE, config));
|
||||
return simplePlop(new ConfiguredFeature<>(Feature.TREE, config));
|
||||
}
|
||||
|
||||
private static Thing spawnCustomStructure(Structure structure)
|
||||
|
||||
@@ -28,13 +28,13 @@ public abstract class DistanceManager_spawnChunksMixin implements ChunkTicketMan
|
||||
{
|
||||
long pos = chunkPos.toLong();
|
||||
SortedArraySet<Ticket<?>> set = tickets.get(pos);
|
||||
Ticket existingTicket = null;
|
||||
Ticket<?> existingTicket = null;
|
||||
if (set != null)
|
||||
{
|
||||
Iterator<Ticket<?>> iter = set.iterator();
|
||||
while(iter.hasNext())
|
||||
{
|
||||
Ticket ticket = iter.next();
|
||||
Ticket<?> ticket = iter.next();
|
||||
if (ticket.getType() == TicketType.START)
|
||||
{
|
||||
existingTicket = ticket;
|
||||
|
||||
@@ -14,7 +14,7 @@ import net.minecraft.world.level.entity.EntitySectionStorage;
|
||||
import net.minecraft.world.level.entity.LevelEntityGetterAdapter;
|
||||
|
||||
@Mixin(LevelEntityGetterAdapter.class)
|
||||
public class LevelEntityGetterAdapter_scarpetMixin<T extends EntityAccess> implements SimpleEntityLookupInterface
|
||||
public class LevelEntityGetterAdapter_scarpetMixin<T extends EntityAccess> implements SimpleEntityLookupInterface<T>
|
||||
{
|
||||
|
||||
@Shadow @Final private EntitySectionStorage<T> sectionStorage;
|
||||
|
||||
@@ -94,7 +94,7 @@ public abstract class Villager_aiMixin extends AbstractVillager
|
||||
(recentlySeen?"rb ":"lb ")+time ));
|
||||
this.setCustomNameVisible(true);
|
||||
}
|
||||
else if (MobAI.isTracking(this, MobAI.TrackingType.VILLAGER_BREEDING))
|
||||
else if (MobAI.isTracking(this, MobAI.TrackingType.BREEDING))
|
||||
{
|
||||
if (tickCount % 50 == 0 || tickCount < 20)
|
||||
{
|
||||
@@ -117,7 +117,7 @@ public abstract class Villager_aiMixin extends AbstractVillager
|
||||
@Inject(method = "mobInteract", at = @At("HEAD"), cancellable = true)
|
||||
private void onInteract(Player playerEntity_1, InteractionHand hand_1, CallbackInfoReturnable<InteractionResult> cir)
|
||||
{
|
||||
if (MobAI.isTracking(this, MobAI.TrackingType.VILLAGER_BREEDING))
|
||||
if (MobAI.isTracking(this, MobAI.TrackingType.BREEDING))
|
||||
{
|
||||
ItemStack itemStack_1 = playerEntity_1.getItemInHand(hand_1);
|
||||
if (itemStack_1.getItem() == Items.EMERALD)
|
||||
|
||||
@@ -25,14 +25,14 @@ import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class ServerNetworkHandler
|
||||
{
|
||||
private static Map<ServerPlayer, String> remoteCarpetPlayers = new HashMap<>();
|
||||
private static Set<ServerPlayer> validCarpetPlayers = new HashSet<>();
|
||||
private static final Map<ServerPlayer, String> remoteCarpetPlayers = new HashMap<>();
|
||||
private static final Set<ServerPlayer> validCarpetPlayers = new HashSet<>();
|
||||
|
||||
private static Map<String, BiConsumer<ServerPlayer, Tag>> dataHandlers = new HashMap<String, BiConsumer<ServerPlayer, Tag>>(){{
|
||||
put("clientCommand", (p, t) -> {
|
||||
private static final Map<String, BiConsumer<ServerPlayer, Tag>> dataHandlers = Map.of(
|
||||
"clientCommand", (p, t) -> {
|
||||
handleClientCommand(p, (CompoundTag)t);
|
||||
});
|
||||
}};
|
||||
}
|
||||
);
|
||||
|
||||
public static void handleData(FriendlyByteBuf data, ServerPlayer player)
|
||||
{
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -983,11 +982,9 @@ public class CarpetEventServer
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static final Map<EntityType<? extends Entity>, Event> ENTITY_LOAD= new HashMap<>()
|
||||
{{
|
||||
EntityType.byString("zombie");
|
||||
Registry.ENTITY_TYPE.forEach(et -> {
|
||||
put(et, new Event(getEntityLoadEventName(et), 1, true, false)
|
||||
public static final Map<EntityType<? extends Entity>, Event> ENTITY_LOAD = Registry.ENTITY_TYPE
|
||||
.stream()
|
||||
.map(et -> Map.entry(et, new Event(getEntityLoadEventName(et), 1, true, false)
|
||||
{
|
||||
@Override
|
||||
public void onEntityAction(Entity entity, boolean created)
|
||||
@@ -997,32 +994,25 @@ public class CarpetEventServer
|
||||
() -> CarpetServer.minecraft_server.createCommandSourceStack().withLevel((ServerLevel) entity.level).withPermission(CarpetSettings.runPermissionLevel)
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}};
|
||||
})).collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
|
||||
public static String getEntityHandlerEventName(EntityType<? extends Entity> et)
|
||||
{
|
||||
return "entity_handler_" + ValueConversions.of(Registry.ENTITY_TYPE.getKey(et)).getString();
|
||||
}
|
||||
|
||||
public static final Map<EntityType<? extends Entity>, Event> ENTITY_HANDLER= new HashMap<>()
|
||||
{{
|
||||
EntityType.byString("zombie");
|
||||
Registry.ENTITY_TYPE.forEach(et -> {
|
||||
put(et, new Event(getEntityHandlerEventName(et), 2, true, false)
|
||||
{
|
||||
public static final Map<EntityType<? extends Entity>, Event> ENTITY_HANDLER = Registry.ENTITY_TYPE
|
||||
.stream()
|
||||
.map(et -> Map.entry(et, new Event(getEntityHandlerEventName(et), 2, true, false) {
|
||||
@Override
|
||||
public void onEntityAction(Entity entity, boolean created)
|
||||
{
|
||||
public void onEntityAction(Entity entity, boolean created) {
|
||||
handler.call(
|
||||
() -> Arrays.asList(new EntityValue(entity), BooleanValue.of(created)),
|
||||
() -> CarpetServer.minecraft_server.createCommandSourceStack().withLevel((ServerLevel) entity.level).withPermission(CarpetSettings.runPermissionLevel)
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}};
|
||||
}))
|
||||
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
|
||||
// on projectile thrown (arrow from bows, crossbows, tridents, snoballs, e-pearls
|
||||
|
||||
|
||||
@@ -21,12 +21,12 @@ import carpet.script.value.ScreenValue;
|
||||
import carpet.script.value.StringValue;
|
||||
import carpet.script.value.Value;
|
||||
import carpet.script.value.ValueConversions;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.commands.arguments.item.ItemInput;
|
||||
import net.minecraft.core.HolderSet;
|
||||
@@ -336,7 +336,7 @@ public class Inventories {
|
||||
if (lv.size() > inventoryLocator.offset()+1)
|
||||
amount = (int)NumericValue.asNumber(lv.get(inventoryLocator.offset()+1)).getLong();
|
||||
// not enough
|
||||
if (((amount == 1) && (!inventoryLocator.inventory().hasAnyOf(Sets.newHashSet(searchItem.getItem()))))
|
||||
if (((amount == 1) && (!inventoryLocator.inventory().hasAnyOf(Set.of(searchItem.getItem()))))
|
||||
|| (inventoryLocator.inventory().countItem(searchItem.getItem()) < amount)) return Value.FALSE;
|
||||
for (int i = 0, maxi = inventoryLocator.inventory().getContainerSize(); i < maxi; i++)
|
||||
{
|
||||
|
||||
@@ -134,11 +134,11 @@ public class WorldAccess {
|
||||
DIRECTION_MAP.put("x", Direction.EAST);
|
||||
|
||||
}
|
||||
private final static Map<String, TicketType<?>> ticketTypes = new HashMap<String, TicketType<?>>(){{
|
||||
put("portal", TicketType.PORTAL);
|
||||
put("teleport", TicketType.POST_TELEPORT);
|
||||
put("unknown", TicketType.UNKNOWN); // unknown
|
||||
}};
|
||||
private static final Map<String, TicketType<?>> ticketTypes = Map.of(
|
||||
"portal", TicketType.PORTAL,
|
||||
"teleport", TicketType.POST_TELEPORT,
|
||||
"unknown", TicketType.UNKNOWN
|
||||
);
|
||||
// dummy entity for dummy requirements in the loot tables (see snowball)
|
||||
private static FallingBlockEntity DUMMY_ENTITY = null;
|
||||
private static Value booleanStateTest(
|
||||
|
||||
@@ -515,7 +515,7 @@ public class FileArgument
|
||||
{
|
||||
try (BufferedReader reader = Files.newBufferedReader(filePath, StandardCharsets.UTF_8))
|
||||
{
|
||||
return new JsonParser().parse(new JsonReader(reader));
|
||||
return JsonParser.parseReader(reader);
|
||||
}
|
||||
catch (JsonParseException e)
|
||||
{
|
||||
|
||||
@@ -3,10 +3,10 @@ package carpet.script.language;
|
||||
import carpet.script.Context;
|
||||
import carpet.script.Expression;
|
||||
import carpet.script.LazyValue;
|
||||
import carpet.script.api.Auxiliary;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.exception.ThrowStatement;
|
||||
import carpet.script.exception.Throwables;
|
||||
import carpet.script.utils.ScarpetJsonDeserializer;
|
||||
import carpet.script.value.BooleanValue;
|
||||
import carpet.script.value.ContainerValueInterface;
|
||||
import carpet.script.value.LContainerValue;
|
||||
@@ -341,7 +341,7 @@ public class DataStructures {
|
||||
expression.addUnaryFunction("encode_json", v -> StringValue.of(v.toJson().toString()));
|
||||
expression.addUnaryFunction("decode_json", v -> {
|
||||
try {
|
||||
return new ScarpetJsonDeserializer().deserialize(new JsonParser().parse(v.getString()), null, null);
|
||||
return Auxiliary.GSON.fromJson(v.getString(), Value.class);
|
||||
} catch (JsonParseException jpe){
|
||||
throw new ThrowStatement("Invalid json string: " + v.getString(), Throwables.JSON_ERROR);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -68,31 +68,20 @@ public class MobAI
|
||||
{
|
||||
Set<TrackingType> availableOptions = new HashSet<>();
|
||||
for (TrackingType type: TrackingType.values())
|
||||
for (EntityType<?> etype: type.types)
|
||||
if (etype == entityType)
|
||||
if (type.types.contains(entityType))
|
||||
availableOptions.add(type);
|
||||
return availableOptions.stream().map(t -> t.name).collect(Collectors.toList());
|
||||
return availableOptions.stream().map(t -> t.name().toLowerCase()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public enum TrackingType
|
||||
{
|
||||
IRON_GOLEM_SPAWNING("iron_golem_spawning", Sets.newHashSet(EntityType.VILLAGER)),
|
||||
VILLAGER_BREEDING("breeding", Sets.newHashSet(EntityType.VILLAGER));
|
||||
IRON_GOLEM_SPAWNING(Set.of(EntityType.VILLAGER)),
|
||||
BREEDING(Set.of(EntityType.VILLAGER));
|
||||
public final Set<EntityType<?>> types;
|
||||
public final String name;
|
||||
TrackingType(String name, Set<EntityType<?>> applicableTypes)
|
||||
TrackingType(Set<EntityType<?>> applicableTypes)
|
||||
{
|
||||
this.name = name;
|
||||
types = applicableTypes;
|
||||
}
|
||||
|
||||
public static TrackingType byName(String aspect)
|
||||
{
|
||||
for (TrackingType type: values())
|
||||
if (type.name.equalsIgnoreCase(aspect))
|
||||
return type;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,8 +3,12 @@ package carpet.utils;
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.helpers.HopperCounter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -17,6 +21,8 @@ import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.level.material.MaterialColor;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import static java.util.Map.entry;
|
||||
|
||||
/**
|
||||
* A series of utility functions and variables for dealing predominantly with hopper counters and determining which counter
|
||||
* to add their items to, as well as helping dealing with carpet functionality.
|
||||
@@ -27,38 +33,32 @@ 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<MaterialColor,DyeColor> Material2Dye = new HashMap<>();
|
||||
private static final Map<MaterialColor,DyeColor> Material2Dye = Arrays.stream(DyeColor.values())
|
||||
.collect(Collectors.toUnmodifiableMap(DyeColor::getMaterialColor, Function.identity()));
|
||||
|
||||
/**
|
||||
* 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<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.getMaterialColor(),color);
|
||||
}
|
||||
}
|
||||
public static final Map<MaterialColor,String> Material2DyeName = Map.ofEntries(
|
||||
entry(MaterialColor.SNOW, "w "),
|
||||
entry(MaterialColor.COLOR_ORANGE, "#F9801D "),
|
||||
entry(MaterialColor.COLOR_MAGENTA, "m "),
|
||||
entry(MaterialColor.COLOR_LIGHT_BLUE, "t "),
|
||||
entry(MaterialColor.COLOR_YELLOW, "y "),
|
||||
entry(MaterialColor.COLOR_LIGHT_GREEN, "l "),
|
||||
entry(MaterialColor.COLOR_PINK, "#FFACCB "),
|
||||
entry(MaterialColor.COLOR_GRAY, "f "),
|
||||
entry(MaterialColor.COLOR_LIGHT_GRAY, "g "),
|
||||
entry(MaterialColor.COLOR_CYAN, "c "),
|
||||
entry(MaterialColor.COLOR_PURPLE, "p "),
|
||||
entry(MaterialColor.COLOR_BLUE, "v "),
|
||||
entry(MaterialColor.COLOR_BROWN, "#835432 "),
|
||||
entry(MaterialColor.COLOR_GREEN, "e "),
|
||||
entry(MaterialColor.COLOR_RED, "r "),
|
||||
entry(MaterialColor.COLOR_BLACK, "k ")
|
||||
);
|
||||
|
||||
/**
|
||||
* The method which gets triggered when a player places a carpet, and decides what to do based on the carpet's colour:
|
||||
|
||||
Reference in new issue
Block a user