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