use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class CommandsMixin method impl$preventPutIntoMapIfNodeIsComplex.
@SuppressWarnings("unchecked")
@Redirect(method = "fillUsableCommands", at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", remap = false))
private <K, V> V impl$preventPutIntoMapIfNodeIsComplex(final Map<K, V> map, final K key, final V value, final CommandNode<CommandSourceStack> rootCommandSource, final CommandNode<SharedSuggestionProvider> rootSuggestion, final CommandSourceStack source, final Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> commandNodeToSuggestionNode) {
if (!map.containsKey(key)) {
// done here because this check is applicable
final ServerPlayer e = (ServerPlayer) source.getEntity();
final Map<CommandNode<CommandSourceStack>, List<CommandNode<SharedSuggestionProvider>>> playerNodes = this.impl$playerNodeCache.get(e);
if (!playerNodes.containsKey(key)) {
final List<CommandNode<SharedSuggestionProvider>> children = new ArrayList<>();
children.add((CommandNode<SharedSuggestionProvider>) value);
playerNodes.put((CommandNode<CommandSourceStack>) key, children);
}
// we need to swap it out.
if (value instanceof ArgumentCommandNode && CommandUtil.checkForCustomSuggestions(rootSuggestion)) {
rootSuggestion.addChild(this.impl$cloneArgumentCommandNodeWithoutSuggestions((ArgumentCommandNode<SharedSuggestionProvider, ?>) value));
} else {
rootSuggestion.addChild((CommandNode<SharedSuggestionProvider>) value);
}
return map.put(key, value);
}
// it's ignored anyway.
return null;
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinEntityArmorStand method fireDamageEventDamage.
@Redirect(method = "attackEntityFrom", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/EntityArmorStand;damageArmorStand(F)V"))
private void fireDamageEventDamage(EntityArmorStand self, float effectiveAmount, DamageSource source, float originalAmount) {
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
DamageEventHandler.generateCauseFor(source);
DamageEntityEvent event = SpongeEventFactory.createDamageEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), new ArrayList<>(), this, effectiveAmount);
if (!SpongeImpl.postEvent(event)) {
this.damageArmorStand((float) event.getFinalDamage());
}
}
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinEntityParrot method onTame.
@Redirect(method = "processInteract", at = @At(value = "INVOKE", target = "Ljava/util/Random;nextInt(I)I", ordinal = 0, remap = false))
public int onTame(Random rand, int bound, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
int random = rand.nextInt(bound);
if (random == 0) {
stack.setCount(stack.getCount() + 1);
try (StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(player);
if (!SpongeImpl.postEvent(SpongeEventFactory.createTameEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), this))) {
stack.setCount(stack.getCount() - 1);
return random;
}
}
}
return 1;
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinEntityWolf method onTame.
@Redirect(method = "processInteract", at = @At(value = "INVOKE", target = "Ljava/util/Random;nextInt(I)I", ordinal = 0, remap = false))
public int onTame(Random rand, int bound, EntityPlayer player, EnumHand hand) {
int random = rand.nextInt(bound);
ItemStack stack = player.getHeldItem(hand);
if (random == 0) {
stack.shrink(1);
try {
Sponge.getCauseStackManager().pushCause(((org.spongepowered.api.item.inventory.ItemStack) stack).createSnapshot());
Sponge.getCauseStackManager().pushCause(player);
if (!SpongeImpl.postEvent(SpongeEventFactory.createTameEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), this))) {
stack.grow(1);
return random;
}
} finally {
Sponge.getCauseStackManager().popCauses(2);
}
}
return 1;
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinInventoryPlayer method onAdd.
@Redirect(method = "storePartialItemStack", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/InventoryPlayer;addResource(ILnet/minecraft/item/ItemStack;)I"))
public int onAdd(InventoryPlayer inv, int index, ItemStack stack) {
if (this.doCapture) {
// Capture items getting picked up
Slot slot = index == 40 ? this.getOffhand() : getSpongeSlot(index);
ItemStackSnapshot original = ItemStackUtil.snapshotOf(this.getStackInSlot(index));
int result = this.addResource(index, stack);
ItemStackSnapshot replacement = ItemStackUtil.snapshotOf(this.getStackInSlot(index));
this.capturedTransactions.add(new SlotTransaction(slot, original, replacement));
return result;
}
return this.addResource(index, stack);
}
Aggregations