use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinCommandDifficulty method onSetDifficulty.
/**
* @author Minecrell - September 28, 2016
* @reason Change difficulty only in the world the command was executed in
*/
@Redirect(method = "execute", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;" + "setDifficultyForAllWorlds(Lnet/minecraft/world/EnumDifficulty;)V"))
private void onSetDifficulty(MinecraftServer server, EnumDifficulty difficulty, MinecraftServer server2, ICommandSender sender, String[] args) {
World world = sender.getEntityWorld();
// Coped from MinecraftServer.setDifficultyForAllWorlds
if (world.getWorldInfo().isHardcoreModeEnabled()) {
world.getWorldInfo().setDifficulty(EnumDifficulty.HARD);
world.setAllowedSpawnTypes(true, true);
} else if (server.isSinglePlayer()) {
world.getWorldInfo().setDifficulty(difficulty);
world.setAllowedSpawnTypes(world.getDifficulty() != EnumDifficulty.PEACEFUL, true);
} else {
world.getWorldInfo().setDifficulty(difficulty);
world.setAllowedSpawnTypes(server.allowSpawnMonsters(), server.getCanSpawnAnimals());
}
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinCommandToggleDownfall method onToggleDownfall.
@Redirect(method = "execute", at = @At(value = "INVOKE", target = "Lnet/minecraft/command/CommandToggleDownfall;toggleRainfall(Lnet/minecraft/server/MinecraftServer;)V"))
private void onToggleDownfall(CommandToggleDownfall self, MinecraftServer server, MinecraftServer server2, ICommandSender sender, String[] args) {
WorldInfo worldInfo = sender.getEntityWorld().getWorldInfo();
worldInfo.setRaining(!worldInfo.isRaining());
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinPlayerAdvancements method onUnregisterListenersGetProgress.
@Nullable
@Redirect(method = "unregisterListeners", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/advancements/AdvancementProgress;getCriterionProgress(Ljava/lang/String;)Lnet/minecraft/advancements/CriterionProgress;"))
private CriterionProgress onUnregisterListenersGetProgress(AdvancementProgress advancementProgress, String criterion) {
final org.spongepowered.api.advancement.Advancement advancement = ((org.spongepowered.api.advancement.AdvancementProgress) advancementProgress).getAdvancement();
final AdvancementCriterion advancementCriterion = (AdvancementCriterion) ((Advancement) advancement).getCriteria().get(criterion);
final IMixinCriterion mixinCriterion = (IMixinCriterion) advancementCriterion;
// Only remove the trigger once the goal is reached
if (mixinCriterion.getScoreCriterion() != null && !((org.spongepowered.api.advancement.AdvancementProgress) advancementProgress).get(mixinCriterion.getScoreCriterion()).get().achieved()) {
return null;
}
return advancementProgress.getCriterionProgress(criterion);
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinBlockDispenser method onSetInventoryContents.
@Redirect(method = "dispense", at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/TileEntityDispenser;setInventorySlotContents(ILnet/minecraft/item/ItemStack;)V"))
public void onSetInventoryContents(TileEntityDispenser dispenser, int index, @Nullable ItemStack stack) {
final PhaseData phaseData = PhaseTracker.getInstance().getCurrentPhaseData();
final PhaseContext<?> context = phaseData.context;
// If we captured nothing, simply set the slot contents and return
if (context.getCapturedItemsOrEmptyList().isEmpty()) {
dispenser.setInventorySlotContents(index, stack);
return;
}
final ItemStack dispensedItem = context.getCapturedItems().get(0).getItem();
final ItemStackSnapshot snapshot = ItemStackUtil.snapshotOf(dispensedItem);
final List<ItemStackSnapshot> original = new ArrayList<>();
original.add(snapshot);
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(dispenser);
final DropItemEvent.Pre dropEvent = SpongeEventFactory.createDropItemEventPre(Sponge.getCauseStackManager().getCurrentCause(), ImmutableList.of(snapshot), original);
SpongeImpl.postEvent(dropEvent);
if (dropEvent.isCancelled()) {
dispenser.setInventorySlotContents(index, (net.minecraft.item.ItemStack) this.originalItem.createStack());
context.getCapturedItems().clear();
return;
}
if (dropEvent.getDroppedItems().isEmpty()) {
context.getCapturedItems().clear();
}
dispenser.setInventorySlotContents(index, stack);
}
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinBlockFalling method onIsAreaLoadedCheck.
@Redirect(method = "checkFallable", at = @At(value = "INVOKE", target = WORLD_IS_AREA_LOADED))
private boolean onIsAreaLoadedCheck(World world, BlockPos pos, BlockPos to) {
if (world.isAreaLoaded(pos, to)) {
if (!world.isRemote) {
BlockPos actualPos = pos.add(32, 32, 32);
EntityType fallingBlock = EntityTypes.FALLING_BLOCK;
Vector3d position = new Vector3d(actualPos.getX() + 0.5D, actualPos.getY(), actualPos.getZ() + 0.5D);
BlockSnapshot snapshot = ((org.spongepowered.api.world.World) world).createSnapshot(actualPos.getX(), actualPos.getY(), actualPos.getZ());
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(snapshot);
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.FALLING_BLOCK);
Transform<org.spongepowered.api.world.World> worldTransform = new Transform<>((org.spongepowered.api.world.World) world, position);
ConstructEntityEvent.Pre event = SpongeEventFactory.createConstructEntityEventPre(Sponge.getCauseStackManager().getCurrentCause(), fallingBlock, worldTransform);
SpongeImpl.postEvent(event);
return !event.isCancelled();
}
}
}
return false;
}
Aggregations