Search in sources :

Example 46 with BlockPos

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

the class ChunkGenWorker method doWork.

@Override
public boolean doWork() {
    /* TODO: Check how many things are pending save, and slow down world gen if to many
        AnvilChunkLoader loader = dim.getChunkProvider().chunkLoader instanceof AnvilChunkLoader ? (AnvilChunkLoader)world.getChunkProvider().chunkLoader : null;
        if (loader != null && loader.getPendingSaveCount() > 100)
        {

            if (lastNotifcationTime < System.currentTimeMillis() - 10*1000)
            {
                listener.sendFeedback(new TranslationTextComponent("commands.forge.gen.progress", total - queue.size(), total), true);
                lastNotifcationTime = System.currentTimeMillis();
            }
            return false;
        }
        */
    BlockPos next = queue.poll();
    if (next != null) {
        if (++lastNotification >= notificationFrequency || lastNotifcationTime < System.currentTimeMillis() - 60 * 1000) {
            listener.sendSuccess(new TranslatableComponent("commands.forge.gen.progress", total - queue.size(), total), true);
            lastNotification = 0;
            lastNotifcationTime = System.currentTimeMillis();
        }
        int x = next.getX();
        int z = next.getZ();
        if (!dim.hasChunk(x, z)) {
            // Chunk is unloaded
            ChunkAccess chunk = dim.getChunk(x, z, ChunkStatus.EMPTY, true);
            if (!chunk.getStatus().isOrAfter(ChunkStatus.FULL)) {
                chunk = dim.getChunk(x, z, ChunkStatus.FULL);
                // There isn't a way to check if the chunk is actually created just if it was loaded
                genned++;
            }
        }
    }
    if (queue.size() == 0) {
        listener.sendSuccess(new TranslatableComponent("commands.forge.gen.complete", genned, total, dim.dimension().location()), true);
        /* TODO: Readd if/when we introduce world unloading, or get Mojang to do it.
            if (keepingLoaded != null && !keepingLoaded)
                DimensionManager.keepLoaded(dim, false);
            */
        return false;
    }
    return true;
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) BlockPos(net.minecraft.core.BlockPos)

Example 47 with BlockPos

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

the class GameTestTest method testWood.

/**
 * An example game test
 * <p><ul>
 * <li>Must take <b>one</b> parameter, the {@link GameTestHelper}</li>
 * <li>The return type is ignored, so it should be {@code void}</li>
 * <li>Can be {@code static} or non-static<p>
 * WARNING: If made non-static, then it will create an instance of the class every time it is run.</li>
 * </ul>
 * The default template name converts the containing class's name to all lowercase, and the method name to all lowercase.
 * In this example, the structure name would be "gametesttest.testwood" under the "gametest_test" namespace.
 */
@GameTest(templateNamespace = MODID)
public static void testWood(GameTestHelper helper) {
    // The woodPos is in the bottom center of the 3x3x3 structure
    BlockPos woodPos = new BlockPos(1, 1, 1);
    // assertBlockState will convert the relative woodPos into a real world block position and check it with the predicate.
    // Relative positions are made absolute by adding their value to the block position of the structure tile entity,
    // which is always the lowest northwest corner inside the structure.
    // If the predicate fails, the String supplier will be used to construct an exception message, which is thrown
    helper.assertBlockState(woodPos, b -> b.is(Blocks.OAK_LOG), () -> "Block was not an oak log");
    // If we got to this point, the assert succeeded, so the test has succeeded.
    // Game tests require explicitly declaring success, otherwise they fail from timeout.
    helper.succeed();
}
Also used : BlockPos(net.minecraft.core.BlockPos) GameTest(net.minecraft.gametest.framework.GameTest)

Example 48 with BlockPos

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

the class GameTestTest method testHopperPickup.

@PrefixGameTestTemplate(false)
@GameTest(templateNamespace = MODID, template = "empty3x3x3")
public static void testHopperPickup(GameTestHelper helper) {
    BlockPos hopperPos = new BlockPos(1, 1, 1);
    // Sets (1,1,1) to a hopper and spawns a golden apple one block above it
    helper.setBlock(hopperPos, Blocks.HOPPER);
    helper.spawnItem(Items.GOLDEN_APPLE, 1, 2, 1);
    // Waits 20 ticks before checking that the hopper contains the golden apple
    helper.assertAtTickTimeContainerContains(20, hopperPos, Items.GOLDEN_APPLE);
    // Succeeds at 21 ticks if the previous check didn't throw an exception
    helper.runAtTickTime(21, helper::succeed);
}
Also used : BlockPos(net.minecraft.core.BlockPos) GameTest(net.minecraft.gametest.framework.GameTest) PrefixGameTestTemplate(net.minecraftforge.gametest.PrefixGameTestTemplate)

Example 49 with BlockPos

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

the class GameTestTest method testEnergyStorage.

@PrefixGameTestTemplate(false)
@GameTest(templateNamespace = MODID, template = "empty3x3x3")
public static void testEnergyStorage(GameTestHelper helper) {
    BlockPos energyPos = new BlockPos(1, 1, 1);
    // Sets (1,1,1) to our custom energy block
    helper.setBlock(energyPos, ENERGY_BLOCK.get());
    // Queries the energy capability
    LazyOptional<IEnergyStorage> energyHolder = helper.getBlockEntity(energyPos).getCapability(CapabilityEnergy.ENERGY);
    // Adds 2000 FE, but our energy storage can only hold 1000 FE
    energyHolder.ifPresent(energyStorage -> energyStorage.receiveEnergy(2000, false));
    // Fails test if stored energy is not equal to 1000 FE
    int energy = energyHolder.map(IEnergyStorage::getEnergyStored).orElse(0);
    int target = 1000;
    if (energy != target) {
        helper.fail("Expected energy=" + target + " but it was energy=" + energy, energyPos);
    }
    helper.succeed();
}
Also used : IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) BlockPos(net.minecraft.core.BlockPos) GameTest(net.minecraft.gametest.framework.GameTest) PrefixGameTestTemplate(net.minecraftforge.gametest.PrefixGameTestTemplate)

Example 50 with BlockPos

use of net.minecraft.core.BlockPos in project MyPet by xXKeyleXx.

the class EatGrass method tick.

@Override
public void tick() {
    if (--this.eatTicks == 0) {
        int blockLocX = Mth.floor(this.entityMySheep.getX());
        int blockLocY = Mth.floor(this.entityMySheep.getY());
        int blockLocZ = Mth.floor(this.entityMySheep.getZ());
        BlockPos blockAt = new BlockPos(blockLocX, blockLocY, blockLocZ);
        if (GRASS.test(this.world.getBlockState(blockAt))) {
            if (!CraftEventFactory.callEntityChangeBlockEvent(this.entityMySheep, blockAt, Blocks.AIR.defaultBlockState(), !this.world.getWorld().getGameRuleValue(GameRule.MOB_GRIEFING)).isCancelled()) {
                this.world.destroyBlock(blockAt, false);
            }
            entityMySheep.getMyPet().setSheared(false);
        } else {
            BlockPos blockUnder = blockAt.below();
            if (this.world.getBlockState(blockUnder).getBlock() == Blocks.GRASS) {
                if (!CraftEventFactory.callEntityChangeBlockEvent(this.entityMySheep, blockAt, Blocks.AIR.defaultBlockState(), !this.world.getWorld().getGameRuleValue(GameRule.MOB_GRIEFING)).isCancelled()) {
                    this.world.levelEvent(2001, blockUnder, Block.getId(Blocks.GRASS_BLOCK.defaultBlockState()));
                    this.world.setBlock(blockUnder, Blocks.DIRT.defaultBlockState(), 2);
                }
                entityMySheep.getMyPet().setSheared(false);
            }
        }
    }
}
Also used : BlockPos(net.minecraft.core.BlockPos)

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