Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into patch-9
Browse files Browse the repository at this point in the history
  • Loading branch information
17183248569 committed Sep 26, 2024
2 parents 0d043c8 + 6144967 commit 6e686af
Show file tree
Hide file tree
Showing 22 changed files with 83 additions and 35 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check https://fabricmc.net/develop/
minecraft_version=24w38a
minecraft_version=24w39a
loader_version=0.16.5
jsr305_version=3.0.2
fabric_version=0.102.0+1.21

# Mod Properties
mod_version = 1.4.153
mod_version = 1.4.154
maven_group = carpet
archives_base_name = fabric-carpet

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/carpet/api/settings/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public void initializeScarpetRules() { //TODO try remove
/**
* Calling this method is not supported.
*/
public void inspectClientsideCommand(CommandSourceStack source, String string)
public void inspectClientsideCommand(String string)
{
if (string.startsWith("/" + identifier + " "))
{
Expand All @@ -316,9 +316,9 @@ public void inspectClientsideCommand(CommandSourceStack source, String string)
if (rules.containsKey(rule) && rules.get(rule).canBeToggledClientSide())
{
try {
rules.get(rule).set(source, strOption);
rules.get(rule).set(null, strOption);
} catch (InvalidRuleValueException e) {
e.notifySource(rule, source);
//e.notifySource(rule, source);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/carpet/commands/PlayerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ private static boolean cantSpawn(CommandContext<CommandSourceStack> context)
private static int kill(CommandContext<CommandSourceStack> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).kill();
ServerPlayer player = getPlayer(context);
player.kill(player.serverLevel());
return 1;
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/carpet/fakes/FoodDataInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package carpet.fakes;

public interface FoodDataInterface
{
float getCMExhaustionLevel();

void setExhaustion(float aFloat);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private void inspectMessage(String string, CallbackInfo ci)
if (CarpetServer.minecraft_server == null && !CarpetClient.isCarpet() && minecraft.player != null)
{
LocalPlayer playerSource = minecraft.player;
CarpetServer.forEachManager(sm -> sm.inspectClientsideCommand(playerSource.createCommandSourceStack(), "/" + string));
CarpetServer.forEachManager(sm -> sm.inspectClientsideCommand("/" + string));
}
}
}
24 changes: 24 additions & 0 deletions src/main/java/carpet/mixins/FoodData_scarpetMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package carpet.mixins;

import carpet.fakes.FoodDataInterface;
import net.minecraft.world.food.FoodData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(FoodData.class)
public class FoodData_scarpetMixin implements FoodDataInterface
{
@Shadow private float exhaustionLevel;

@Override
public float getCMExhaustionLevel()
{
return exhaustionLevel;
}

@Override
public void setExhaustion(float aFloat)
{
exhaustionLevel = aFloat;
}
}
3 changes: 2 additions & 1 deletion src/main/java/carpet/mixins/LivingEntity_cleanLogsMixin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package carpet.mixins;

import carpet.CarpetSettings;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
Expand All @@ -22,6 +23,6 @@ public LivingEntity_cleanLogsMixin(EntityType<?> type, Level world)
@Redirect(method = "die", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;hasCustomName()Z"))
private boolean shouldLogDeaths(LivingEntity livingEntity)
{
return livingEntity.hasCustomName() && CarpetSettings.cleanLogs && level().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
return livingEntity.hasCustomName() && CarpetSettings.cleanLogs && livingEntity.getServer().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private void tickPushingReplacement(CallbackInfo ci) {
int maxEntityCramming =-1;
if (CarpetSettings.maxEntityCollisions > 0)
{
maxEntityCramming = this.level().getGameRules().getInt(GameRules.RULE_MAX_ENTITY_CRAMMING);
maxEntityCramming = this.getServer().getGameRules().getInt(GameRules.RULE_MAX_ENTITY_CRAMMING);
entities = ((LevelInterface) this.level()).getOtherEntitiesLimited(
this,
this.getBoundingBox(),
Expand All @@ -50,7 +50,7 @@ private void tickPushingReplacement(CallbackInfo ci) {
}

if (!entities.isEmpty()) {
if (maxEntityCramming < 0) maxEntityCramming = this.level().getGameRules().getInt(GameRules.RULE_MAX_ENTITY_CRAMMING);
if (maxEntityCramming < 0) maxEntityCramming = this.getServer().getGameRules().getInt(GameRules.RULE_MAX_ENTITY_CRAMMING);
if (maxEntityCramming > 0 && entities.size() > maxEntityCramming - 1 && this.random.nextInt(4) == 0) {
int candidates = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import carpet.fakes.EntityInterface;
import carpet.fakes.LivingEntityInterface;
import carpet.script.EntityEventsGroup;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
Expand Down Expand Up @@ -42,7 +43,7 @@ private void onDeathCall(DamageSource damageSource_1, CallbackInfo ci)
target = "Lnet/minecraft/world/entity/LivingEntity;getDamageAfterArmorAbsorb(Lnet/minecraft/world/damagesource/DamageSource;F)F",
shift = At.Shift.BEFORE
))
private void entityTakingDamage(DamageSource source, float amount, CallbackInfo ci)
private void entityTakingDamage(ServerLevel serverLevel, DamageSource source, float amount, CallbackInfo ci)
{
((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.Event.ON_DAMAGE, amount, source);
// this is not applicable since its not a playr for sure
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/carpet/mixins/MinecraftMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class MinecraftMixin
{
@Shadow public ClientLevel level;

@Inject(method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At("HEAD"))
private void onCloseGame(Screen screen, CallbackInfo ci)
@Inject(method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;Z)V", at = @At("HEAD"))
private void onCloseGame(Screen screen, boolean b, CallbackInfo ci)
{
CarpetClient.disconnect();
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/carpet/mixins/Player_parrotMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import carpet.CarpetSettings;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
Expand Down Expand Up @@ -57,7 +58,7 @@ private void onTickMovement(CallbackInfo ci)
}
}

@Redirect(method = "hurt", at = @At(value = "INVOKE",
@Redirect(method = "hurtServer", at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/entity/player/Player;removeEntitiesOnShoulder()V"))
private void cancelDropShoulderEntities2(Player playerEntity)
{
Expand All @@ -76,9 +77,9 @@ protected void dismount_right()
this.setShoulderEntityRight(new CompoundTag());
}

@Inject(method = "hurt", at = @At(value = "INVOKE", shift = At.Shift.BEFORE,
@Inject(method = "hurtServer", at = @At(value = "INVOKE", shift = At.Shift.BEFORE,
target = "Lnet/minecraft/world/entity/player/Player;removeEntitiesOnShoulder()V"))
private void onDamage(DamageSource damageSource_1, float float_1, CallbackInfoReturnable<Boolean> cir)
private void onDamage(ServerLevel serverLevel, DamageSource damageSource_1, float float_1, CallbackInfoReturnable<Boolean> cir)
{
if (CarpetSettings.persistentParrots && !this.isShiftKeyDown())
{
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/carpet/mixins/Player_scarpetEventsMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import carpet.fakes.EntityInterface;
import carpet.script.EntityEventsGroup;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
Expand Down Expand Up @@ -36,7 +37,7 @@ protected Player_scarpetEventsMixin(EntityType<? extends LivingEntity> type, Lev
value = "INVOKE",
target = "Lnet/minecraft/world/entity/player/Player;getDamageAfterArmorAbsorb(Lnet/minecraft/world/damagesource/DamageSource;F)F"
))
private void playerTakingDamage(DamageSource source, float amount, CallbackInfo ci)
private void playerTakingDamage(ServerLevel serverLevel, DamageSource source, float amount, CallbackInfo ci)
{
// version of LivingEntity_scarpetEventsMixin::entityTakingDamage
((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.Event.ON_DAMAGE, amount, source);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/carpet/mixins/ServerLevel_scarpetMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
public abstract class ServerLevel_scarpetMixin extends Level implements ServerWorldInterface
{

@Shadow public abstract GameRules getGameRules();

protected ServerLevel_scarpetMixin(WritableLevelData writableLevelData, ResourceKey<Level> resourceKey, RegistryAccess registryAccess, Holder<DimensionType> holder, boolean bl, boolean bl2, long l, int i)
{
super(writableLevelData, resourceKey, registryAccess, holder, bl, bl2, l, i);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/carpet/mixins/WoolCarpetBlock_placeMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import carpet.utils.WoolTool;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.WoolCarpetBlock;
Expand All @@ -17,12 +18,13 @@ public WoolCarpetBlock_placeMixin(Properties block$Settings_1)
super(block$Settings_1);
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext context)
{
BlockState state = super.getStateForPlacement(context);
if (context.getPlayer() != null && !context.getLevel().isClientSide)
{ // getColor()
WoolTool.carpetPlacedAction(((WoolCarpetBlock)(Object)this).getColor(), context.getPlayer(), context.getClickedPos(), (ServerLevel) context.getLevel());
WoolTool.carpetPlacedAction(((WoolCarpetBlock)(Object)this).getColor(), (ServerPlayer) context.getPlayer(), context.getClickedPos(), (ServerLevel) context.getLevel());
}
return state;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/carpet/patches/EntityPlayerMPFake.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void onEquipItem(final EquipmentSlot slot, final ItemStack previous, fina
}

@Override
public void kill()
public void kill(ServerLevel level)
{
kill(Messenger.s("Killed"));
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/carpet/script/CarpetEventServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ public boolean onDamage(Entity target, float amount, DamageSource source)
new NumericValue(amount),
StringValue.of(source.getMsgId()),
source.getEntity() == null ? Value.NULL : new EntityValue(source.getEntity())
), target::createCommandSourceStack);
), () -> target.getServer().createCommandSourceStack());
}
};
public static final Event PLAYER_DEALS_DAMAGE = new Event("player_deals_damage", 3, false)
Expand All @@ -894,7 +894,7 @@ public boolean onDamage(Entity target, float amount, DamageSource source)
{
return handler.call(() ->
Arrays.asList(new EntityValue(source.getEntity()), new NumericValue(amount), new EntityValue(target)),
() -> source.getEntity().createCommandSourceStack()
() -> source.getEntity().getServer().createCommandSourceStack()
);
}
};
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/carpet/script/EntityEventsGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
import java.util.List;
import java.util.Map;

import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec3;

public class EntityEventsGroup
Expand Down Expand Up @@ -167,7 +170,7 @@ public CarpetEventServer.Callback create(EventKey key, FunctionValue function, L
public CarpetEventServer.CallbackResult call(CarpetEventServer.Callback tickCall, Entity entity, Object... args)
{
assert args.length == argcount - 1;
return tickCall.execute(entity.createCommandSourceStack(), makeArgs(entity, args));
return tickCall.execute((entity instanceof ServerPlayer player ? player.createCommandSourceStack() : entity.getServer().createCommandSourceStack()), makeArgs(entity, args));
}

protected List<Value> makeArgs(Entity entity, Object... args)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/carpet/script/utils/SnoopyCommandSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public SnoopyCommandSource(CommandSourceStack original, Component[] error, List<

public SnoopyCommandSource(ServerPlayer player, Component[] error, List<Component> output)
{
super(player, player.position(), player.getRotationVector(),
super(player.commandSource(), player.position(), player.getRotationVector(),
player.level() instanceof final ServerLevel serverLevel ? serverLevel : null,
player.server.getProfilePermissions(player.getGameProfile()), player.getName().getString(), player.getDisplayName(),
player.level().getServer(), player);
this.output = player;
this.output = player.commandSource();
this.position = player.position();
this.world = player.level() instanceof final ServerLevel serverLevel ? serverLevel : null;
this.level = player.server.getProfilePermissions(player.getGameProfile());
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/carpet/script/value/EntityValue.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package carpet.script.value;

import carpet.fakes.FoodDataInterface;
import carpet.script.external.Vanilla;
import carpet.script.utils.Tracer;
import carpet.script.CarpetContext;
Expand Down Expand Up @@ -302,11 +303,11 @@ public Value listValue(RegistryAccess regs)
EntityType.TRIDENT, EntityType.WITHER_SKULL, EntityType.FISHING_BOBBER, EntityType.SHULKER_BULLET
);
Set<EntityType<?>> deads = Set.of(
EntityType.AREA_EFFECT_CLOUD, EntityType.MARKER, EntityType.BOAT, EntityType.END_CRYSTAL,
EntityType.AREA_EFFECT_CLOUD, EntityType.MARKER, 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,
EntityType.LEASH_KNOT, EntityType.LIGHTNING_BOLT, EntityType.PAINTING,
EntityType.TNT, EntityType.ARMOR_STAND, EntityType.CHEST_BOAT
EntityType.TNT, EntityType.ARMOR_STAND

);
Set<EntityType<?>> minecarts = Set.of(
Expand Down Expand Up @@ -336,7 +337,7 @@ public Value listValue(RegistryAccess regs)
);

Set<EntityType<?>> living = allTypes.stream().filter(et ->
!deads.contains(et) && !projectiles.contains(et) && !minecarts.contains(et)
!deads.contains(et) && !projectiles.contains(et) && !minecarts.contains(et) && !et.is(EntityTypeTags.BOAT)
).collect(Collectors.toSet());

Set<EntityType<?>> regular = allTypes.stream().filter(et ->
Expand Down Expand Up @@ -550,7 +551,7 @@ public Value get(String what, @Nullable Value arg)
put("persistence", (e, a) -> e instanceof Mob mob ? BooleanValue.of(mob.isPersistenceRequired()) : Value.NULL);
put("hunger", (e, a) -> e instanceof Player player ? new NumericValue(player.getFoodData().getFoodLevel()) : Value.NULL);
put("saturation", (e, a) -> e instanceof Player player ? new NumericValue(player.getFoodData().getSaturationLevel()) : Value.NULL);
put("exhaustion", (e, a) -> e instanceof Player player ? new NumericValue(player.getFoodData().getExhaustionLevel()) : Value.NULL);
put("exhaustion", (e, a) -> e instanceof Player player ? new NumericValue(((FoodDataInterface)player.getFoodData()).getCMExhaustionLevel()) : Value.NULL);
put("absorption", (e, a) -> e instanceof Player player ? new NumericValue(player.getAbsorptionAmount()) : Value.NULL);
put("xp", (e, a) -> e instanceof Player player ? new NumericValue(player.totalExperience) : Value.NULL);
put("xp_level", (e, a) -> e instanceof Player player ? new NumericValue(player.experienceLevel) : Value.NULL);
Expand Down Expand Up @@ -1040,7 +1041,7 @@ private static void updateVelocity(Entity e, double scale)
}
});*/
put("kill", (e, v) -> e.kill());
put("kill", (e, v) -> e.kill((ServerLevel) e.level()));
put("location", (e, v) ->
{
if (!(v instanceof ListValue lv))
Expand Down Expand Up @@ -1605,7 +1606,7 @@ else if (v instanceof ListValue lv)
put("exhaustion", (e, v) -> {
if (e instanceof Player p)
{
p.getFoodData().setExhaustion(NumericValue.asNumber(v).getFloat());
((FoodDataInterface)p.getFoodData()).setExhaustion(NumericValue.asNumber(v).getFloat());
}
});

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/carpet/utils/Messenger.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextColor;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec3;
Expand Down Expand Up @@ -243,7 +244,7 @@ public static void m(CommandSourceStack source, Object ... fields)
}
public static void m(Player player, Object ... fields)
{
player.sendSystemMessage(Messenger.c(fields));
((ServerPlayer)player).sendSystemMessage(Messenger.c(fields));
}

/*
Expand Down Expand Up @@ -287,7 +288,7 @@ public static Component s(String text, String style)

public static void send(Player player, Collection<Component> lines)
{
lines.forEach(message -> player.sendSystemMessage(message));
lines.forEach(message -> ((ServerPlayer)player).sendSystemMessage(message));
}
public static void send(CommandSourceStack source, Collection<Component> lines)
{
Expand All @@ -301,7 +302,7 @@ public static void print_server_message(MinecraftServer server, String message)
LOG.error("Message not delivered: "+message);
server.sendSystemMessage(Component.literal(message));
Component txt = c("gi "+message);
for (Player entityplayer : server.getPlayerList().getPlayers())
for (ServerPlayer entityplayer : server.getPlayerList().getPlayers())
{
entityplayer.sendSystemMessage(txt);
}
Expand All @@ -311,7 +312,7 @@ public static void print_server_message(MinecraftServer server, Component messag
if (server == null)
LOG.error("Message not delivered: "+message.getString());
server.sendSystemMessage(message);
for (Player entityplayer : server.getPlayerList().getPlayers())
for (ServerPlayer entityplayer : server.getPlayerList().getPlayers())
{
entityplayer.sendSystemMessage(message);
}
Expand Down
Loading

0 comments on commit 6e686af

Please sign in to comment.