org.spongepowered.asm.mixin.injection.Slice Java Examples

The following examples show how to use org.spongepowered.asm.mixin.injection.Slice. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExperienceOrbEntityMixin_RealTime.java    From Galaxy with GNU Affero General Public License v3.0 6 votes vote down vote up
@Redirect(
    method = "tick",
    at = @At(value = "FIELD",
        target = "Lnet/minecraft/entity/ExperienceOrbEntity;orbAge:I",
        opcode = Opcodes.PUTFIELD
    ),
    slice = @Slice(
        from = @At(
            value = "FIELD",
            target = "Lnet/minecraft/entity/ExperienceOrbEntity;renderTicks:I",
            opcode = Opcodes.PUTFIELD
        ),
        to = @At(
            value = "CONSTANT",
            args = "intValue=6000"
        )
    )
)
private void realTimeImpl$adjustForRealTimeAge(final ExperienceOrbEntity self, final int modifier) {
    final int ticks = (int) ((RealTimeTrackingBridge) self.getEntityWorld()).realTimeBridge$getRealTimeTicks();
    this.orbAge += ticks;
}
 
Example #2
Source File: PlayerEntityMixin_RealTime.java    From Galaxy with GNU Affero General Public License v3.0 6 votes vote down vote up
@Redirect(
    method = "tick",
    at = @At(
        value = "FIELD",
        target = "Lnet/minecraft/entity/player/PlayerEntity;sleepTimer:I",
        opcode = Opcodes.PUTFIELD
    ),
    slice = @Slice(
        from = @At(
            value = "INVOKE",
            target = "Lnet/minecraft/entity/player/PlayerEntity;isSleeping()Z"
        ),
        to = @At(
            value = "CONSTANT",
            args = "intValue=100",
            ordinal = 0
        )
    )
)
private void realTimeImpl$adjustForRealTimeSleepTimer(final PlayerEntity self, final int modifier) {
    final int ticks = (int) ((RealTimeTrackingBridge) self.getEntityWorld()).realTimeBridge$getRealTimeTicks();
    this.sleepTimer += ticks;
}
 
Example #3
Source File: PlayerEntityMixin_RealTime.java    From Galaxy with GNU Affero General Public License v3.0 6 votes vote down vote up
@Redirect(
    method = "tick",
    at = @At(
        value = "FIELD",
        target = "Lnet/minecraft/entity/player/PlayerEntity;sleepTimer:I",
        opcode = Opcodes.PUTFIELD
    ),
    slice = @Slice(
        from = @At(
            value = "INVOKE",
            target = "Lnet/minecraft/entity/player/PlayerEntity;wakeUp(ZZ)V"
        ),
        to = @At(
            value = "CONSTANT",
            args = "intValue=110"
        )
    )
)
private void realTimeImpl$adjustForRealTimeWakeTimer(final PlayerEntity self, final int modifier) {
    final int ticks = (int) ((RealTimeTrackingBridge) self.getEntityWorld()).realTimeBridge$getRealTimeTicks();
    this.sleepTimer += ticks;
}
 
Example #4
Source File: EntityMixin_RealTime.java    From Galaxy with GNU Affero General Public License v3.0 6 votes vote down vote up
@Redirect(method = "baseTick",
    at = @At(
        value = "FIELD",
        target = "Lnet/minecraft/entity/Entity;ridingCooldown:I",
        opcode = Opcodes.PUTFIELD
    ),
    slice = @Slice(
        from = @At(
            value = "INVOKE",
            target = "Lnet/minecraft/entity/Entity;stopRiding()V"
        ),
        to = @At(
            value = "FIELD",
            target = "Lnet/minecraft/entity/Entity;horizontalSpeed:F",
            opcode = Opcodes.GETFIELD
        )
    )
)
private void realTimeImpl$adjustForRealTimeEntityCooldown(final Entity self, final int modifier) {
    final int ticks = (int) ((RealTimeTrackingBridge) this.world).realTimeBridge$getRealTimeTicks();
    this.ridingCooldown = Math.max(0, this.ridingCooldown - ticks);
}
 
Example #5
Source File: AbstractFurnaceBlockEntityMixin_RealTime.java    From Galaxy with GNU Affero General Public License v3.0 6 votes vote down vote up
@Redirect(method = "tick",
    at = @At(
        value = "FIELD",
        target = "Lnet/minecraft/block/entity/AbstractFurnaceBlockEntity;burnTime:I",
        opcode = Opcodes.PUTFIELD
    ),
    slice = @Slice(
        from = @At(
            value = "INVOKE",
            target = "Lnet/minecraft/block/entity/AbstractFurnaceBlockEntity;isBurning()Z",
            opcode = 1
        ),
        to = @At(
            value = "FIELD",
            target = "Lnet/minecraft/block/entity/AbstractFurnaceBlockEntity;world:Lnet/minecraft/world/World;",
            opcode = Opcodes.GETFIELD,
            ordinal = 0
        )
    )
)
private void realTimeImpl$adjustForRealTimeBurnTime(final AbstractFurnaceBlockEntity self, final int modifier) {
    final int ticks = (int) ((RealTimeTrackingBridge) this.getWorld()).realTimeBridge$getRealTimeTicks();
    this.burnTime = Math.max(0, this.burnTime - Math.max(1, ticks - 1));
}
 
Example #6
Source File: AbstractFurnaceBlockEntityMixin_RealTime.java    From Galaxy with GNU Affero General Public License v3.0 6 votes vote down vote up
@Redirect(
    method = "tick",
    at = @At(
        value = "FIELD",
        target = "Lnet/minecraft/block/entity/AbstractFurnaceBlockEntity;cookTime:I",
        opcode = Opcodes.PUTFIELD
    ),
    slice = @Slice(
        from = @At(
            value = "INVOKE",
            target = "Lnet/minecraft/block/entity/AbstractFurnaceBlockEntity;canAcceptRecipeOutput(Lnet/minecraft/recipe/Recipe;)Z",
            ordinal = 1
        ),
        to = @At(
            value = "FIELD",
            target = "Lnet/minecraft/block/entity/AbstractFurnaceBlockEntity;cookTimeTotal:I",
            opcode = Opcodes.GETFIELD,
            ordinal = 0
        )
    )
)
private void realTimeImpl$adjustForRealTimeCookTime(final AbstractFurnaceBlockEntity self, final int modifier) {
    final int ticks = (int) ((RealTimeTrackingBridge) this.getWorld()).realTimeBridge$getRealTimeTicks();
    this.cookTime = Math.min(this.cookTimeTotal, this.cookTime + ticks);
}
 
Example #7
Source File: AbstractFurnaceBlockEntityMixin_RealTime.java    From Galaxy with GNU Affero General Public License v3.0 6 votes vote down vote up
@Redirect(
    method = "tick",
    at = @At(
        value = "FIELD",
        target = "Lnet/minecraft/block/entity/AbstractFurnaceBlockEntity;cookTime:I",
        opcode = Opcodes.PUTFIELD
    ),
    slice = @Slice(
        from = @At(
            value = "INVOKE",
            target = "Lnet/minecraft/util/math/MathHelper;clamp(III)I"
        ),
        to = @At(
            value = "INVOKE",
            target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"
        )
    )
)
private void realTimeImpl$adjustForRealTimeCookTimeCooldown(final AbstractFurnaceBlockEntity self, final int modifier) {
    final int ticks = (int) ((RealTimeTrackingBridge) this.getWorld()).realTimeBridge$getRealTimeTicks();
    this.cookTime = MathHelper.clamp(this.cookTime - (2 * ticks), 0, this.cookTimeTotal);
}
 
Example #8
Source File: MixinCauldronBlock.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "onUse",
        slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/potion/PotionUtil;getPotion(Lnet/minecraft/item/ItemStack;)Lnet/minecraft/potion/Potion;")),
        at = @At(value = "RETURN", ordinal = 0),
        cancellable = true)
private void cancelWaterBottleUse(CallbackInfoReturnable<ActionResult> ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_10) {
        ci.setReturnValue(ActionResult.PASS);
    }
}
 
Example #9
Source File: MixinClientPlayerEntity.java    From multiconnect with MIT License 5 votes vote down vote up
@Redirect(method = "tickMovement",
        slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isWalking()Z")),
        at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSwimming()Z", ordinal = 0))
public boolean redirectIsSneakingWhileSwimming(ClientPlayerEntity _this) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_14_1)
        return false;
    else
        return _this.isSwimming();
}
 
Example #10
Source File: BlocksMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Redirect(method = "<clinit>",
    slice = @Slice(from = @At(value = "CONSTANT", args = "stringValue=obsidian")),
    at = @At(value = "INVOKE",
        target = "Lnet/minecraft/block/Blocks;register(Ljava/lang/String;Lnet/minecraft/block/Block;)Lnet/minecraft/block/Block;",
        ordinal = 0))
private static Block registerObsidian(String id, Block obsidian)
{
    return register("obsidian", new ObsidianBlock(Block.Settings.of(Material.STONE, MaterialColor.BLACK).strength(50.0F, 1200.0F)));
}
 
Example #11
Source File: ChunkSerializerMixin.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "serialize", slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;saveToTag(Lnet/minecraft/nbt/CompoundTag;)Z"), to = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/ProtoChunk;getEntities()Ljava/util/List;")), at = @At(value = "JUMP", opcode = Opcodes.GOTO, ordinal = 2), locals = LocalCapture.CAPTURE_FAILHARD)
private static void serializeCapabilities(ServerWorld serverWorld, Chunk chunk, CallbackInfoReturnable<CompoundTag> callbackInfoReturnable, ChunkPos chunkPos, CompoundTag compoundTag, CompoundTag level) {
	CompoundTag tag = ((CapabilityProviderHolder) chunk).serializeCaps();

	if (tag != null) {
		level.put("ForgeCaps", tag);
	}
}
 
Example #12
Source File: CreeperEntityMixin_RealTime.java    From Galaxy with GNU Affero General Public License v3.0 5 votes vote down vote up
@Redirect(
    method = "tick",
    at = @At(
        value = "FIELD",
        target = "Lnet/minecraft/entity/mob/CreeperEntity;currentFuseTime:I",
        opcode = Opcodes.PUTFIELD,
        ordinal = 0
    ),
    slice = @Slice(
        from = @At(value = "INVOKE", target = "Lnet/minecraft/entity/mob/CreeperEntity;playSound(Lnet/minecraft/sound/SoundEvent;FF)V"),
        to = @At(value = "CONSTANT", args = "intValue=0", ordinal = 0)
    )
)
private void realTimeImpl$adjustForRealTimeCreeperFuseTime(final CreeperEntity self, final int modifier) {
    if (modifier != 0) {
        final int ticks = (int) ((RealTimeTrackingBridge) self.getEntityWorld()).realTimeBridge$getRealTimeTicks();
        this.currentFuseTime += (getFuseSpeed() * ticks);

        // delay 1 tick wait AI detect player distance
        if (currentFuseTime >= fuseTime && !delay) {
            delay = true;
            currentFuseTime = fuseTime - 1;
        } else if (delay) {
            delay = false;
        }
    }
}
 
Example #13
Source File: EntityMixin_RealTime.java    From Galaxy with GNU Affero General Public License v3.0 5 votes vote down vote up
@Redirect(method = "tickNetherPortal",
    at = @At(
        value = "FIELD",
        target = "Lnet/minecraft/entity/Entity;netherPortalTime:I",
        opcode = Opcodes.PUTFIELD, ordinal = 0
    ),
    slice = @Slice(
        from = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getMaxNetherPortalTime()I"),
        to = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getDefaultNetherPortalCooldown()I")
    )
)
private void realTimeImpl$adjustForRealTimePortalCounter(final Entity self, final int modifier) {
    final int ticks = (int) ((RealTimeTrackingBridge) this.world).realTimeBridge$getRealTimeTicks();
    this.netherPortalTime += ticks;
}
 
Example #14
Source File: MethodSlice.java    From Mixin with MIT License 5 votes vote down vote up
/**
 * Parses the supplied annotation into a MethodSlice
 * 
 * @param owner Owner injection info
 * @param slice Annotation to parse
 * @return parsed MethodSlice
 */
public static MethodSlice parse(ISliceContext owner, Slice slice) {
    String id = slice.id();
    
    At from = slice.from();
    At to = slice.to();
    
    InjectionPoint fromPoint = from != null ? InjectionPoint.parse(owner, from) : null;
    InjectionPoint toPoint = to != null ? InjectionPoint.parse(owner, to) : null;
    
    return new MethodSlice(owner, id, fromPoint, toPoint);
}