This commit is contained in:
gnembon committed 2022-05-13 11:26:47 +02:00
1 parent 648ea01d15
commit 1a6b1df534
9 files changed
+34 -27

No files matched your search

+1 -1
View File
@@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/use
# or better: https://modmuss50.me/fabric.html
minecraft_version=22w18a
minecraft_version=22w19a
loader_version=0.13.3
fabric_version=0.49.4+1.19
@@ -13,7 +13,6 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.tags.Tag;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property;
@@ -1,7 +1,6 @@
package carpet.mixins;
import carpet.CarpetSettings;
import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.DiggerItem;
import net.minecraft.world.item.ItemStack;
@@ -1,7 +1,8 @@
package carpet.mixins;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MessageSignature;
import net.minecraft.network.chat.SignedMessage;
import net.minecraft.network.chat.PlayerChatMessage;
import net.minecraft.network.protocol.game.ServerboundChatPacket;
import net.minecraft.server.network.TextFilter;
import org.spongepowered.asm.mixin.Mixin;
@@ -286,10 +287,10 @@ public class ServerGamePacketListenerImpl_scarpetEventsMixin
}
@Inject(method = "handleChat(Lnet/minecraft/network/protocol/game/ServerboundChatPacket;Lnet/minecraft/server/network/TextFilter$FilteredText;)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastChatMessage(Lnet/minecraft/network/chat/SignedMessage;Lnet/minecraft/server/network/TextFilter$FilteredText;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/resources/ResourceKey;)V"),
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastChatMessage(Lnet/minecraft/network/chat/PlayerChatMessage;Lnet/minecraft/server/network/TextFilter$FilteredText;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/resources/ResourceKey;)V"),
locals = LocalCapture.CAPTURE_FAILHARD
)
private void onChatMessage(ServerboundChatPacket serverboundChatPacket, TextFilter.FilteredText filteredText, CallbackInfo ci, MessageSignature messageSignature, SignedMessage signedMessage) {
private void onChatMessage(ServerboundChatPacket serverboundChatPacket, TextFilter.FilteredText filteredText, CallbackInfo ci, Component component, MessageSignature messageSignature, PlayerChatMessage playerChatMessage) {
if (PLAYER_MESSAGE.isNeeded())
{
PLAYER_MESSAGE.onPlayerMessage(player, filteredText.getRaw());
@@ -12,7 +12,6 @@ import org.spongepowered.asm.mixin.Shadow;
import java.util.Map;
import java.util.stream.Collectors;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.tags.Tag;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
@@ -3,6 +3,7 @@ package carpet.mixins;
import carpet.helpers.ParticleDisplay;
import carpet.utils.Messenger;
import carpet.utils.MobAI;
import net.minecraft.world.entity.ai.village.poi.PoiTypes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@@ -141,9 +142,9 @@ public abstract class Villager_aiMixin extends AbstractVillager
else if (itemStack_1.getItem() instanceof BedItem)
{
List<PoiRecord> list_1 = ((ServerLevel) getCommandSenderWorld()).getPoiManager().getInRange(
type -> type == PoiType.HOME,
type -> type.is(PoiTypes.HOME),
blockPosition(),
48, PoiManager.Occupancy.ANY).collect(Collectors.toList());
48, PoiManager.Occupancy.ANY).toList();
for (PoiRecord poi : list_1)
{
Vec3 pv = Vec3.atCenterOf(poi.getPos());
@@ -153,7 +154,7 @@ public abstract class Villager_aiMixin extends AbstractVillager
pv.x, pv.y+1.5, pv.z,
50, 0.1, 0.3, 0.1, 0.0);
}
else if (canReachHome((Villager)(Object)this, poi.getPos()))
else if (canReachHome((Villager)(Object)this, poi.getPos(), poi))
((ServerLevel) getCommandSenderWorld()).sendParticles(ParticleTypes.END_ROD,
pv.x, pv.y+1, pv.z,
50, 0.1, 0.3, 0.1, 0.0);
@@ -168,9 +169,9 @@ public abstract class Villager_aiMixin extends AbstractVillager
}
}
// stolen from VillagerBreedTask
private boolean canReachHome(Villager villager, BlockPos pos) {
Path path = villager.getNavigation().createPath(pos, PoiType.HOME.getValidRange());
// stolen from VillagerMakeLove
private boolean canReachHome(Villager villager, BlockPos pos, PoiRecord poi) {
Path path = villager.getNavigation().createPath(pos, poi.getPoiType().value().validRange());
return path != null && path.canReach();
}
@@ -11,6 +11,7 @@ import carpet.fakes.ThreadedAnvilChunkStorageInterface;
import carpet.helpers.FeatureGenerator;
import carpet.mixins.PoiRecord_scarpetMixin;
import carpet.script.CarpetContext;
import carpet.script.CarpetScriptServer;
import carpet.script.Context;
import carpet.script.Expression;
import carpet.script.Fluff;
@@ -278,14 +279,15 @@ public class WorldAccess {
PoiManager store = cc.s.getLevel().getPoiManager();
if (lv.size() == locator.offset)
{
PoiType poiType = store.getType(pos).orElse(null);
if (poiType == null) return Value.NULL;
Optional<Holder<PoiType>> foo = store.getType(pos);
if (foo.isEmpty()) return Value.NULL;
PoiType poiType = foo.get().value();
// this feels wrong, but I don't want to mix-in more than I really need to.
// also distance adds 0.5 to each point which screws up accurate distance calculations
// you shoudn't be using POI with that in mind anyways, so I am not worried about it.
PoiRecord poi = store.getInRange(
poiType.getPredicate(),
type -> type.value() == poiType,
pos,
1,
PoiManager.Occupancy.ANY
@@ -293,13 +295,13 @@ public class WorldAccess {
if (poi == null)
return Value.NULL;
return ListValue.of(
new StringValue(poi.getPoiType().toString()),
new NumericValue(poiType.getMaxTickets() - ((PoiRecord_scarpetMixin)poi).getFreeTickets())
ValueConversions.of(Registry.POINT_OF_INTEREST_TYPE.getKey(poi.getPoiType().value())),
new NumericValue(poiType.maxTickets() - ((PoiRecord_scarpetMixin)poi).getFreeTickets())
);
}
int radius = NumericValue.asNumber(lv.get(locator.offset+0)).getInt();
if (radius < 0) return ListValue.of();
Predicate<PoiType> condition = PoiType.ALL;
Predicate<Holder<PoiType>> condition = p -> true;
PoiManager.Occupancy status = PoiManager.Occupancy.ANY;
boolean inColumn = false;
if (locator.offset + 1 < lv.size())
@@ -309,7 +311,7 @@ public class WorldAccess {
{
PoiType type = Registry.POINT_OF_INTEREST_TYPE.getOptional(InputValidator.identifierOf(poiType))
.orElseThrow(() -> new ThrowStatement(poiType, Throwables.UNKNOWN_POI));
condition = (tt) -> tt == type;
condition = (tt) -> tt.value() == type;
}
if (locator.offset + 2 < lv.size())
{
@@ -333,8 +335,8 @@ public class WorldAccess {
store.getInRange(condition, pos, radius, status);
return ListValue.wrap(pois.sorted(Comparator.comparingDouble(p -> p.getPos().distSqr(pos))).map(p ->
ListValue.of(
new StringValue(p.getPoiType().toString()),
new NumericValue(p.getPoiType().getMaxTickets() - ((PoiRecord_scarpetMixin)p).getFreeTickets()),
ValueConversions.of(Registry.POINT_OF_INTEREST_TYPE.getKey(p.getPoiType().value())),
new NumericValue(p.getPoiType().value().maxTickets() - ((PoiRecord_scarpetMixin)p).getFreeTickets()),
ListValue.of(new NumericValue(p.getPos().getX()), new NumericValue(p.getPos().getY()), new NumericValue(p.getPos().getZ()))
)
).collect(Collectors.toList()));
@@ -357,8 +359,11 @@ public class WorldAccess {
return Value.TRUE;
}
String poiTypeString = poi.getString().toLowerCase(Locale.ROOT);
PoiType type = Registry.POINT_OF_INTEREST_TYPE.getOptional(InputValidator.identifierOf(poiTypeString))
ResourceLocation resource = InputValidator.identifierOf(poiTypeString);
PoiType type = Registry.POINT_OF_INTEREST_TYPE.getOptional(resource)
.orElseThrow(() -> new ThrowStatement(poiTypeString, Throwables.UNKNOWN_POI));
Holder<PoiType> holder = Registry.POINT_OF_INTEREST_TYPE.getHolderOrThrow(ResourceKey.create(Registry.POINT_OF_INTEREST_TYPE_REGISTRY, resource));
int occupancy = 0;
if (locator.offset + 1 < lv.size())
{
@@ -366,13 +371,13 @@ public class WorldAccess {
if (occupancy < 0) throw new InternalExpressionException("Occupancy cannot be negative");
}
if (store.getType(pos).isPresent()) store.remove(pos);
store.add(pos, type);
store.add(pos, holder);
// setting occupancy for a
// again - don't want to mix in unnecessarily - peeps not gonna use it that often so not worries about it.
if (occupancy > 0)
{
int finalO = occupancy;
store.getInSquare((tt) -> tt==type, pos, 1, PoiManager.Occupancy.ANY
store.getInSquare((tt) -> tt.value()==type, pos, 1, PoiManager.Occupancy.ANY
).filter(p -> p.getPos().equals(pos)).findFirst().ifPresent(p -> {
for (int i=0; i < finalO; i++) ((PoiRecord_scarpetMixin)p).callAcquireTicket();
});
@@ -16,6 +16,7 @@ import carpet.script.value.StringValue;
import carpet.script.value.Value;
import carpet.script.value.ValueConversions;
import carpet.utils.CarpetProfiler;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import com.mojang.datafixers.util.Either;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
@@ -114,6 +115,9 @@ public abstract class CommandArgument
return new SimpleCommandExceptionType(Component.literal(text)).create();
}
private static final DynamicCommandExceptionType ERROR_BIOME_INVALID = new DynamicCommandExceptionType(v -> Component.translatable("commands.locate.biome.invalid", v));
private static final List<? extends CommandArgument> baseTypes = Lists.newArrayList(
// default
new StringArgument(),
@@ -219,7 +223,7 @@ public abstract class CommandArgument
),
new VanillaUnconfigurableArgument("biome", () -> ResourceOrTagLocationArgument.resourceOrTag(Registry.BIOME_REGISTRY),
(c, p) -> {
ResourceOrTagLocationArgument.Result<Biome> result = ResourceOrTagLocationArgument.getBiome(c, p);
ResourceOrTagLocationArgument.Result<Biome> result = ResourceOrTagLocationArgument.getRegistryType(c, "biome", Registry.BIOME_REGISTRY, ERROR_BIOME_INVALID);
Either<ResourceKey<Biome>, TagKey<Biome>> res = result.unwrap();
if (res.left().isPresent())
{
@@ -38,7 +38,6 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;