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();
}
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);
}
}
}
}
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);
}
}
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);
}
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);
}
Aggregations