Search in sources :

Example 6 with BlockPos

use of net.minecraft.core.BlockPos in project MinecraftForge by MinecraftForge.

the class ForgeHooksClient method renderPistonMovedBlocks.

public static void renderPistonMovedBlocks(BlockPos pos, BlockState state, PoseStack stack, MultiBufferSource buffer, Level world, boolean checkSides, int combinedOverlay, BlockRenderDispatcher blockRenderer) {
    RenderType.chunkBufferLayers().stream().filter(t -> ItemBlockRenderTypes.canRenderInLayer(state, t)).forEach(rendertype -> {
        setRenderType(rendertype);
        VertexConsumer ivertexbuilder = buffer.getBuffer(rendertype == RenderType.translucent() ? RenderType.translucentMovingBlock() : rendertype);
        blockRenderer.getModelRenderer().tesselateBlock(world, blockRenderer.getBlockModel(state), state, pos, stack, ivertexbuilder, checkSides, new Random(), state.getSeed(pos), combinedOverlay);
    });
    setRenderType(null);
}
Also used : Camera(net.minecraft.client.Camera) Font(net.minecraft.client.gui.Font) Arrays(java.util.Arrays) Connection(net.minecraft.network.Connection) ForgeMod(net.minecraftforge.common.ForgeMod) Dist(net.minecraftforge.api.distmarker.Dist) net.minecraftforge.fml(net.minecraftforge.fml) Pair(org.apache.commons.lang3.tuple.Pair) MultiPlayerGameMode(net.minecraft.client.multiplayer.MultiPlayerGameMode) Map(java.util.Map) AbstractClientPlayer(net.minecraft.client.player.AbstractClientPlayer) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) TooltipComponent(net.minecraft.world.inventory.tooltip.TooltipComponent) WorldPreset(net.minecraft.client.gui.screens.worldselection.WorldPreset) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Window(com.mojang.blaze3d.platform.Window) ForgeVersion(net.minecraftforge.versions.forge.ForgeVersion) SoundInstance(net.minecraft.client.resources.sounds.SoundInstance) Screen(net.minecraft.client.gui.screens.Screen) ResourceManager(net.minecraft.server.packs.resources.ResourceManager) Set(java.util.Set) Language(net.minecraft.locale.Language) NetworkRegistry(net.minecraftforge.network.NetworkRegistry) TextComponent(net.minecraft.network.chat.TextComponent) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) FormattedText(net.minecraft.network.chat.FormattedText) FluidState(net.minecraft.world.level.material.FluidState) ForgeI18n(net.minecraftforge.common.ForgeI18n) ItemStack(net.minecraft.world.item.ItemStack) GameType(net.minecraft.world.level.GameType) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) BETA(net.minecraftforge.fml.VersionChecker.Status.BETA) Resource(net.minecraft.server.packs.resources.Resource) WorldGenSettings(net.minecraft.world.level.levelgen.WorldGenSettings) com.mojang.blaze3d.vertex(com.mojang.blaze3d.vertex) HumanoidArm(net.minecraft.world.entity.HumanoidArm) BlockState(net.minecraft.world.level.block.state.BlockState) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) Supplier(java.util.function.Supplier) Vector3f(com.mojang.math.Vector3f) ArrayList(java.util.ArrayList) I18n(net.minecraft.client.resources.language.I18n) MouseHandler(net.minecraft.client.MouseHandler) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance) ModelManager(net.minecraft.client.resources.model.ModelManager) TitleScreen(net.minecraft.client.gui.screens.TitleScreen) Marker(org.apache.logging.log4j.Marker) Nullable(javax.annotation.Nullable) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) BlockAndTintGetter(net.minecraft.world.level.BlockAndTintGetter) ServerData(net.minecraft.client.multiplayer.ServerData) BakedModel(net.minecraft.client.resources.model.BakedModel) Transformation(com.mojang.math.Transformation) ItemTransforms(net.minecraft.client.renderer.block.model.ItemTransforms) Component(net.minecraft.network.chat.Component) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) TransformationHelper(net.minecraftforge.common.model.TransformationHelper) IOException(java.io.IOException) NarratorChatListener(net.minecraft.client.gui.chat.NarratorChatListener) File(java.io.File) ItemRenderer(net.minecraft.client.renderer.entity.ItemRenderer) LerpingBossEvent(net.minecraft.client.gui.components.LerpingBossEvent) MinecraftForge(net.minecraftforge.common.MinecraftForge) EquipmentSlot(net.minecraft.world.entity.EquipmentSlot) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) ClientTooltipComponent(net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent) InteractionHand(net.minecraft.world.InteractionHand) Material(net.minecraft.client.resources.model.Material) net.minecraftforge.client.event(net.minecraftforge.client.event) ResourceLocation(net.minecraft.resources.ResourceLocation) Either(com.mojang.datafixers.util.Either) LivingEntity(net.minecraft.world.entity.LivingEntity) TextureAtlas(net.minecraft.client.renderer.texture.TextureAtlas) Direction(net.minecraft.core.Direction) Matrix4f(com.mojang.math.Matrix4f) Random(java.util.Random) ServerStatus(net.minecraft.network.protocol.status.ServerStatus) ForgeTextureMetadata(net.minecraftforge.client.textures.ForgeTextureMetadata) GameData(net.minecraftforge.registries.GameData) ChatFormatting(net.minecraft.ChatFormatting) BETA_OUTDATED(net.minecraftforge.fml.VersionChecker.Status.BETA_OUTDATED) FogMode(net.minecraft.client.renderer.FogRenderer.FogMode) Event(net.minecraftforge.eventbus.api.Event) Input(net.minecraft.client.player.Input) ImmutableMap(com.google.common.collect.ImmutableMap) BlockHitResult(net.minecraft.world.phys.BlockHitResult) Matrix3f(com.mojang.math.Matrix3f) Collectors(java.util.stream.Collectors) Player(net.minecraft.world.entity.player.Player) Objects(java.util.Objects) MarkerManager(org.apache.logging.log4j.MarkerManager) List(java.util.List) RecipeManager(net.minecraft.world.item.crafting.RecipeManager) BlockPos(net.minecraft.core.BlockPos) Optional(java.util.Optional) BOSSINFO(net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType.BOSSINFO) Level(net.minecraft.world.level.Level) net.minecraft.client.renderer(net.minecraft.client.renderer) PlayerInfo(net.minecraft.client.multiplayer.PlayerInfo) GuiComponent(net.minecraft.client.gui.GuiComponent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) SoundEngine(net.minecraft.client.sounds.SoundEngine) PlaySoundEvent(net.minecraftforge.client.event.sound.PlaySoundEvent) Function(java.util.function.Function) Stack(java.util.Stack) ItemColors(net.minecraft.client.color.item.ItemColors) BlockRenderDispatcher(net.minecraft.client.renderer.block.BlockRenderDispatcher) ParticleRenderType(net.minecraft.client.particle.ParticleRenderType) Minecraft(net.minecraft.client.Minecraft) JoinMultiplayerScreen(net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen) Fluid(net.minecraft.world.level.material.Fluid) Mod(net.minecraftforge.fml.common.Mod) HumanoidModel(net.minecraft.client.model.HumanoidModel) NativeImage(com.mojang.blaze3d.platform.NativeImage) Nonnull(javax.annotation.Nonnull) EntityHitResult(net.minecraft.world.phys.EntityHitResult) NetworkConstants(net.minecraftforge.network.NetworkConstants) LayerDefinition(net.minecraft.client.model.geom.builders.LayerDefinition) LocalPlayer(net.minecraft.client.player.LocalPlayer) ModelLayerLocation(net.minecraft.client.model.geom.ModelLayerLocation) HitResult(net.minecraft.world.phys.HitResult) Entity(net.minecraft.world.entity.Entity) Model(net.minecraft.client.model.Model) BlockColors(net.minecraft.client.color.block.BlockColors) KeyMapping(net.minecraft.client.KeyMapping) Comparator(java.util.Comparator) LogManager(org.apache.logging.log4j.LogManager) ForgeModelBakery(net.minecraftforge.client.model.ForgeModelBakery) Random(java.util.Random)

Example 7 with BlockPos

use of net.minecraft.core.BlockPos in project MinecraftForge by MinecraftForge.

the class GameTestTest method generateTests.

/**
 * An example game test generator.
 * <p>
 * A <b>game test generator</b> generates a collection of test functions.
 * It is called immediately when registered to GameTestRegistry.
 * <p><ul>
 * <li>Must return {@code Collection<TestFunction>} (or a subclass)</li>
 * <li>Must take no parameters</li>
 * <li>Can be {@code static} or non-static</li>
 * <p>
 * WARNING: If made non-static, then it will create an instance of the class every time it is run.</li>
 * </ul>
 */
@GameTestGenerator
public static List<TestFunction> generateTests() {
    // An example test function, run in the default batch, with the test name "teststone", and the structure name "gametesttest.teststone" under the "gametest_test" namespace.
    // No rotation, 100 ticks until the test times out if it does not fail or succeed, 0 ticks for setup time, and the actual code to run.
    TestFunction testStone = new TestFunction("defaultBatch", "teststone", new ResourceLocation(MODID, "gametesttest.teststone").toString(), Rotation.NONE, 100, 0, true, helper -> {
        BlockPos stonePos = new BlockPos(1, 1, 1);
        // This should always assert to true, since we set it then directly check it
        helper.setBlock(stonePos, Blocks.STONE);
        helper.assertBlockState(stonePos, b -> b.is(Blocks.STONE), () -> "Block was not stone");
        helper.succeed();
    });
    return List.of(testStone);
}
Also used : TestFunction(net.minecraft.gametest.framework.TestFunction) ResourceLocation(net.minecraft.resources.ResourceLocation) BlockPos(net.minecraft.core.BlockPos) GameTestGenerator(net.minecraft.gametest.framework.GameTestGenerator)

Example 8 with BlockPos

use of net.minecraft.core.BlockPos in project MinecraftForge by MinecraftForge.

the class PistonEventTest method pistonPre.

@SubscribeEvent
public static void pistonPre(PistonEvent.Pre event) {
    if (event.getPistonMoveType() == PistonMoveType.EXTEND) {
        Level world = (Level) event.getWorld();
        PistonStructureResolver pistonHelper = event.getStructureHelper();
        Player player = DistExecutor.safeCallWhenOn(Dist.CLIENT, () -> () -> Minecraft.getInstance().player);
        if (world.isClientSide && player != null) {
            if (pistonHelper.resolve()) {
                player.sendMessage(new TextComponent(String.format(Locale.ENGLISH, "Piston will extend moving %d blocks and destroy %d blocks", pistonHelper.getToPush().size(), pistonHelper.getToDestroy().size())), player.getUUID());
            } else {
                player.sendMessage(new TextComponent("Piston won't extend"), player.getUUID());
            }
        }
        if (pistonHelper.resolve()) {
            List<BlockPos> posList = pistonHelper.getToPush();
            for (BlockPos newPos : posList) {
                BlockState state = event.getWorld().getBlockState(newPos);
                if (state.getBlock() == Blocks.BLACK_WOOL) {
                    Block.dropResources(state, world, newPos);
                    world.setBlockAndUpdate(newPos, Blocks.AIR.defaultBlockState());
                }
            }
        }
        // Make the block move up and out of the way so long as it won't replace the piston
        BlockPos pushedBlockPos = event.getFaceOffsetPos();
        if (world.getBlockState(pushedBlockPos).getBlock() == shiftOnMove.get() && event.getDirection() != Direction.DOWN) {
            world.setBlockAndUpdate(pushedBlockPos, Blocks.AIR.defaultBlockState());
            world.setBlockAndUpdate(pushedBlockPos.above(), shiftOnMove.get().defaultBlockState());
        }
        // Block pushing cobblestone (directly, indirectly works)
        event.setCanceled(event.getWorld().getBlockState(event.getFaceOffsetPos()).getBlock() == Blocks.COBBLESTONE);
    } else {
        boolean isSticky = event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.STICKY_PISTON;
        Player player = DistExecutor.safeCallWhenOn(Dist.CLIENT, () -> () -> Minecraft.getInstance().player);
        if (event.getWorld().isClientSide() && player != null) {
            if (isSticky) {
                BlockPos targetPos = event.getFaceOffsetPos().relative(event.getDirection());
                boolean canPush = PistonBaseBlock.isPushable(event.getWorld().getBlockState(targetPos), (Level) event.getWorld(), event.getFaceOffsetPos(), event.getDirection().getOpposite(), false, event.getDirection());
                boolean isAir = event.getWorld().isEmptyBlock(targetPos);
                player.sendMessage(new TextComponent(String.format(Locale.ENGLISH, "Piston will retract moving %d blocks", !isAir && canPush ? 1 : 0)), player.getUUID());
            } else {
                player.sendMessage(new TextComponent("Piston will retract"), player.getUUID());
            }
        }
        // Offset twice to see if retraction will pull cobblestone
        event.setCanceled(event.getWorld().getBlockState(event.getFaceOffsetPos().relative(event.getDirection())).getBlock() == Blocks.COBBLESTONE && isSticky);
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) Player(net.minecraft.world.entity.player.Player) BlockState(net.minecraft.world.level.block.state.BlockState) PistonStructureResolver(net.minecraft.world.level.block.piston.PistonStructureResolver) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 9 with BlockPos

use of net.minecraft.core.BlockPos in project Denizen-For-Bukkit by DenizenScript.

the class BlockHelperImpl method doRandomTick.

@Override
public void doRandomTick(Location location) {
    BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    LevelChunk nmsChunk = ((CraftChunk) location.getChunk()).getHandle();
    net.minecraft.world.level.block.state.BlockState nmsBlock = nmsChunk.getBlockState(pos);
    ServerLevel nmsWorld = ((CraftWorld) location.getWorld()).getHandle();
    if (nmsBlock.isRandomlyTicking()) {
        nmsBlock.randomTick(nmsWorld, pos, nmsWorld.random);
    }
    try {
        // FluidState fluid = nmsBlock.getFluidState();
        // if (fluid.isRandomlyTicking()) {
        // fluid.animateTick(nmsWorld, pos, nmsWorld.random);
        // }
        Object fluid = BLOCKSTATEBASE_GETFLUIDSTATE.invoke(nmsBlock);
        if ((boolean) FLUIDSTATE_ISRANDOMLYTICKING.invoke(fluid)) {
            FLUIDSTATE_ANIMATETICK.invoke(fluid, nmsWorld, pos, nmsWorld.random);
        }
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) BlockPos(net.minecraft.core.BlockPos) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_17_R1.CraftChunk)

Example 10 with BlockPos

use of net.minecraft.core.BlockPos in project Denizen-For-Bukkit by DenizenScript.

the class BlockHelperImpl method getNbtData.

@Override
public CompoundTag getNbtData(Block block) {
    BlockEntity te = ((CraftWorld) block.getWorld()).getHandle().getTileEntity(new BlockPos(block.getX(), block.getY(), block.getZ()), true);
    if (te != null) {
        net.minecraft.nbt.CompoundTag compound = new net.minecraft.nbt.CompoundTag();
        te.save(compound);
        return CompoundTagImpl.fromNMSTag(compound);
    }
    return null;
}
Also used : BlockPos(net.minecraft.core.BlockPos) CompoundTag(com.denizenscript.denizen.nms.util.jnbt.CompoundTag) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Aggregations

BlockPos (net.minecraft.core.BlockPos)54 BlockState (net.minecraft.world.level.block.state.BlockState)10 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)8 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)8 Level (net.minecraft.world.level.Level)7 Direction (net.minecraft.core.Direction)6 Vec3 (net.minecraft.world.phys.Vec3)6 Nonnull (javax.annotation.Nonnull)5 ResourceLocation (net.minecraft.resources.ResourceLocation)5 ItemStack (net.minecraft.world.item.ItemStack)5 LocationTag (com.denizenscript.denizen.objects.LocationTag)4 ChunkCoordinate (com.denizenscript.denizen.utilities.blocks.ChunkCoordinate)4 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)4 Nullable (javax.annotation.Nullable)3 GameTest (net.minecraft.gametest.framework.GameTest)3 ChunkPos (net.minecraft.world.level.ChunkPos)3 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)3 BlockLight (com.denizenscript.denizen.nms.abstracts.BlockLight)2 CompoundTagBuilder (com.denizenscript.denizen.nms.util.jnbt.CompoundTagBuilder)2 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)2