Search in sources :

Example 26 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project AgriCraft by AgriCraft.

the class MagnifyingGlassViewHandler method inspectionRender.

@SubscribeEvent
@SuppressWarnings("unused")
public void inspectionRender(RenderWorldLastEvent event) {
    // Check if the player is in first person
    if (!Minecraft.getInstance().gameSettings.getPointOfView().func_243192_a()) {
        return;
    }
    // Check if an inspection renderer is present and cache it (another thread might set it to null)
    IMagnifyingGlassInspector inspector = this.inspector;
    if (inspector == null) {
        return;
    }
    // Check if the inspector has a target and cache (another thread might set it to null)
    Target target = this.lastTarget;
    if (target == null) {
        return;
    }
    // Fetch and push matrix to the matrix stack
    MatrixStack transforms = event.getMatrixStack();
    transforms.push();
    // Correct for render view
    Vector3d projectedView = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView();
    transforms.translate(-projectedView.x, -projectedView.y, -projectedView.z);
    // Move to the player's eye position
    Vector3d eyes = this.getPlayer().getEyePosition(event.getPartialTicks());
    transforms.translate(eyes.getX(), eyes.getY(), eyes.getZ());
    // Fetch the player's target
    Vector3d hit = target.getTargetVector(event.getPartialTicks());
    Vector3d view = hit.subtract(eyes).normalize();
    // Translate offset
    transforms.translate(GENOME_OFFSET * view.getX(), GENOME_OFFSET * view.getY(), GENOME_OFFSET * view.getZ());
    // Fetch player look orientation;
    float yaw = (float) (Math.PI * this.getPlayer().getYaw(event.getPartialTicks())) / 180;
    float pitch = (float) (Math.PI * this.getPlayer().getPitch(event.getPartialTicks())) / 180;
    // Rotate for yaw
    transforms.rotate(Vector3f.YP.rotation(-yaw));
    // Render
    transforms.push();
    inspector.doInspectionRender(transforms, event.getPartialTicks(), target.getTargetEntity());
    transforms.pop();
    // Pop last transformation matrix from the stack
    transforms.pop();
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) IMagnifyingGlassInspector(com.infinityraider.agricraft.api.v1.client.IMagnifyingGlassInspector) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 27 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project BluePower by Qmunity.

the class BPEventHandler method blockHighlightEvent.

@OnlyIn(Dist.CLIENT)
@SubscribeEvent
public void blockHighlightEvent(DrawHighlightEvent event) {
    PlayerEntity player = Minecraft.getInstance().player;
    if (player == null) {
        return;
    }
    World world = player.level;
    if (world == null) {
        return;
    }
    RayTraceResult mop = event.getTarget();
    if (mop instanceof BlockRayTraceResult) {
        BlockPos pos = ((BlockRayTraceResult) mop).getBlockPos();
        BlockState state = world.getBlockState(pos);
        if (state.getBlock() instanceof BlockBPMultipart) {
            BlockState partstate = MultipartUtils.getClosestState(player, pos);
            IVertexBuilder builder = event.getBuffers().getBuffer(RenderType.lines());
            if (partstate != null) {
                VoxelShape shape = partstate.getShape(world, pos, ISelectionContext.of(player));
                Vector3d projectedView = event.getInfo().getPosition();
                double d0 = pos.getX() - projectedView.x();
                double d1 = pos.getY() - projectedView.y();
                double d2 = pos.getZ() - projectedView.z();
                Matrix4f matrix4f = event.getMatrix().last().pose();
                shape.forAllEdges((startX, startY, startZ, endX, endY, endZ) -> {
                    builder.vertex(matrix4f, (float) (startX + d0), (float) (startY + d1), (float) (startZ + d2)).color(0.0F, 0.0F, 0.0F, 0.4F).endVertex();
                    builder.vertex(matrix4f, (float) (endX + d0), (float) (endY + d1), (float) (endZ + d2)).color(0.0F, 0.0F, 0.0F, 0.4F).endVertex();
                });
                event.setCanceled(true);
            }
        }
    }
}
Also used : Matrix4f(net.minecraft.util.math.vector.Matrix4f) BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) Vector3d(net.minecraft.util.math.vector.Vector3d) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) BlockBPMultipart(com.bluepowermod.block.BlockBPMultipart) BlockPos(net.minecraft.util.math.BlockPos) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) World(net.minecraft.world.World) PlayerEntity(net.minecraft.entity.player.PlayerEntity) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 28 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project BluePower by Qmunity.

the class WorldGenFlowers method onBiomeLoad.

@SubscribeEvent
public void onBiomeLoad(BiomeLoadingEvent event) {
    int n = getConfigAmount(event.getName());
    if (n > 0) {
        BiomeGenerationSettingsBuilder generation = event.getGeneration();
        ConfiguredFeature<?, ?> feature = WorldGenRegistries.CONFIGURED_FEATURE.get(new ResourceLocation("bluepower:" + Refs.INDIGOFLOWER_NAME + n));
        if (feature != null)
            generation.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, feature);
    }
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) BiomeGenerationSettingsBuilder(net.minecraftforge.common.world.BiomeGenerationSettingsBuilder) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 29 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project BluePower by Qmunity.

the class Renderers method onModelBakeEvent.

@SubscribeEvent
public void onModelBakeEvent(ModelBakeEvent event) {
    // Register Multipart Model
    BPMultipartModel multipartModel = new BPMultipartModel();
    event.getModelRegistry().put(new ModelResourceLocation("bluepower:multipart", "waterlogged=false"), multipartModel);
    event.getModelRegistry().put(new ModelResourceLocation("bluepower:multipart", "waterlogged=true"), multipartModel);
    BPMicroblockModel microblockModel = new BPMicroblockModel();
    for (Direction dir : Direction.values()) {
        // Register Microblock Models
        event.getModelRegistry().put(new ModelResourceLocation("bluepower:half_block", "face=" + dir.getName()), event.getModelRegistry().get(new ModelResourceLocation("bluepower:half_block", "facing=" + dir.getName() + ",waterlogged=true")));
        event.getModelRegistry().put(new ModelResourceLocation("bluepower:half_block", "facing=" + dir.getName() + ",waterlogged=true"), microblockModel);
        event.getModelRegistry().put(new ModelResourceLocation("bluepower:half_block", "facing=" + dir.getName() + ",waterlogged=false"), microblockModel);
        event.getModelRegistry().put(new ModelResourceLocation("bluepower:panel", "face=" + dir.getName()), event.getModelRegistry().get(new ModelResourceLocation("bluepower:panel", "facing=" + dir.getName() + ",waterlogged=true")));
        event.getModelRegistry().put(new ModelResourceLocation("bluepower:panel", "facing=" + dir.getName() + ",waterlogged=true"), microblockModel);
        event.getModelRegistry().put(new ModelResourceLocation("bluepower:panel", "facing=" + dir.getName() + ",waterlogged=false"), microblockModel);
        event.getModelRegistry().put(new ModelResourceLocation("bluepower:cover", "face=" + dir.getName()), event.getModelRegistry().get(new ModelResourceLocation("bluepower:cover", "facing=" + dir.getName() + ",waterlogged=true")));
        event.getModelRegistry().put(new ModelResourceLocation("bluepower:cover", "facing=" + dir.getName() + ",waterlogged=true"), microblockModel);
        event.getModelRegistry().put(new ModelResourceLocation("bluepower:cover", "facing=" + dir.getName() + ",waterlogged=false"), microblockModel);
    }
    event.getModelRegistry().put(new ModelResourceLocation("bluepower:half_block", "inventory"), microblockModel);
    event.getModelRegistry().put(new ModelResourceLocation("bluepower:panel", "inventory"), microblockModel);
    event.getModelRegistry().put(new ModelResourceLocation("bluepower:cover", "inventory"), microblockModel);
}
Also used : Direction(net.minecraft.util.Direction) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 30 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project Geolosys by oitsjustjose.

the class Geolosys method attachCap.

@SubscribeEvent
public void attachCap(AttachCapabilitiesEvent<World> event) {
    event.addCapability(new ResourceLocation(Constants.MODID, "pluton"), new DepositCapProvider());
    String dimName = event.getObject().getDimensionKey().getLocation().toString();
    LOGGER.info("Geolosys capability attached for {}", dimName);
}
Also used : DepositCapProvider(com.oitsjustjose.geolosys.common.world.capability.DepositCapProvider) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)87 PlayerEntity (net.minecraft.entity.player.PlayerEntity)18 ItemStack (net.minecraft.item.ItemStack)17 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)11 ResourceLocation (net.minecraft.util.ResourceLocation)10 World (net.minecraft.world.World)8 Player (net.minecraft.world.entity.player.Player)8 BlockPos (net.minecraft.util.math.BlockPos)7 Entity (net.minecraft.world.entity.Entity)7 ItemStack (net.minecraft.world.item.ItemStack)7 CompoundNBT (net.minecraft.nbt.CompoundNBT)6 Minecraft (net.minecraft.client.Minecraft)5 BlockPos (net.minecraft.core.BlockPos)5 ServerPlayer (net.minecraft.server.level.ServerPlayer)5 StringTextComponent (net.minecraft.util.text.StringTextComponent)5 Item (net.minecraft.world.item.Item)5 BlockItem (net.minecraft.item.BlockItem)4 ResourceLocation (net.minecraft.resources.ResourceLocation)4 BlockState (net.minecraft.world.level.block.state.BlockState)4 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)4