Skip to content

Commit

Permalink
force players out of shops that are more than 10 blocks away (fixes w…
Browse files Browse the repository at this point in the history
  • Loading branch information
gliscowo committed Feb 9, 2024
1 parent 84842a2 commit 988f3f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected ScreenHandler createScreenHandler(int syncId, PlayerInventory playerIn

@Override
public boolean canPlayerUse(PlayerEntity player) {
return player.getUuid().equals(this.owner);
return player.getUuid().equals(this.owner) && this.pos.getSquaredDistance(player.getX(), player.getY(), player.getZ()) <= 100;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,8 @@ public SoundEvent getYesSound() {
public boolean isClient() {
return false;
}

public ShopBlockEntity shop() {
return this.shop;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.glisco.numismaticoverhaul.mixin;

import com.glisco.numismaticoverhaul.ModComponents;
import com.glisco.numismaticoverhaul.block.ShopMerchant;
import com.glisco.numismaticoverhaul.currency.CurrencyComponent;
import com.glisco.numismaticoverhaul.currency.CurrencyHelper;
import com.glisco.numismaticoverhaul.item.CoinItem;
Expand All @@ -17,6 +18,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(MerchantScreenHandler.class)
public class MerchantScreenHandlerMixin {
Expand Down Expand Up @@ -88,4 +90,13 @@ public void checkForEntityOnYes(CallbackInfo ci) {
if (!(merchant instanceof Entity)) ci.cancel();
}

@Inject(method = "canUse", at = @At("HEAD"), cancellable = true)
public void thwartTaxEvasion(PlayerEntity player, CallbackInfoReturnable<Boolean> cir) {
if (!(this.merchant instanceof ShopMerchant shopMerchant)) return;

if (shopMerchant.shop().getPos().getSquaredDistance(player.getX(), player.getY(), player.getZ()) > 100) {
cir.setReturnValue(false);
}
}

}

0 comments on commit 988f3f4

Please sign in to comment.