net.minecraft.state.property.Property Java Examples

The following examples show how to use net.minecraft.state.property.Property. 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: OxygenCollectorBlock.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
@Override
public Property<SideOption> getProperty(@Nonnull BlockFace direction) {
    switch (direction) {
        case FRONT:
            return FRONT_SIDE_OPTION;
        case RIGHT:
            return RIGHT_SIDE_OPTION;
        case LEFT:
            return LEFT_SIDE_OPTION;
        case BACK:
            return BACK_SIDE_OPTION;
        case TOP:
            return TOP_SIDE_OPTION;
        case BOTTOM:
            return BOTTOM_SIDE_OPTION;
    }
    throw new NullPointerException();
}
 
Example #2
Source File: BasicSolarPanelBlock.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
@Override
public Property<SideOption> getProperty(@Nonnull BlockFace direction) {
    switch (direction) {
        case FRONT:
            return FRONT_SIDE_OPTION;
        case RIGHT:
            return RIGHT_SIDE_OPTION;
        case LEFT:
            return LEFT_SIDE_OPTION;
        case BACK:
            return BACK_SIDE_OPTION;
        case TOP:
            return TOP_SIDE_OPTION;
        case BOTTOM:
            return BOTTOM_SIDE_OPTION;
    }
    throw new NullPointerException();
}
 
Example #3
Source File: CircuitFabricatorBlock.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
@Override
public Property<SideOption> getProperty(@Nonnull BlockFace direction) {
    switch (direction) {
        case FRONT:
            return FRONT_SIDE_OPTION;
        case RIGHT:
            return RIGHT_SIDE_OPTION;
        case LEFT:
            return LEFT_SIDE_OPTION;
        case BACK:
            return BACK_SIDE_OPTION;
        case TOP:
            return TOP_SIDE_OPTION;
        case BOTTOM:
            return BOTTOM_SIDE_OPTION;
    }
    throw new NullPointerException();
}
 
Example #4
Source File: ElectricCompressorBlock.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
@Override
public Property<SideOption> getProperty(@Nonnull BlockFace direction) {
    switch (direction) {
        case FRONT:
            return FRONT_SIDE_OPTION;
        case RIGHT:
            return RIGHT_SIDE_OPTION;
        case LEFT:
            return LEFT_SIDE_OPTION;
        case BACK:
            return BACK_SIDE_OPTION;
        case TOP:
            return TOP_SIDE_OPTION;
        case BOTTOM:
            return BOTTOM_SIDE_OPTION;
    }
    throw new NullPointerException();
}
 
Example #5
Source File: RefineryBlock.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
@Override
public Property<SideOption> getProperty(@Nonnull BlockFace direction) {
    switch (direction) {
        case FRONT:
            return FRONT_SIDE_OPTION;
        case RIGHT:
            return RIGHT_SIDE_OPTION;
        case LEFT:
            return LEFT_SIDE_OPTION;
        case BACK:
            return BACK_SIDE_OPTION;
        case TOP:
            return TOP_SIDE_OPTION;
        case BOTTOM:
            return BOTTOM_SIDE_OPTION;
    }
    throw new NullPointerException();
}
 
Example #6
Source File: EnergyStorageModuleBlock.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
@Override
public Property<SideOption> getProperty(@Nonnull BlockFace direction) {
    switch (direction) {
        case FRONT:
            return FRONT_SIDE_OPTION;
        case RIGHT:
            return RIGHT_SIDE_OPTION;
        case LEFT:
            return LEFT_SIDE_OPTION;
        case BACK:
            return BACK_SIDE_OPTION;
        case TOP:
            return TOP_SIDE_OPTION;
        case BOTTOM:
            return BOTTOM_SIDE_OPTION;
    }
    throw new NullPointerException();
}
 
Example #7
Source File: CoalGeneratorBlock.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
@Override
public Property<SideOption> getProperty(@Nonnull BlockFace direction) {
    switch (direction) {
        case FRONT:
            return FRONT_SIDE_OPTION;
        case RIGHT:
            return RIGHT_SIDE_OPTION;
        case LEFT:
            return LEFT_SIDE_OPTION;
        case BACK:
            return BACK_SIDE_OPTION;
        case TOP:
            return TOP_SIDE_OPTION;
        case BOTTOM:
            return BOTTOM_SIDE_OPTION;
    }
    throw new NullPointerException();
}
 
Example #8
Source File: StandardWrenchItem.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
private void use(PlayerEntity player, BlockState state, WorldAccess iWorld, BlockPos pos, ItemStack stack) {
    Block block = state.getBlock();
    if (block instanceof Rotatable) {
        StateManager<Block, BlockState> manager = block.getStateManager();
        Collection<Property<?>> collection = manager.getProperties();
        String string_1 = Registry.BLOCK.getId(block).toString();
        if (!collection.isEmpty()) {
            CompoundTag compoundTag_1 = stack.getOrCreateSubTag("wrenchProp");
            String string_2 = compoundTag_1.getString(string_1);
            Property<?> property = manager.getProperty(string_2);
            if (property == null) {
                property = collection.iterator().next();
            }
            if (property.getName().equals("facing")) {
                BlockState blockState_2 = cycle(state, property, player.isSneaking());
                iWorld.setBlockState(pos, blockState_2, 18);
                stack.damage(2, player, (playerEntity) -> playerEntity.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND));
            }
        }
    }
}
 
Example #9
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Re-colors this block in the world.
 *
 * @param state   The current state
 * @param world   The world
 * @param pos     Block position
 * @param facing  ??? (this method has no usages)
 * @param color   Color to recolor to.
 * @return if the block was affected
 */
@SuppressWarnings("unchecked")
default boolean recolorBlock(BlockState state, IWorld world, BlockPos pos, Direction facing, DyeColor color) {
	for (Property<?> prop : state.getProperties()) {
		if (prop.getName().equals("color") && prop.getType() == DyeColor.class) {
			DyeColor current = (DyeColor) state.get(prop);

			if (current != color && prop.getValues().contains(color)) {
				world.setBlockState(pos, state.with(((Property<DyeColor>) prop), color), 3);
				return true;
			}
		}
	}

	return false;
}
 
Example #10
Source File: CarpetExpression.java    From fabric-carpet with MIT License 5 votes vote down vote up
private <T extends Comparable<T>> BlockState setProperty(Property<T> property, String name, String value,
                                                          BlockState bs)
{
    Optional<T> optional = property.parse(value);

    if (optional.isPresent())
    {
        bs = bs.with(property, optional.get());
    }
    else
    {
        throw new InternalExpressionException(value + " is not a valid value for property " + name);
    }
    return bs;
}
 
Example #11
Source File: BlockValue.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public Tag toTag(boolean force)
{
    if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
    // follows falling block convertion
    CompoundTag tag =  new CompoundTag();
    CompoundTag state = new CompoundTag();
    BlockState s = getBlockState();
    state.put("Name", StringTag.of(Registry.BLOCK.getId(s.getBlock()).toString()));
    Collection<Property<?>> properties = s.getProperties();
    if (!properties.isEmpty())
    {
        CompoundTag props = new CompoundTag();
        for (Property<?> p: properties)
        {
            props.put(p.getName(), StringTag.of(s.get(p).toString().toLowerCase(Locale.ROOT)));
        }
        state.put("Properties", props);
    }
    tag.put("BlockState", state);
    CompoundTag dataTag = getData();
    if (dataTag != null)
    {
        tag.put("TileEntityData", dataTag);
    }
    return tag;
}
 
Example #12
Source File: MixinStateManager.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@ModifyVariable(method = "add", at = @At("HEAD"), ordinal = 0)
        public Property<?>[] properties(Property<?>[] in) {
//            if (ArrayUtils.contains(in, Properties.WATERLOGGED)) {
//                in=ArrayUtils.add(ArrayUtils.removeElement(in, Properties.WATERLOGGED), SandboxProperties.PROPERTY_FLUIDLOGGABLE);
//            }
            return in;
        }
 
Example #13
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Get the rotations that can apply to the block at the specified coordinates. Null means no rotations are possible.
 * Note, this is up to the block to decide. It may not be accurate or representative.
 *
 * @param state The current state
 * @param world The world
 * @param pos   Block position in world
 * @return An array of valid axes to rotate around, or null for none or unknown
 */
@Nullable
default Direction[] getValidRotations(BlockState state, BlockView world, BlockPos pos) {
	for (Property<?> prop : state.getProperties()) {
		if ((prop.getName().equals("facing") || prop.getName().equals("rotation")) && prop.getType() == Direction.class) {
			@SuppressWarnings("unchecked")
			Collection<Direction> values = ((Collection<Direction>) prop.getValues());
			return values.toArray(new Direction[values.size()]);
		}
	}

	return null;
}
 
Example #14
Source File: Protocol_1_12_2.java    From multiconnect with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private static <T extends Comparable<T>> BlockState addProperty(StateManager<Block, BlockState> stateManager, BlockState state, String propName, String valName) {
    Property<T> prop = (Property<T>) stateManager.getProperty(propName);
    return prop == null ? state : state.with(prop, prop.parse(valName).orElseGet(() -> state.get(prop)));
}
 
Example #15
Source File: MixinCropBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@SuppressWarnings("rawtypes")
@Redirect(method = "getAvailableMoisture", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;get(Lnet/minecraft/state/property/Property;)Ljava/lang/Comparable;"))
private static Comparable<Integer> redirectHydratedCheck(BlockState blockState, Property property) {
	final IForgeBlockState forgeBlockState = (IForgeBlockState) blockState;
	return forgeBlockState.isFertile(currentWorld.get(), currentBlockPos.get()) ? 1 : 0;
}
 
Example #16
Source File: WrappingUtil.java    From Sandbox with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Property convert(org.sandboxpowered.sandbox.api.state.Property property) {
    //TODO: Wrapper
    return (Property) property;
}
 
Example #17
Source File: AbstractBlockStateMixin.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
private AbstractBlockStateMixin(WurstClient wurst, Block object,
	ImmutableMap<Property<?>, Comparable<?>> immutableMap,
	MapCodec<BlockState> mapCodec)
{
	super(object, immutableMap, mapCodec);
}
 
Example #18
Source File: MixinBlockState.java    From Sandbox with GNU Lesser General Public License v3.0 4 votes vote down vote up
public MixinBlockState(net.minecraft.block.Block object_1, ImmutableMap<Property<?>, Comparable<?>> immutableMap_1) {
    super(object_1, immutableMap_1);
}
 
Example #19
Source File: StandardWrenchItem.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
private static <T extends Comparable<T>> BlockState cycle(BlockState state, Property<T> property, boolean sneaking) {
    return state.with(property, cycle(property.getValues(), state.get(property), sneaking));
}
 
Example #20
Source File: ConfigurableElectricMachineBlock.java    From Galacticraft-Rewoven with MIT License votes vote down vote up
public abstract Property<SideOption> getProperty(BlockFace direction);