下面列出了net.minecraft.util.profiler.Profiler#org.spongepowered.asm.mixin.injection.callback.LocalCapture 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Inject( method = "onChunkData", locals = LocalCapture.CAPTURE_FAILHARD, require = 0, at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/world/ClientWorld;getBlockEntity(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/entity/BlockEntity;",
shift = At.Shift.AFTER
))
private void recreateMovingPistons(ChunkDataS2CPacket packet, CallbackInfo ci,
Iterator var5, CompoundTag tag, BlockPos blockPos)
{
if (CarpetSettings.smoothClientAnimations)
{
BlockEntity blockEntity = world.getBlockEntity(blockPos);
if (blockEntity == null && "minecraft:piston".equals(tag.getString("id")))
{
BlockState blockState = world.getBlockState(blockPos);
if (blockState.getBlock() == Blocks.MOVING_PISTON) {
tag.putFloat("progress", Math.min(tag.getFloat("progress") + 0.5F, 1.0F));
blockEntity = new PistonBlockEntity();
blockEntity.fromTag(tag);
world.setBlockEntity(blockPos, blockEntity);
blockEntity.resetBlock();
}
}
}
}
@Inject(method = "move", at = @At(value = "INVOKE", shift = At.Shift.BEFORE,
target = "Ljava/util/List;size()I", ordinal = 4),locals = LocalCapture.CAPTURE_FAILHARD)
private void onMove(World world_1, BlockPos blockPos_1, Direction direction_1, boolean boolean_1,
CallbackInfoReturnable<Boolean> cir, BlockPos blockPos_2, PistonHandler pistonHandler_1, Map map_1,
List<BlockPos> list_1, List<BlockState> list_2, List list_3, int int_2, BlockState[] blockStates_1,
Direction direction_2)
{
//Get the blockEntities and remove them from the world before any magic starts to happen
if (CarpetSettings.movableBlockEntities)
{
list1_BlockEntities.set(Lists.newArrayList());
for (int i = 0; i < list_1.size(); ++i)
{
BlockPos blockpos = list_1.get(i);
BlockEntity blockEntity = (list_2.get(i).getBlock().hasBlockEntity()) ? world_1.getBlockEntity(blockpos) : null;
list1_BlockEntities.get().add(blockEntity);
if (blockEntity != null)
{
//hopefully this call won't have any side effects in the future, such as dropping all the BlockEntity's items
//we want to place this same(!) BlockEntity object into the world later when the movement stops again
world_1.removeBlockEntity(blockpos);
blockEntity.markDirty();
}
}
}
}
@Inject(method = "render", at = @At("RETURN"), locals = LocalCapture.NO_CAPTURE)
private void endMethod3576(PistonBlockEntity pistonBlockEntity_1, float partialTicks, MatrixStack matrixStack_1, VertexConsumerProvider layeredVertexConsumerStorage_1, int int_1, int init_2, CallbackInfo ci)
{
if (((PistonBlockEntityInterface) pistonBlockEntity_1).getRenderCarriedBlockEntity())
{
BlockEntity carriedBlockEntity = ((PistonBlockEntityInterface) pistonBlockEntity_1).getCarriedBlockEntity();
if (carriedBlockEntity != null)
{
carriedBlockEntity.setPos(pistonBlockEntity_1.getPos());
//((BlockEntityRenderDispatcherInterface) BlockEntityRenderDispatcher.INSTANCE).renderBlockEntityOffset(carriedBlockEntity, float_1, int_1, BlockRenderLayer.field_20799, bufferBuilder_1, pistonBlockEntity_1.getRenderOffsetX(float_1), pistonBlockEntity_1.getRenderOffsetY(float_1), pistonBlockEntity_1.getRenderOffsetZ(float_1));
matrixStack_1.translate(
pistonBlockEntity_1.getRenderOffsetX(partialTicks),
pistonBlockEntity_1.getRenderOffsetY(partialTicks),
pistonBlockEntity_1.getRenderOffsetZ(partialTicks)
);
BlockEntityRenderDispatcher.INSTANCE.render(carriedBlockEntity, partialTicks, matrixStack_1, layeredVertexConsumerStorage_1);
}
}
}
@SuppressWarnings("UnresolvedMixinReference")
@Inject(
method = "method_13238",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/PlayerManager;broadcastChatMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V",
ordinal = 0
),
locals = LocalCapture.CAPTURE_FAILSOFT
)
private static void onCommand(CommandContext<ServerCommandSource> context, CallbackInfoReturnable<Integer> cir, TranslatableText translatableText, Entity entity) {
if (!(entity instanceof ServerPlayerEntity)) return;
Main main = Main.Companion.getMain();
ServerPlayerEntity player = (ServerPlayerEntity) entity;
if (main == null || !main.getEventManager().emit(new PlayerChatEvent(player, translatableText)).getCancel()) {
player.server.getPlayerManager().broadcastChatMessage(translatableText, MessageType.CHAT, entity.getUuid());
} else {
cir.setReturnValue(0);
cir.cancel();
player.server.sendSystemMessage(translatableText.append(" (Canceled)"), entity.getUuid());
}
}
@SuppressWarnings("UnresolvedMixinReference")
@Inject(
method = "method_13563",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/PlayerManager;broadcastChatMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V",
ordinal = 0
),
locals = LocalCapture.CAPTURE_FAILSOFT
)
private static void onCommand(CommandContext<ServerCommandSource> context, CallbackInfoReturnable<Integer> cir, Text text, TranslatableText translatableText, Entity entity) {
if (!(entity instanceof ServerPlayerEntity)) return;
Main main = Main.Companion.getMain();
ServerPlayerEntity player = (ServerPlayerEntity) entity;
if (main == null || !main.getEventManager().emit(new PlayerChatEvent(player, translatableText)).getCancel()) {
player.server.getPlayerManager().broadcastChatMessage(translatableText, MessageType.CHAT, entity.getUuid());
} else {
cir.setReturnValue(0);
cir.cancel();
player.server.sendSystemMessage(translatableText.append(" (Canceled)"), entity.getUuid());
}
}
@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/vehicle/HopperMinecartEntity;setTransferCooldown(I)V",ordinal = 0),locals = LocalCapture.CAPTURE_FAILHARD)
private void rememberBlockPos(CallbackInfo ci){
if(CarpetExtraSettings.hopperMinecart8gtCooldown)
this.currentBlockPos = this.getBlockPos();
else
this.currentBlockPos = BlockPos.ORIGIN;
}
@Inject(method = "canOperate", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/HopperBlockEntity;extract(Lnet/minecraft/inventory/Inventory;Lnet/minecraft/entity/ItemEntity;)Z", shift = At.Shift.BEFORE),cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
private void extractAndReturnSuccess(CallbackInfoReturnable<Boolean> cir, List list_1) {
if (CarpetExtraSettings.hopperMinecart8gtCooldown) {
boolean result = HopperBlockEntity.extract(this, (ItemEntity) list_1.get(0));
cir.setReturnValue(result);
cir.cancel();
}
}
@Inject(
method = "tick",
at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 1,
target = "Lnet/minecraft/entity/FallingBlockEntity;setVelocity(Lnet/minecraft/util/math/Vec3d;)V"),
locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true
)
private void onTick(CallbackInfo ci, Block block_1, BlockPos blockPos_2, boolean b1, boolean bl2, BlockState blockState_1)
{
if (block_1.matches(BlockTags.ANVIL))
{
if (CarpetExtraSettings.renewablePackedIce && this.world.getBlockState(new BlockPos(this.getX(), this.getY() - 0.059999999776482582D, this.getZ())).getBlock() == Blocks.ICE)
{
if (iceCount < 2)
{
world.breakBlock(blockPos_2.down(), false, null);
this.onGround = false;
iceCount++;
ci.cancel();
}
else
{
world.setBlockState(blockPos_2.down(), Blocks.PACKED_ICE.getDefaultState(), 3);
world.playLevelEvent(2001, blockPos_2.down(), Block.getRawIdFromState(Blocks.PACKED_ICE.getDefaultState()));
}
}
else if (CarpetExtraSettings.renewableSand && this.world.getBlockState(new BlockPos(this.getX(), this.getY() - 0.06, this.getZ())).getBlock() == Blocks.COBBLESTONE)
{
world.breakBlock(blockPos_2.down(1), false);
world.setBlockState(blockPos_2.down(1), Blocks.SAND.getDefaultState(), 3);
}
}
}
@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);
}
}
@Inject(method = "drop", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/LivingEntity;playerHitTimer : I"), locals = LocalCapture.CAPTURE_FAILHARD)
private void hookDropForCapturePre(DamageSource src, CallbackInfo info, int lootingLevel) {
IForgeEntity forgeEntity = (IForgeEntity) this;
forgeEntity.captureDrops(new ArrayList<>());
dropLootingLevel.set(lootingLevel);
}
@Inject(method = SPAWN, at = @At(value = "INVOKE", target = "net/minecraft/world/World.spawnEntity(Lnet/minecraft/entity/Entity;)Z"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
private void hookMobSpawns(World world, @Nullable CompoundTag itemTag, @Nullable Text name, @Nullable PlayerEntity player, BlockPos pos, SpawnType type, boolean alignPosition, boolean bl, CallbackInfoReturnable<Entity> callback, Entity entity) {
if (!(entity instanceof MobEntity)) {
return;
}
MobEntity mob = (MobEntity) entity;
if (EntityEvents.doSpecialSpawn(mob, world, pos.getX(), pos.getY(), pos.getZ(), null, type)) {
callback.setReturnValue(null);
}
}
@Inject(method = "onMouseScroll", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSpectator()Z", shift = Shift.BEFORE), cancellable = true)
private void onMouseScroll(long window, double d, double e, CallbackInfo info, double f, float i) {
final Event event = new InputEvent.MouseScrollEvent(f, wasLeftButtonClicked(), middleButtonClicked, wasRightButtonClicked(), getX(), getY());
if (MinecraftForge.EVENT_BUS.post(event)) {
info.cancel();
}
}
@Inject(method = "method_1611", at = @At("HEAD"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
public void preMouseClicked(boolean[] handled, double mouseX, double mouseY, int button, CallbackInfo info) {
if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseClickedEvent.Pre(client.currentScreen, mouseX, mouseY, button))) {
handled[0] = true;
info.cancel();
}
}
@Inject(method = "method_1611", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private void postMouseClicked(boolean[] handled, double mouseX, double mouseY, int button, CallbackInfo info) {
if (handled[0]) {
return;
}
if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseClickedEvent.Post(client.currentScreen, mouseX, mouseY, button))) {
handled[0] = true;
info.cancel();
}
}
@Inject(method = "method_1605", at = @At("HEAD"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private void preMouseReleased(boolean[] handled, double mouseX, double mouseY, int button, CallbackInfo info) {
if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseReleasedEvent.Pre(client.currentScreen, mouseX, mouseY, button))) {
handled[0] = true;
info.cancel();
}
}
@Inject(method = "method_1605", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD)
private void postMouseReleased(boolean[] handled, double mouseX, double mouseY, int button, CallbackInfo info) {
if (handled[0]) {
return;
}
if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseReleasedEvent.Post(client.currentScreen, mouseX, mouseY, button))) {
handled[0] = true;
info.cancel();
}
}
@Inject(method = "onMouseScroll", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/gui/screen/Screen;mouseScrolled(DDD)Z",
ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private void preMouseScrolled(long window, double xOffset, double yOffset, CallbackInfo info, double amount, double mouseX, double mouseY) {
if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseScrollEvent.Pre(client.currentScreen, mouseX, mouseY, amount))) {
info.cancel();
}
}
@Inject(method = "tryMove", at = @At(value = "INVOKE", target = "Ljava/util/List;get(I)Ljava/lang/Object;", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
/**
* Handles blocks besides the slimeblock that are sticky. Currently only supports blocks that are sticky on one side.
* @author 2No2Name
*/
private void stickToStickySide(BlockPos blockPos_1, Direction direction_1, CallbackInfoReturnable<Boolean> cir, BlockState blockState_1, Block block_1, int int_1, int int_2, int int_4, BlockPos blockPos_3, int int_5, int int_6){
if(!stickToStickySide(blockPos_3)){
cir.setReturnValue(false);
cir.cancel();
}
}
@Inject(method = "calculatePush", at = @At(value = "INVOKE", target = "Ljava/util/List;get(I)Ljava/lang/Object;", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
/**
* Handles blocks besides the slimeblock that are sticky. Currently only supports blocks that are sticky on one side.
* @author 2No2Name
*/
private void stickToStickySide(CallbackInfoReturnable<Boolean> cir, int int_1){
BlockPos pos = this.movedBlocks.get(int_1);
if(!stickToStickySide(pos)){
cir.setReturnValue(false);
cir.cancel();
}
}
@Inject(method = "tickChunk", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/world/ServerWorld;addLightning(Lnet/minecraft/entity/LightningEntity;)V"
))
private void onNaturalLightinig(WorldChunk chunk, int randomTickSpeed, CallbackInfo ci,
ChunkPos chunkPos, boolean bl, int i, int j, Profiler profiler, BlockPos blockPos, boolean bl2)
{
if (LIGHTNING.isNeeded()) LIGHTNING.onWorldEventFlag((ServerWorld) (Object)this, blockPos, bl2?1:0);
}
@Inject(method = "onUse", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(
value = "INVOKE",
target = "Lnet/minecraft/item/ItemStack;hasTag()Z",
shift = At.Shift.BEFORE
))
private void setSboxCount(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult arg5, CallbackInfoReturnable<Boolean> cir,
ItemStack itemStack, int i, Item item, Block block, ItemStack itemStack5)
{
if (CarpetSettings.stackableShulkerBoxes)
itemStack5.setCount(itemStack.getCount());
}
@Inject(method = "createPlayer", at = @At(value = "INVOKE", shift = At.Shift.BEFORE,
target = "Ljava/util/Iterator;hasNext()Z"), locals = LocalCapture.CAPTURE_FAILHARD)
private void newWhileLoop(GameProfile gameProfile_1, CallbackInfoReturnable<ServerPlayerEntity> cir, UUID uUID_1,
List list_1, Iterator var5)
{
while (var5.hasNext())
{
ServerPlayerEntity serverPlayerEntity_3 = (ServerPlayerEntity) var5.next();
if(serverPlayerEntity_3 instanceof EntityPlayerMPFake)
{
serverPlayerEntity_3.kill();
continue;
}
serverPlayerEntity_3.networkHandler.disconnect(new TranslatableText("multiplayer.disconnect.duplicate_login"));
}
}
@Inject(method = "tickBlockEntities", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/entity/BlockEntity;isRemoved()Z",
shift = At.Shift.BEFORE,
ordinal = 0
))
private void startTileEntitySection(CallbackInfo ci, Profiler profiler_1, Iterator i, BlockEntity blockEntity_2)
{
entitySection = CarpetProfiler.start_entity_section((World)(Object)this, blockEntity_2, CarpetProfiler.TYPE.TILEENTITY);
}
@Inject(method = "move", at = @At(value = "INVOKE", shift = At.Shift.BEFORE,
target = "Lnet/minecraft/world/World;setBlockEntity(Lnet/minecraft/util/math/BlockPos;" +
"Lnet/minecraft/block/entity/BlockEntity;)V", ordinal = 0),
locals = LocalCapture.CAPTURE_FAILHARD)
private void setBlockEntityWithCarried(World world_1, BlockPos blockPos_1, Direction direction_1, boolean boolean_1,
CallbackInfoReturnable<Boolean> cir, BlockPos blockPos_2, PistonHandler pistonHandler_1, Map map_1, List list_1,
List list_2, List list_3, int int_2, BlockState[] blockStates_1, Direction direction_2,
int int_3, BlockPos blockPos_4, BlockState blockState_1)
{
BlockEntity blockEntityPiston = PistonExtensionBlock.createBlockEntityPiston((BlockState) list_2.get(int_3),
direction_1, boolean_1, false);
if (CarpetSettings.movableBlockEntities)
((PistonBlockEntityInterface) blockEntityPiston).setCarriedBlockEntity(list1_BlockEntities.get().get(int_3));
world_1.setBlockEntity(blockPos_4, blockEntityPiston);
}
@Inject(method = "tryBreakBlock", locals = LocalCapture.CAPTURE_FAILEXCEPTION, at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/Block;onBroken(Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V",
shift = At.Shift.BEFORE
))
private void onBlockBroken(BlockPos blockPos_1, CallbackInfoReturnable<Boolean> cir, BlockState blockState_1, BlockEntity be, Block b, boolean boolean_1)
{
PLAYER_BREAK_BLOCK.onBlockBroken(player, blockPos_1, blockState_1);
}
@Inject(method = "sendChatMessage(Ljava/lang/String;)V", at = @At("HEAD"),
locals = LocalCapture.CAPTURE_FAILHARD,
cancellable = true)
public void onSendChatMessage(String message, CallbackInfo ci) {
if (FabricSparkGameHooks.INSTANCE.tryProcessChat(message)) {
ci.cancel();
}
}
@Inject(method = "onSignUpdate", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/entity/SignBlockEntity;isEditable()Z"
), cancellable = true, locals = LocalCapture.CAPTURE_FAILSOFT)
private void onSignUpdate(UpdateSignC2SPacket packet, CallbackInfo ci, ServerWorld serverWorld, BlockPos blockPos, BlockState blockState, BlockEntity blockEntity, SignBlockEntity signBlockEntity) {
Main main = Main.Companion.getMain();
if (main == null) return;
if (main.getEventManager().emit(new PlayerUpdateSignEvent(packet, player, signBlockEntity)).getCancel()) {
ci.cancel();
signBlockEntity.markDirty();
serverWorld.updateListeners(blockPos, blockState, blockState, 3);
}
}
@Override
protected Injector parseInjector(AnnotationNode injectAnnotation) {
boolean cancellable = Annotations.<Boolean>getValue(injectAnnotation, "cancellable", Boolean.FALSE);
LocalCapture locals = Annotations.<LocalCapture>getValue(injectAnnotation, "locals", LocalCapture.class, LocalCapture.NO_CAPTURE);
String identifier = Annotations.<String>getValue(injectAnnotation, "id", "");
return new CallbackInjector(this, cancellable, locals, identifier);
}
@Inject(method = "onGuiActionConfirm", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/ConfirmGuiActionS2CPacket;wasAccepted()Z"), locals = LocalCapture.CAPTURE_FAILHARD)
private void onOnGuiActionConfirm(ConfirmGuiActionS2CPacket packet, CallbackInfo ci, ScreenHandler screenHandler) {
if (ConnectionInfo.protocolVersion <= Protocols.V1_11_2) {
((IScreenHandler) screenHandler).multiconnect_getRecipeBookEmulator().onConfirmTransaction(packet);
}
}
@Inject(method = "decode", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/Packet;read(Lnet/minecraft/network/PacketByteBuf;)V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
private void postDecode(ChannelHandlerContext context, ByteBuf buf, List<Object> output, CallbackInfo ci, PacketByteBuf packetBuf, int packetId, Packet<?> packet) {
if (!((TransformerByteBuf) packetBuf).canDecodeAsync(packet.getClass())) {
ConnectionInfo.resourceReloadLock.readLock().unlock();
}
}