Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: FabricMC/fabric
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.93.1+1.20.5
Choose a base ref
...
head repository: FabricMC/fabric
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.94.0+1.20.5
Choose a head ref
  • 5 commits
  • 28 files changed
  • 3 contributors

Commits on Jan 15, 2024

  1. Update to loom 1.5 (#3515)

    * Update to loom 1.5
    
    * Continue to use the mixin AP for now.
    
    * Bump
    modmuss50 authored Jan 15, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    05ec3fa View commit details
  2. Add mob conversion event (#3511)

    * Add mob conversion event
    
    * spacing
    
    * use a smarter mixin strategy
    
    * add pig and villager lightning triggers
    
    * tyop
    
    Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com>
    
    * handle tadpole -> frog conversion
    
    - update javadoc to clarify the handled cases
    - document keepEquipment parameter
    - improve mixin handler names
    
    ---------
    
    Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com>
    (cherry picked from commit 44c0f8c)
    Syst3ms authored and modmuss50 committed Jan 15, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    92bc82c View commit details
  3. Stack aware getFoodComponent (#3520)

    * Stack aware `getFoodComponent`
    
    Co-authored-by: Phoupraw <50520903+phoupraw@users.noreply.github.com>
    
    * Back to redirects
    
    ---------
    
    Co-authored-by: Phoupraw <50520903+phoupraw@users.noreply.github.com>
    (cherry picked from commit d6f2b08)
    modmuss50 committed Jan 15, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    fd15459 View commit details
  4. Don't tick gametests if the server isn't ticking (#3528)

    * Don't tick gametests if the server isn't ticking
    
    * Fix import order
    
    (cherry picked from commit 85d85a9)
    jaredlll08 authored and modmuss50 committed Jan 15, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    ab3cc93 View commit details
  5. Bump version

    modmuss50 committed Jan 15, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c10e41a View commit details
Showing with 788 additions and 60 deletions.
  1. +4 −1 build.gradle
  2. +28 −0 ...ity-events-v1/src/main/java/net/fabricmc/fabric/api/entity/event/v1/ServerLivingEntityEvents.java
  3. +36 −0 fabric-entity-events-v1/src/main/java/net/fabricmc/fabric/mixin/entity/event/MobEntityMixin.java
  4. +46 −0 fabric-entity-events-v1/src/main/java/net/fabricmc/fabric/mixin/entity/event/PigEntityMixin.java
  5. +46 −0 fabric-entity-events-v1/src/main/java/net/fabricmc/fabric/mixin/entity/event/TadpoleEntityMixin.java
  6. +46 −0 ...ic-entity-events-v1/src/main/java/net/fabricmc/fabric/mixin/entity/event/VillagerEntityMixin.java
  7. +7 −3 fabric-entity-events-v1/src/main/resources/fabric-entity-events-v1.mixins.json
  8. +4 −0 fabric-entity-events-v1/src/testmod/java/net/fabricmc/fabric/test/entity/event/EntityEventTests.java
  9. +8 −1 fabric-gametest-api-v1/src/main/java/net/fabricmc/fabric/mixin/gametest/MinecraftServerMixin.java
  10. +13 −0 fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/FabricItem.java
  11. +13 −0 fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/FabricItemStack.java
  12. +32 −0 fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/BlockItemMixin.java
  13. +41 −0 fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/CatEntityMixin.java
  14. +32 −0 fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/CookingRecipeJsonBuilderMixin.java
  15. +46 −0 fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/FoxEntityMixin.java
  16. +40 −0 fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/HungerManagerMixin.java
  17. +32 −0 fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/ItemMixin.java
  18. +6 −0 fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/ItemStackMixin.java
  19. +24 −0 fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/LivingEntityMixin.java
  20. +57 −0 fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/WolfEntityMixin.java
  21. +7 −1 fabric-item-api-v1/src/main/resources/fabric-item-api-v1.mixins.json
  22. +63 −0 fabric-item-api-v1/src/testmod/java/net/fabricmc/fabric/test/item/FoodGameInitializer.java
  23. +95 −0 fabric-item-api-v1/src/testmod/java/net/fabricmc/fabric/test/item/gametest/FoodGameTest.java
  24. +3 −0 ...-item-api-v1/src/testmod/resources/assets/fabric-item-api-v1-testmod/models/item/damage_food.json
  25. +3 −0 ...ic-item-api-v1/src/testmod/resources/assets/fabric-item-api-v1-testmod/models/item/name_food.json
  26. +4 −2 fabric-item-api-v1/src/testmod/resources/fabric.mod.json
  27. +51 −51 gradle.properties
  28. +1 −1 gradle/module-versioning.gradle
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ plugins {
id "idea"
id "maven-publish"
id 'jacoco'
id "fabric-loom" version "1.4.4" apply false
id "fabric-loom" version "1.5.4" apply false
id "com.diffplug.spotless" version "6.20.0"
id "org.ajoberstar.grgit" version "3.1.0"
id "me.modmuss50.remotesign" version "0.4.0" apply false
@@ -157,6 +157,9 @@ allprojects {

loom {
splitEnvironmentSourceSets()
mixin {
useLegacyMixinAp = true
}
}

sourceSets {
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.MobEntity;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
@@ -73,6 +74,21 @@ public final class ServerLivingEntityEvents {
}
});

/**
* An event that is called when a mob has been converted to another type.
*
* <p>When this event is called, the old instance has not yet been discarded, and the new one has not yet been spawned.
* Mods may use this event to copy some of the old entity's data to the converted one.</p>
*
* <p>This event only handles cases where the entity type changes, requiring a new instance. Notably it does not
* cover mooshrooms changing color from lightning, creepers getting charged, or wolves being tamed.</p>
*/
public static final Event<MobConversion> MOB_CONVERSION = EventFactory.createArrayBacked(MobConversion.class, callbacks -> (previous, converted, keepEquipment) -> {
for (MobConversion callback : callbacks) {
callback.onConversion(previous, converted, keepEquipment);
}
});

@FunctionalInterface
public interface AllowDamage {
/**
@@ -112,6 +128,18 @@ public interface AfterDeath {
void afterDeath(LivingEntity entity, DamageSource damageSource);
}

@FunctionalInterface
public interface MobConversion {
/**
* Called when a mob is converted to another type.
*
* @param previous the previous entity instance
* @param converted the new instance for the converted entity
* @param keepEquipment whether the converted entity should keep the previous one's equipment, like armor
*/
void onConversion(MobEntity previous, MobEntity converted, boolean keepEquipment);
}

private ServerLivingEntityEvents() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.mixin.entity.event;

import com.llamalad7.mixinextras.sugar.Local;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.MobEntity;

import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;

@Mixin(MobEntity.class)
public class MobEntityMixin {
@ModifyArg(method = "convertTo", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;spawnEntity(Lnet/minecraft/entity/Entity;)Z"))
private Entity afterEntityConverted(Entity converted, @Local(argsOnly = true) boolean keepEquipment) {
ServerLivingEntityEvents.MOB_CONVERSION.invoker().onConversion((MobEntity) (Object) this, (MobEntity) converted, keepEquipment);
return converted;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.mixin.entity.event;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.entity.passive.PigEntity;
import net.minecraft.world.World;

import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;

@Mixin(PigEntity.class)
abstract class PigEntityMixin extends AnimalEntity {
protected PigEntityMixin(EntityType<? extends AnimalEntity> entityType, World world) {
super(entityType, world);
}

@ModifyArg(
method = "onStruckByLightning",
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;spawnEntity(Lnet/minecraft/entity/Entity;)Z")
)
private Entity afterPiglinConversion(Entity converted) {
ServerLivingEntityEvents.MOB_CONVERSION.invoker().onConversion(this, (MobEntity) converted, false);
return converted;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.mixin.entity.event;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.passive.FishEntity;
import net.minecraft.entity.passive.TadpoleEntity;
import net.minecraft.world.World;

import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;

@Mixin(TadpoleEntity.class)
abstract class TadpoleEntityMixin extends FishEntity {
TadpoleEntityMixin(EntityType<? extends FishEntity> entityType, World world) {
super(entityType, world);
}

@ModifyArg(
method = "growUp",
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;spawnEntityAndPassengers(Lnet/minecraft/entity/Entity;)V")
)
private Entity afterGrowingUpToFrog(Entity converted) {
ServerLivingEntityEvents.MOB_CONVERSION.invoker().onConversion(this, (MobEntity) converted, false);
return converted;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.mixin.entity.event;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.passive.MerchantEntity;
import net.minecraft.entity.passive.VillagerEntity;
import net.minecraft.world.World;

import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;

@Mixin(VillagerEntity.class)
abstract class VillagerEntityMixin extends MerchantEntity {
VillagerEntityMixin(EntityType<? extends MerchantEntity> entityType, World world) {
super(entityType, world);
}

@ModifyArg(
method = "onStruckByLightning",
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;spawnEntityAndPassengers(Lnet/minecraft/entity/Entity;)V")
)
private Entity afterWitchConversion(Entity converted) {
ServerLivingEntityEvents.MOB_CONVERSION.invoker().onConversion(this, (MobEntity) converted, false);
return converted;
}
}
Original file line number Diff line number Diff line change
@@ -3,13 +3,17 @@
"package": "net.fabricmc.fabric.mixin.entity.event",
"compatibilityLevel": "JAVA_17",
"mixins": [
"elytra.LivingEntityMixin",
"elytra.PlayerEntityMixin",
"EntityMixin",
"LivingEntityMixin",
"MobEntityMixin",
"PigEntityMixin",
"PlayerEntityMixin",
"PlayerManagerMixin",
"ServerPlayerEntityMixin"
"ServerPlayerEntityMixin",
"TadpoleEntityMixin",
"VillagerEntityMixin",
"elytra.LivingEntityMixin",
"elytra.PlayerEntityMixin"
],
"injectors": {
"defaultRequire": 1,
Original file line number Diff line number Diff line change
@@ -114,6 +114,10 @@ public void onInitialize() {
LOGGER.info("{} died due to {} damage source", entity.getName().getString(), source.getName());
});

ServerLivingEntityEvents.MOB_CONVERSION.register((previous, converted, keepEquipment) -> {
LOGGER.info("{} is being converted to {} [{}]", previous.getName().getString(), converted.getName().getString(), keepEquipment);
});

EntitySleepEvents.ALLOW_SLEEPING.register((player, sleepingPos) -> {
// Can't sleep if holds blue wool
if (player.getStackInHand(Hand.MAIN_HAND).isOf(Items.BLUE_WOOL)) {
Original file line number Diff line number Diff line change
@@ -18,21 +18,28 @@

import java.util.function.BooleanSupplier;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.SharedConstants;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerTickManager;
import net.minecraft.test.TestManager;

@Mixin(MinecraftServer.class)
public abstract class MinecraftServerMixin {
@Shadow
@Final
private ServerTickManager tickManager;

@Inject(method = "tickWorlds", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;updatePlayerLatency()V", shift = At.Shift.AFTER))
private void tickWorlds(BooleanSupplier shouldKeepTicking, CallbackInfo callbackInfo) {
// Called by vanilla when isDevelopment is enabled.
if (!SharedConstants.isDevelopment) {
if (!SharedConstants.isDevelopment && this.tickManager.shouldTick()) {
TestManager.INSTANCE.tick();
}
}
Original file line number Diff line number Diff line change
@@ -17,12 +17,14 @@
package net.fabricmc.fabric.api.item.v1;

import com.google.common.collect.Multimap;
import org.jetbrains.annotations.Nullable;

import net.minecraft.block.BlockState;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.FoodComponent;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.entry.RegistryEntry;
@@ -123,4 +125,15 @@ default boolean isSuitableFor(ItemStack stack, BlockState state) {
default ItemStack getRecipeRemainder(ItemStack stack) {
return ((Item) this).hasRecipeRemainder() ? ((Item) this).getRecipeRemainder().getDefaultStack() : ItemStack.EMPTY;
}

/**
* This is a stack-aware version of {@link Item#getFoodComponent()}.
* Note that simple food component can also be set via {@link Item.Settings#food(FoodComponent)}.
* If you want to get a food component for a stack, is <strong>recommended</strong> to use the stack version of this method: {@link FabricItemStack#getFoodComponent()}.
*
* @return this item's {@link FoodComponent}, or {@code null} if none was set
*/
default @Nullable FoodComponent getFoodComponent(ItemStack stack) {
return ((Item) this).getFoodComponent();
}
}
Original file line number Diff line number Diff line change
@@ -16,6 +16,9 @@

package net.fabricmc.fabric.api.item.v1;

import org.jetbrains.annotations.Nullable;

import net.minecraft.item.FoodComponent;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

@@ -36,4 +39,14 @@ public interface FabricItemStack {
default ItemStack getRecipeRemainder() {
return ((ItemStack) this).getItem().getRecipeRemainder((ItemStack) this);
}

/**
* Stack-aware version of {@link Item#getFoodComponent()}.
* See {@link FabricItem#getFoodComponent(ItemStack)} for a more in depth description.
*
* @return this item stack's {@link FoodComponent}, or {@code null} if none was set
*/
default @Nullable FoodComponent getFoodComponent() {
return ((ItemStack) this).getItem().getFoodComponent(((ItemStack) this));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.mixin.item;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemUsageContext;

@Mixin(BlockItem.class)
class BlockItemMixin {
@Redirect(method = "useOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/BlockItem;isFood()Z"))
private boolean isStackAwareFood(BlockItem instance, ItemUsageContext context) {
return context.getStack().isFood();
}
}
Loading