Skip to content

Commit cebbdbb

Browse files
committed
Fixes #3 (animal theft)
1 parent eefb291 commit cebbdbb

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/main/java/org/scbrm/fidelity/WhipItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity
4141
iequine.setMaster(user);
4242
} else if(iequine.getMaster() != user) {
4343
user.sendSystemMessage(new LiteralText("You do not own this animal"), Util.NIL_UUID);
44-
return ActionResult.FAIL;
44+
return ActionResult.success(user.world.isClient);
4545
}
4646

4747
final IHorseBaseEntity.State state = iequine.getState().next();

src/main/java/org/scbrm/fidelity/mixin/HorseBaseEntityMixin.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.scbrm.fidelity.mixin;
22

3+
import net.minecraft.entity.player.PlayerEntity;
34
import net.minecraft.nbt.CompoundTag;
45
import net.minecraft.server.ServerConfigHandler;
6+
import net.minecraft.text.LiteralText;
57
import org.scbrm.fidelity.bridge.IHorseBaseEntity;
68
import org.scbrm.fidelity.entity.ai.goal.ObeyMasterGoal;
79
import net.minecraft.entity.EntityType;
@@ -22,6 +24,8 @@
2224
import java.util.Optional;
2325
import java.util.UUID;
2426

27+
import static net.minecraft.util.Util.NIL_UUID;
28+
2529
@Mixin(HorseBaseEntity.class)
2630
public abstract class HorseBaseEntityMixin extends AnimalEntity implements IHorseBaseEntity {
2731

@@ -97,4 +101,13 @@ public void _readCustomDataFromTag(CompoundTag tag, CallbackInfo info) {
97101
}
98102
}
99103

104+
@Inject(at = @At("HEAD"), method = "putPlayerOnBack(Lnet/minecraft/entity/player/PlayerEntity;)V", cancellable = true)
105+
void preventTheft(PlayerEntity player, CallbackInfo info){
106+
if(!this.isMaster(player)) {
107+
if(!player.world.isClient)
108+
player.sendSystemMessage(new LiteralText("You do not own this animal"), NIL_UUID);
109+
info.cancel();
110+
}
111+
}
112+
100113
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.scbrm.fidelity.mixin;
2+
3+
import net.minecraft.entity.EntityType;
4+
import net.minecraft.entity.passive.HorseBaseEntity;
5+
import net.minecraft.entity.passive.HorseEntity;
6+
import net.minecraft.world.World;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
9+
@Mixin(HorseEntity.class)
10+
public abstract class HorseEntityMixin extends HorseBaseEntity {
11+
12+
protected HorseEntityMixin(EntityType<? extends HorseBaseEntity> entityType, World world) {
13+
super(entityType, world);
14+
}
15+
16+
17+
}

0 commit comments

Comments
 (0)