generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
596599b
commit 1fd282e
Showing
16 changed files
with
427 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
src/main/java/com/imyvm/villagerShop/mixin/ExampleMixin.java
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
src/main/java/com/imyvm/villagerShop/mixin/NoCollisionMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.imyvm.villagerShop.mixin; | ||
|
||
import net.minecraft.entity.Entity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(Entity.class) | ||
public abstract class NoCollisionMixin { | ||
|
||
@Inject(method = "isCollidable", at = @At("HEAD"), cancellable = true) | ||
private void isCollidable(CallbackInfoReturnable<Boolean> callback) { | ||
// 获取实体的NBT数据 | ||
Entity Entity = (Entity) (Object) this; | ||
|
||
// 判断实体的NBT数据中是否包含特定键值 | ||
if (Entity.getScoreboardTags().contains("VillagerShop")) { | ||
callback.setReturnValue(false); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/imyvm/villagerShop/mixin/VillagerCanMoveMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.imyvm.villagerShop.mixin; | ||
|
||
import net.minecraft.command.argument.EntityAnchorArgumentType; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.passive.VillagerEntity; | ||
import net.minecraft.util.math.Vec3d; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import com.imyvm.villagerShop.VillagerShopMain; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.util.math.Box; | ||
import java.util.List; | ||
@Mixin(VillagerEntity.class) | ||
public class VillagerCanMoveMixin { | ||
|
||
@Inject(method = "tick", at = @At("HEAD"), cancellable = true) | ||
public void tick(CallbackInfo ci) { | ||
VillagerEntity villager = (VillagerEntity) (Object) this; | ||
Box searchBox = villager.getBoundingBox().expand(10); | ||
List<PlayerEntity> nearbyPlayers = villager.world.getEntitiesByClass(PlayerEntity.class, searchBox, player -> true); | ||
|
||
if (villager.getScoreboardTags().contains("VillagerShop")&& !nearbyPlayers.isEmpty()) { | ||
// 阻止村民移动 | ||
villager.setVelocity(0, villager.getVelocity().y, 0); | ||
|
||
// 允许村民继续看向玩家 | ||
PlayerEntity targetPlayer = nearbyPlayers.get(0); | ||
Vec3d targetPlayerPosition = targetPlayer.getPos().add(0, targetPlayer.getEyeHeight(targetPlayer.getPose()), 0); | ||
villager.lookAt(EntityAnchorArgumentType.EntityAnchor.EYES, targetPlayerPosition); | ||
} | ||
// 取消后续方法调用 | ||
ci.cancel(); | ||
} | ||
} | ||
|
||
|
28 changes: 28 additions & 0 deletions
28
src/main/java/com/imyvm/villagerShop/mixin/VillagerPreventWitchMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.imyvm.villagerShop.mixin; | ||
|
||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.passive.PassiveEntity; | ||
import net.minecraft.entity.passive.VillagerEntity; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(VillagerEntity.class) | ||
public abstract class VillagerPreventWitchMixin extends PassiveEntity { | ||
|
||
public VillagerPreventWitchMixin(EntityType<? extends PassiveEntity> entityType, World world) { | ||
super(entityType, world); | ||
} | ||
|
||
@Inject(method = "onStruckByLightning", at = @At("HEAD"), cancellable = true) | ||
private void preventWitchTransformation(CallbackInfo ci) { | ||
LivingEntity livingEntity = this; | ||
if (livingEntity.getScoreboardTags().contains("VillagerShop")) { | ||
ci.cancel(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.