Search in sources :

Example 6 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project MinecraftForge by MinecraftForge.

the class FiniteWaterTest method handleFiniteWaterSource.

@SubscribeEvent
public static void handleFiniteWaterSource(BlockEvent.CreateFluidSourceEvent event) {
    if (ENABLED) {
        BlockState state = event.getState();
        FluidState fluidState = state.getFluidState();
        if (fluidState.getType().isSame(Fluids.WATER)) {
            event.setResult(Event.Result.DENY);
        } else if (fluidState.getType().isSame(Fluids.LAVA)) {
            event.setResult(Event.Result.ALLOW);
        }
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) FluidState(net.minecraft.world.level.material.FluidState) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 7 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project MinecraftForge by MinecraftForge.

the class NewFluidTest method loadComplete.

public void loadComplete(FMLLoadCompleteEvent event) {
    // some sanity checks
    BlockState state = Fluids.WATER.defaultFluidState().createLegacyBlock();
    BlockState state2 = Fluids.WATER.getAttributes().getBlock(null, null, Fluids.WATER.defaultFluidState());
    Validate.isTrue(state.getBlock() == Blocks.WATER && state2 == state);
    ItemStack stack = Fluids.WATER.getAttributes().getBucket(new FluidStack(Fluids.WATER, 1));
    Validate.isTrue(stack.getItem() == Fluids.WATER.getBucket());
    event.enqueueWork(() -> DispenserBlock.registerBehavior(test_fluid_bucket.get(), DispenseFluidContainer.getInstance()));
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.world.item.ItemStack)

Example 8 with BlockState

use of net.minecraft.world.level.block.state.BlockState 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 BlockState

use of net.minecraft.world.level.block.state.BlockState in project MinecraftForge by MinecraftForge.

the class VariantBlockStateBuilder method addModels.

/**
 * Assign some models to a given {@link PartialBlockstate partial state}.
 *
 * @param state  The {@link PartialBlockstate partial state} for which to add
 *               the models
 * @param models A set of models to add to this state
 * @return this builder
 * @throws NullPointerException     if {@code state} is {@code null}
 * @throws IllegalArgumentException if {@code models} is empty
 * @throws IllegalArgumentException if {@code state}'s owning block differs from
 *                                  the builder's
 * @throws IllegalArgumentException if {@code state} partially matches another
 *                                  state which has already been configured
 */
public VariantBlockStateBuilder addModels(PartialBlockstate state, ConfiguredModel... models) {
    Preconditions.checkNotNull(state, "state must not be null");
    Preconditions.checkArgument(models.length > 0, "Cannot set models to empty array");
    Preconditions.checkArgument(state.getOwner() == owner, "Cannot set models for a different block. Found: %s, Current: %s", state.getOwner(), owner);
    if (!this.models.containsKey(state)) {
        Preconditions.checkArgument(disjointToAll(state), "Cannot set models for a state for which a partial match has already been configured");
        this.models.put(state, new ConfiguredModelList(models));
        for (BlockState fullState : owner.getStateDefinition().getPossibleStates()) {
            if (state.test(fullState)) {
                coveredStates.add(fullState);
            }
        }
    } else {
        this.models.compute(state, ($, cml) -> cml.append(models));
    }
    return this;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) ConfiguredModelList(net.minecraftforge.client.model.generators.BlockStateProvider.ConfiguredModelList)

Example 10 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project MinecraftForge by MinecraftForge.

the class VariantBlockStateBuilder method forAllStatesExcept.

public VariantBlockStateBuilder forAllStatesExcept(Function<BlockState, ConfiguredModel[]> mapper, Property<?>... ignored) {
    Set<PartialBlockstate> seen = new HashSet<>();
    for (BlockState fullState : owner.getStateDefinition().getPossibleStates()) {
        Map<Property<?>, Comparable<?>> propertyValues = Maps.newLinkedHashMap(fullState.getValues());
        for (Property<?> p : ignored) {
            propertyValues.remove(p);
        }
        PartialBlockstate partialState = new PartialBlockstate(owner, propertyValues, this);
        if (seen.add(partialState)) {
            setModels(partialState, mapper.apply(fullState));
        }
    }
    return this;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Property(net.minecraft.world.level.block.state.properties.Property) HashSet(java.util.HashSet)

Aggregations

BlockState (net.minecraft.world.level.block.state.BlockState)38 BlockPos (net.minecraft.core.BlockPos)10 SoundType (net.minecraft.world.level.block.SoundType)10 Level (net.minecraft.world.level.Level)6 LocationTag (com.denizenscript.denizen.objects.LocationTag)4 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)4 ArrayList (java.util.ArrayList)3 Nonnull (javax.annotation.Nonnull)3 Direction (net.minecraft.core.Direction)3 ChunkPos (net.minecraft.world.level.ChunkPos)3 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)3 ChunkCoordinate (com.denizenscript.denizen.utilities.blocks.ChunkCoordinate)2 File (java.io.File)2 List (java.util.List)2 Optional (java.util.Optional)2 TextComponent (net.minecraft.network.chat.TextComponent)2 Player (net.minecraft.world.entity.player.Player)2 ItemStack (net.minecraft.world.item.ItemStack)2 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)2 Fluid (net.minecraft.world.level.material.Fluid)2