Merge branch 'master' of https://github.com/gnembon/fabric-carpet
This commit is contained in:
commit
68af14211d
6 files changed
+75
-2
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.slot.TradeOutputSlot;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.village.Merchant;
|
||||
import net.minecraft.village.TradeOffer;
|
||||
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.CallbackInfoReturnable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_TRADES;
|
||||
|
||||
@Mixin(value = TradeOutputSlot.class)
|
||||
public abstract class TradeOutputSlot_scarpetEventMixin {
|
||||
@Shadow @Final private Merchant merchant;
|
||||
|
||||
@Inject(method = "onTakeItem", at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/village/Merchant;trade(Lnet/minecraft/village/TradeOffer;)V"),
|
||||
locals = LocalCapture.CAPTURE_FAILHARD
|
||||
)
|
||||
private void onTrade(PlayerEntity player, ItemStack stack, CallbackInfoReturnable cir, TradeOffer tradeOffer) {
|
||||
if(PLAYER_TRADES.isNeeded() && !this.merchant.getMerchantWorld().isClient())
|
||||
{
|
||||
PLAYER_TRADES.onTrade((ServerPlayerEntity) player, merchant, tradeOffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.passive.MerchantEntity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -35,6 +36,8 @@ import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.village.Merchant;
|
||||
import net.minecraft.village.TradeOffer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
@@ -548,6 +551,20 @@ public class CarpetEventServer
|
||||
), player::getCommandSource);
|
||||
}
|
||||
};
|
||||
public static final Event PLAYER_TRADES = new Event("player_trades", 5, false)
|
||||
{
|
||||
@Override
|
||||
public void onTrade(ServerPlayerEntity player, Merchant merchant, TradeOffer tradeOffer)
|
||||
{
|
||||
handler.call( () -> Arrays.asList(
|
||||
new EntityValue(player),
|
||||
merchant instanceof MerchantEntity ? new EntityValue((MerchantEntity) merchant) : Value.NULL,
|
||||
ValueConversions.of(tradeOffer.getOriginalFirstBuyItem()),
|
||||
ValueConversions.of(tradeOffer.getSecondBuyItem()),
|
||||
ValueConversions.of(tradeOffer.getSellItem())
|
||||
), player::getCommandSource);
|
||||
}
|
||||
};
|
||||
public static final Event PLAYER_PICKS_UP_ITEM = new Event("player_picks_up_item", 2, false)
|
||||
{
|
||||
@Override
|
||||
@@ -926,6 +943,7 @@ public class CarpetEventServer
|
||||
public void onDamage(Entity target, float amount, DamageSource source) { }
|
||||
public void onRecipeSelected(ServerPlayerEntity player, Identifier recipe, boolean fullStack) {}
|
||||
public void onSlotSwitch(ServerPlayerEntity player, int from, int to) {}
|
||||
public void onTrade(ServerPlayerEntity player, Merchant merchant, TradeOffer tradeOffer) {}
|
||||
|
||||
|
||||
public void onWorldEvent(ServerWorld world, BlockPos pos) { }
|
||||
|
||||
@@ -292,3 +292,14 @@ __on_player_picks_up_item(player, item) ->
|
||||
print(' Player '+player+' injects '+item);
|
||||
);
|
||||
|
||||
__on_player_trades(player, entity, buy, buyB, sell) ->
|
||||
(
|
||||
print('');
|
||||
print('__on_player_trades(player, item)');
|
||||
print('player trades:');
|
||||
print(' - player: '+player);
|
||||
print(' - entity: '+ entity);
|
||||
print(' - buy: '+ buy);
|
||||
print(' - buyB: '+ buyB);
|
||||
print(' - sell: '+ sell);
|
||||
);
|
||||
@@ -164,6 +164,7 @@
|
||||
"BlockItem_scarpetEventMixin",
|
||||
"PlayerManager_scarpetEventsMixin",
|
||||
"PlayerInventory_scarpetEventMixin",
|
||||
"TradeOutputSlot_scarpetEventMixin",
|
||||
|
||||
"ChunkTicketManager_scarpetMixin",
|
||||
"StatType_scarpetMixin",
|
||||
|
||||
Reference in new issue
Block a user