net.minecraftforge.api.distmarker.Dist Java Examples

The following examples show how to use net.minecraftforge.api.distmarker.Dist. 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: CustomParticleHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public static void addLandingEffects(World world, BlockPos pos, BlockState state, Vector3 entityPos, int numParticles) {
    //Spoof a raytrace from the feet.
    BlockRayTraceResult traceResult = new BlockRayTraceResult(new Vec3d(entityPos.x, pos.getY() + 1, entityPos.z), Direction.UP, pos, false);
    ParticleManager manager = Minecraft.getInstance().particles;
    Random randy = new Random();
    BlockModelShapes modelShapes = Minecraft.getInstance().getBlockRendererDispatcher().getBlockModelShapes();
    IBakedModel model = modelShapes.getModel(state);
    if (model instanceof IModelParticleProvider) {
        IModelData modelData = ModelDataManager.getModelData(world, pos);
        List<TextureAtlasSprite> sprites = new ArrayList<>(((IModelParticleProvider) model).getHitEffects(traceResult, state, world, pos, modelData));

        double speed = 0.15000000596046448D;
        if (numParticles != 0) {
            for (int i = 0; i < numParticles; i++) {
                double mX = randy.nextGaussian() * speed;
                double mY = randy.nextGaussian() * speed;
                double mZ = randy.nextGaussian() * speed;
                manager.addEffect(CustomBreakingParticle.newLandingParticle(world, entityPos.x, entityPos.y, entityPos.z, mX, mY, mZ, sprites.get(randy.nextInt(sprites.size()))));
            }
        }
    }
}
 
Example #2
Source File: CustomParticleHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public static boolean handleRunningEffects(World world, BlockPos pos, BlockState state, Entity entity) {
    //Spoof a raytrace from the feet.
    BlockRayTraceResult traceResult = new BlockRayTraceResult(entity.getPositionVec().add(0, 1, 0), Direction.UP, pos, false);
    BlockModelShapes modelShapes = Minecraft.getInstance().getBlockRendererDispatcher().getBlockModelShapes();
    IBakedModel model = modelShapes.getModel(state);
    if (model instanceof IModelParticleProvider) {
        IModelData modelData = ModelDataManager.getModelData(world, pos);
        ParticleManager particleManager = Minecraft.getInstance().particles;
        List<TextureAtlasSprite> sprites = new ArrayList<>(((IModelParticleProvider) model).getHitEffects(traceResult, state, world, pos, modelData));
        TextureAtlasSprite rolledSprite = sprites.get(world.rand.nextInt(sprites.size()));
        double x = entity.getPosX() + (world.rand.nextFloat() - 0.5D) * entity.getWidth();
        double y = entity.getBoundingBox().minY + 0.1D;
        double z = entity.getPosZ() + (world.rand.nextFloat() - 0.5D) * entity.getWidth();
        particleManager.addEffect(new CustomBreakingParticle(world, x, y, z, -entity.getMotion().x * 4.0D, 1.5D, -entity.getMotion().z * 4.0D, rolledSprite));
        return true;
    }

    return false;
}
 
Example #3
Source File: CCRenderEventHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@OnlyIn (Dist.CLIENT)
@SubscribeEvent (priority = EventPriority.LOW)
public void onBlockHighlight(DrawHighlightEvent.HighlightBlock event) {
    //We have found a CuboidRayTraceResult, Lets render it properly..
    BlockRayTraceResult hit = event.getTarget();
    if (hit instanceof CuboidRayTraceResult) {
        CuboidRayTraceResult cuboidHit = (CuboidRayTraceResult) hit;
        event.setCanceled(true);
        Matrix4 mat = new Matrix4(event.getMatrix());
        mat.translate(cuboidHit.getPos());
        RenderUtils.bufferHitbox(mat, event.getBuffers(), event.getInfo(), cuboidHit.cuboid6);
    }
}
 
Example #4
Source File: GuiOverlay.java    From XRay-Mod with GNU General Public License v3.0 5 votes vote down vote up
@OnlyIn(Dist.CLIENT)
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void RenderGameOverlayEvent(RenderGameOverlayEvent event) {
    // Draw Indicator
    if(!Controller.isXRayActive() || !Configuration.general.showOverlay.get() || event.isCanceled() || event.getType() != RenderGameOverlayEvent.ElementType.TEXT )
        return;

    RenderSystem.color3f(0, 255, 0);
    XRay.mc.getTextureManager().bindTexture(circle);
    Screen.func_238463_a_(event.getMatrixStack(), 5, 5, 0f, 0f, 5, 5, 5, 5); // @mcp: func_238463_a_ = blit (7 parms) =

    // @mcp: func_238405_a_ = drawStringWithShadow
    XRay.mc.fontRenderer.func_238405_a_(event.getMatrixStack(), I18n.format("xray.overlay"), 15, 4, 0xffffffff);
}
 
Example #5
Source File: CodeChickenLib.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public CodeChickenLib() {
    proxy = DistExecutor.runForDist(() -> ProxyClient::new, () -> Proxy::new);
    FMLJavaModLoadingContext.get().getModEventBus().register(this);
    DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(OpenGLUtils::onModelRegistryEvent);
    });
}
 
Example #6
Source File: DistExecutor.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Run the callable in the supplier only on the specified {@link Dist}.
 *
 * @param dist  The {@link Dist} to run on
 * @param toRun A {@link Supplier} of the {@link Callable} to run ({@link Supplier} wrapper to ensure classloading only on the appropriate dist)
 * @param <T>   The return type from the {@link Callable}
 * @return The {@link Callable}'s result
 */
public static <T> T callWhenOn(Dist dist, Supplier<Callable<T>> toRun) {
	if (dist == FMLEnvironment.dist) {
		try {
			return toRun.get().call();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	return null;
}
 
Example #7
Source File: BlockRenderingRegistry.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public static void init() {
    if (!initialized) {
        Minecraft mc = Minecraft.getInstance();
        BlockRendererDispatcher parentDispatcher = mc.getBlockRendererDispatcher();
        mc.blockRenderDispatcher = new CCBlockRendererDispatcher(parentDispatcher, mc.getBlockColors());
        initialized = true;
    }
}
 
Example #8
Source File: CustomParticleHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public static void addBlockHitEffects(World world, Cuboid6 bounds, Direction side, TextureAtlasSprite icon, ParticleManager particleManager) {
    float border = 0.1F;
    Vector3 diff = bounds.max.copy().subtract(bounds.min).add(-2 * border);
    diff.x *= world.rand.nextDouble();
    diff.y *= world.rand.nextDouble();
    diff.z *= world.rand.nextDouble();
    Vector3 pos = diff.add(bounds.min).add(border);

    if (side == Direction.DOWN) {
        diff.y = bounds.min.y - border;
    }
    if (side == Direction.UP) {
        diff.y = bounds.max.y + border;
    }
    if (side == Direction.NORTH) {
        diff.z = bounds.min.z - border;
    }
    if (side == Direction.SOUTH) {
        diff.z = bounds.max.z + border;
    }
    if (side == Direction.WEST) {
        diff.x = bounds.min.x - border;
    }
    if (side == Direction.EAST) {
        diff.x = bounds.max.x + border;
    }

    particleManager.addEffect(new CustomBreakingParticle(world, pos.x, pos.y, pos.z, 0, 0, 0, icon).multiplyVelocity(0.2F).multipleParticleScaleBy(0.6F));
}
 
Example #9
Source File: CustomParticleHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@link Block#addHitEffects}
 * Provided the model bound is an instance of IModelParticleProvider, you will have landing particles just handled for you.
 * Use the default PerspectiveModel implementations inside CCL, Destroy effects will just be handled for you.
 *
 * @param world   The world.
 * @param pos     The position of the block.
 * @param manager The ParticleManager.
 * @return True if particles were added, basically just return the result of this method inside {@link Block#addHitEffects}
 */
@OnlyIn (Dist.CLIENT)
public static boolean handleDestroyEffects(World world, BlockPos pos, BlockState state, ParticleManager manager) {
    BlockModelShapes modelShapes = Minecraft.getInstance().getBlockRendererDispatcher().getBlockModelShapes();
    IBakedModel model = modelShapes.getModel(state);
    if (model instanceof IModelParticleProvider) {
        IModelData modelData = ModelDataManager.getModelData(world, pos);
        Cuboid6 bounds = new Cuboid6(state.getShape(world, pos).getBoundingBox());
        addBlockDestroyEffects(world, bounds.add(pos), new ArrayList<>(((IModelParticleProvider) model).getDestroyEffects(state, world, pos, modelData)), manager);
        return true;
    }
    return false;
}
 
Example #10
Source File: MiningGadget.java    From MiningGadgets with MIT License 5 votes vote down vote up
@OnlyIn(Dist.CLIENT)
public void playLoopSound(LivingEntity player, ItemStack stack) {
    float volume = MiningProperties.getVolume(stack);
    PlayerEntity myplayer = Minecraft.getInstance().player;
    if (myplayer.equals(player)) {
        if (volume != 0.0f) {
            if (laserLoopSound == null) {
                laserLoopSound = new LaserLoopSound((PlayerEntity) player, volume);
                Minecraft.getInstance().getSoundHandler().play(laserLoopSound);
            }
        }
    }
}
 
Example #11
Source File: PatchworkFML.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void onInitialize() {
	ServerStartCallback.EVENT.register(server -> LogicalSidedProvider.setServer(() -> server));
	ServerStopCallback.EVENT.register(server -> LogicalSidedProvider.setServer(null));

	Object instance = FabricLoader.getInstance().getGameInstance();

	DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> LogicalSidedProvider.setClient(() -> (MinecraftClient) instance));
	DistExecutor.runWhenOn(Dist.DEDICATED_SERVER, () -> () -> LogicalSidedProvider.setServer(() -> (MinecraftServer) instance));
}
 
Example #12
Source File: Colour.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public void glColour() {
    RenderSystem.color4f((r & 0xFF) / 255F, (g & 0xFF) / 255F, (b & 0xFF) / 255F, (a & 0xFF) / 255F);
}
 
Example #13
Source File: DistExecutor.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void runWhenOn(Dist dist, Supplier<Runnable> toRun) {
	if (dist == FMLEnvironment.dist) {
		toRun.get().run();
	}
}
 
Example #14
Source File: PacketPipeline.java    From Better-Sprinting with Mozilla Public License 2.0 4 votes vote down vote up
@OnlyIn(Dist.CLIENT)
private PlayerEntity getClientPlayer(){
	return Minecraft.getInstance().player;
}
 
Example #15
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public static void sendToServer(IPacket<?> packet) {
    Minecraft.getInstance().getConnection().sendPacket(packet);
}
 
Example #16
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public void sendToServer() {
    sendToServer(toPacket(NetworkDirection.PLAY_TO_SERVER));
}
 
Example #17
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public static PacketCustom fromTilePacket(SUpdateTileEntityPacket tilePacket) {
    return fromNBTTag(tilePacket.getNbtCompound());
}
 
Example #18
Source File: RayTracer.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@OnlyIn (Dist.CLIENT)
private static double getBlockReachDistance_client() {
    return Minecraft.getInstance().playerController.getBlockReachDistance();
}
 
Example #19
Source File: Vector3.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public Vector4f vector4f() {
    return new Vector4f((float) x, (float) y, (float) z, 1);
}
 
Example #20
Source File: PacketDurabilitySync.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static void handle(PacketDurabilitySync msg, Supplier<NetworkEvent.Context> ctx) {
    ctx.get().enqueueWork(() -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> clientPacketHandler(msg)));
    ctx.get().setPacketHandled(true);
}
 
Example #21
Source File: RenderBlock.java    From MiningGadgets with MIT License 4 votes vote down vote up
@Override
@OnlyIn(Dist.CLIENT)
public float getAmbientOcclusionLightValue(BlockState state, IBlockReader worldIn, BlockPos pos) {
    return 1.0f;
}
 
Example #22
Source File: ICustomParticleBlock.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
@OnlyIn (Dist.CLIENT)
default boolean addDestroyEffects(BlockState state, World world, BlockPos pos, ParticleManager manager) {
    return CustomParticleHandler.handleDestroyEffects(world, pos, state, manager);
}
 
Example #23
Source File: ICustomParticleBlock.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
@OnlyIn (Dist.CLIENT)
default boolean addHitEffects(BlockState state, World worldObj, RayTraceResult target, ParticleManager manager) {
    return CustomParticleHandler.handleHitEffects(state, worldObj, target, manager);
}
 
Example #24
Source File: ICustomParticleBlock.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
@OnlyIn (Dist.CLIENT)
default boolean addRunningEffects(BlockState state, World world, BlockPos pos, Entity entity) {
    return world.isRemote && CustomParticleHandler.handleRunningEffects(world, pos, state, entity);
}
 
Example #25
Source File: ItemEnderPouch.java    From EnderStorage with MIT License 4 votes vote down vote up
@Override
@OnlyIn (Dist.CLIENT)
public IBakery getBakery() {
    return EnderPouchBakery.INSTANCE;
}
 
Example #26
Source File: Colour.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public void glColour(int a) {
    RenderSystem.color4f((r & 0xFF) / 255F, (g & 0xFF) / 255F, (b & 0xFF) / 255F, a / 255F);
}
 
Example #27
Source File: PacketCustomChannelBuilder.java    From CodeChickenLib with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Register a double Supplier, to construct the {@link IClientPacketHandler} for the client side.
 * The double Supplier is used to avoid class loading issues on the server side, you do NOT
 * need any external sided checks if you call using the following example:
 * <br/>
 * <code>builder.assignClientHandler(() -> ClientPacketHandler::new);</code>
 * <p/>
 *
 * @param clientHandler The Supplier.
 * @return The same builder.
 */
public PacketCustomChannelBuilder assignClientHandler(Supplier<Supplier<IClientPacketHandler>> clientHandler) {
    if (FMLEnvironment.dist == Dist.CLIENT) {
        this.clientHandler = clientHandler.get().get();
    }
    return this;
}
 
Example #28
Source File: ILayeredBlockBakery.java    From CodeChickenLib with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Used to actually generate quads for your block based on the face and layer being requested.
 * Use {@link Block#canRenderInLayer(IBlockState, BlockRenderLayer)} to cull layers from this.
 * You will ONLY be requested for quads if canRenderInLayer returns true for the specific layer.
 * <p>
 * Face may be null!!
 * Treat a null face as "general" quads, Quads that will NOT be culled by neighboring blocks.
 * <p>
 * Each layer you agree to with canRenderInLayer will be requested for "general" AND face quads.
 *
 * @param face  The face quads are requested for.
 * @param layer The layer quads are requested for.
 * @param state The IExtendedBlockState of your block. {@link IBlockBakery#handleState(IExtendedBlockState, IBlockAccess, BlockPos)} has already been called.
 * @return The quads for the layer, May be an empty list. Never null.
 */
@Nonnull
@OnlyIn (Dist.CLIENT)
List<BakedQuad> bakeLayerFace(@Nullable Direction face, RenderType layer, BlockState state, IModelData data);
 
Example #29
Source File: ISimpleBlockBakery.java    From CodeChickenLib with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Used to actually generate quads for your block. Using this interface it is assumed that you only wish to render on one specific layer.
 * If you want to render on multiple layers use {@link ILayeredBlockBakery}
 *
 * Face may be null!!
 * Treat a null face as "general" quads, Quads that will NOT be culled by neighboring blocks.
 *
 * You will be requested for "general" AND face quads.
 *
 * @param face  The face quads are requested for.
 * @param state The IExtendedBlockState of your block. {@link IBlockBakery#handleState(IExtendedBlockState, IBlockAccess, BlockPos)} has already been called.
 * @return The quads for the face, May be an empty list. Never null.
 */
@Nonnull
@OnlyIn (Dist.CLIENT)
List<BakedQuad> bakeQuads(@Nullable Direction face, BlockState state, IModelData data);
 
Example #30
Source File: IItemBakery.java    From CodeChickenLib with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Used to actually generate quads for your ItemStack based on the face being requested.
 *
 * Face may be null!
 * Treat a null face as "general" quads, Item Rendering doesn't have any sense of "faces" this is more so a fall over
 * of blocks having face quads. It is fine to have all your quads in the "general" face, but Recommended against for debugging.
 *
 * @param face  The face quads are requested for.
 * @param stack The stack!
 * @return The quads for the layer, May be an empty list. Never null.
 */
@Nonnull
@OnlyIn (Dist.CLIENT)
List<BakedQuad> bakeItemQuads(@Nullable Direction face, ItemStack stack);