Search in sources :

Example 26 with IProperty

use of net.minecraft.block.properties.IProperty in project MorePlanets by SteveKunG.

the class ItemBlockSlabMP method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack itemStack = player.getHeldItem(hand);
    if (this.block instanceof ISlabBlock) {
        ISlabBlock singleSlab = (ISlabBlock) this.block;
        if (itemStack.getCount() != 0 && player.canPlayerEdit(pos.offset(facing), facing, itemStack)) {
            Object object = singleSlab.getHalf().getTypeForItem(itemStack);
            IBlockState state = world.getBlockState(pos);
            if (state.getBlock() == singleSlab.getHalf()) {
                IProperty iproperty = singleSlab.getHalf().getVariantProperty();
                Comparable comparable = state.getValue(iproperty);
                EnumBlockHalf enumblockhalf = state.getValue(BlockSlab.HALF);
                if ((facing == EnumFacing.UP && enumblockhalf == EnumBlockHalf.BOTTOM || facing == EnumFacing.DOWN && enumblockhalf == BlockSlab.EnumBlockHalf.TOP) && comparable == object) {
                    IBlockState state1 = singleSlab.getDouble().getDefaultState().withProperty(iproperty, comparable);
                    AxisAlignedBB axisalignedbb = state1.getCollisionBoundingBox(world, pos);
                    if (axisalignedbb != Block.NULL_AABB && world.checkNoEntityCollision(axisalignedbb.offset(pos)) && world.setBlockState(pos, state1, 11)) {
                        SoundType sound = singleSlab.getDouble().getSoundType(state1, world, pos, player);
                        world.playSound(player, pos, sound.getPlaceSound(), SoundCategory.BLOCKS, (sound.getVolume() + 1.0F) / 2.0F, sound.getPitch() * 0.8F);
                        itemStack.shrink(1);
                    }
                    return EnumActionResult.SUCCESS;
                }
            }
            return this.tryPlace(player, itemStack, world, pos.offset(facing), object, singleSlab.getHalf(), singleSlab.getDouble()) ? EnumActionResult.SUCCESS : super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
        }
    } else {
        return EnumActionResult.FAIL;
    }
    return EnumActionResult.FAIL;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) SoundType(net.minecraft.block.SoundType) EnumBlockHalf(net.minecraft.block.BlockSlab.EnumBlockHalf) IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) ISlabBlock(stevekung.mods.moreplanets.util.blocks.ISlabBlock) ItemStack(net.minecraft.item.ItemStack)

Example 27 with IProperty

use of net.minecraft.block.properties.IProperty in project Almura by AlmuraDev.

the class IngameFarmersAlmanac method loadProperties.

@SuppressWarnings("unchecked")
private void loadProperties(World world, IBlockState blockState, BlockPos blockPos) {
    final Hydration hydration = getHydrationDefinition(blockState).orElse(null);
    if (hydration != null) {
        this.addLineLabel(Text.of(TextColors.WHITE, "Hydrated by:"));
        hydration.blockStates().forEach(bs -> {
            this.addLineLabel(Text.of(TextColors.WHITE, "- ", bs.block().getLocalizedName()), 2, false);
            bs.properties().forEach(property -> bs.value(property).ifPresent(stateValue -> {
                final String formattedValue;
                if (stateValue instanceof RangeStateValue) {
                    final RangeStateValue rangeStateValue = (RangeStateValue) stateValue;
                    formattedValue = numberFormat.format(rangeStateValue.min()) + "-" + numberFormat.format(rangeStateValue.max());
                } else {
                    final Comparable rawValue = stateValue.get((IProperty) property);
                    formattedValue = rawValue == null ? "" : rawValue.toString();
                }
                this.addLineLabel(this.getGenericPropertyText("- " + property.getName(), formattedValue), 6, false);
            }));
        });
        this.addLineLabel(this.getGenericPropertyText("Hydration Radius", String.valueOf(hydration.getMaxRadius())));
    }
    // Growth stage
    getGrowthStage(blockState).ifPresent(growthStage -> this.addLineLabel(this.getGenericPropertyText("Growth Stage", String.format("%d of %d", growthStage.getFirst(), growthStage.getSecond()))));
    // Ground moisture
    final int moistureLevel = getMoistureLevel(blockState);
    final boolean isFertile = moistureLevel > 0;
    final TextColor fertileColor = isFertile ? TextColors.DARK_GREEN : TextColors.RED;
    this.addLineLabel(Text.of(TextColors.WHITE, "Moisture: ", fertileColor, isFertile ? "Fertile" : "Too dry"));
    // Ground temperature
    final DoubleRange temperatureRange = getTemperatureRange(world, blockState, blockPos).orElse(null);
    if (temperatureRange != null) {
        this.addLineLabel(Text.of(TextColors.WHITE, "Ground Temperature: ", (temperatureRange.min() == -1 || temperatureRange.max() == -1) ? TextColors.RED : TextColors.DARK_GREEN, numberFormat.format(message.biomeTemperature)));
        this.addLineLabel(this.getGenericPropertyText("Required", String.format("%s-%s", numberFormat.format(temperatureRange.min()), numberFormat.format(temperatureRange.max()))), 2, false);
    }
    // Biome rain
    this.addLineLabel(Text.of(TextColors.WHITE, "Rain: ", message.biomeRainfall > 0.4 ? TextColors.DARK_GREEN : TextColors.RED, numberFormat.format(message.biomeRainfall)));
    // Sunlight value
    final int sunlight = world.getLightFor(EnumSkyBlock.SKY, blockPos) - world.getSkylightSubtracted();
    this.addLineLabel(this.getGenericPropertyText("Sunlight", String.valueOf(sunlight)));
    // Area light value
    final DoubleRange lightRange = getLightRange(world, blockState, blockPos).orElse(null);
    if (lightRange != null) {
        final int lightValue = world.getLightFor(EnumSkyBlock.SKY, blockPos);
        final TextColor valueColor = lightValue < 6 ? (sunlight < 6 ? TextColors.RED : TextColors.YELLOW) : TextColors.DARK_GREEN;
        this.addLineLabel(Text.of(TextColors.WHITE, "Area light: ", valueColor, String.valueOf(lightValue)));
        this.addLineLabel(this.getGenericPropertyText("Required", String.format("%s-%s", numberFormat.format(lightRange.min()), numberFormat.format(lightRange.max()))), 2, false);
    }
    // Can Die
    this.addLineLabel(this.getGenericPropertyText("Can Die", String.valueOf(canRollback(blockState))));
    // Harvest Tool
    final String harvestTool = blockState.getBlock().getHarvestTool(blockState);
    if (harvestTool != null && !harvestTool.isEmpty()) {
        addLineLabel(this.getGenericPropertyText("Harvested by", harvestTool));
    }
}
Also used : BlockCrops(net.minecraft.block.BlockCrops) BlockFarmland(net.minecraft.block.BlockFarmland) ClientboundWorldPositionInformationPacket(com.almuradev.almura.feature.complex.item.almanac.network.ClientboundWorldPositionInformationPacket) WorldClient(net.minecraft.client.multiplayer.WorldClient) UIFormContainer(com.almuradev.almura.shared.client.ui.component.UIFormContainer) UIButtonBuilder(com.almuradev.almura.shared.client.ui.component.button.UIButtonBuilder) UIComponent(net.malisis.core.client.gui.component.UIComponent) NumberFormat(java.text.NumberFormat) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) WorldType(net.minecraft.world.WorldType) IProperty(net.minecraft.block.properties.IProperty) Block(net.minecraft.block.Block) Text(org.spongepowered.api.text.Text) TextColor(org.spongepowered.api.text.format.TextColor) Minecraft(net.minecraft.client.Minecraft) FontColors(com.almuradev.almura.shared.client.ui.FontColors) Anchor(net.malisis.core.client.gui.Anchor) TextColors(org.spongepowered.api.text.format.TextColors) Growth(com.almuradev.content.type.block.type.crop.processor.growth.Growth) UIScrollBar(net.malisis.core.client.gui.component.control.UIScrollBar) UIButton(net.malisis.core.client.gui.component.interaction.UIButton) RangeStateValue(com.almuradev.content.type.block.state.value.RangeStateValue) SimpleScreen(com.almuradev.almura.shared.client.ui.screen.SimpleScreen) CropBlockStateDefinition(com.almuradev.content.type.block.type.crop.state.CropBlockStateDefinition) IMixinBlockCrops(com.almuradev.almura.feature.complex.item.almanac.asm.interfaces.IMixinBlockCrops) UILabel(net.malisis.core.client.gui.component.decoration.UILabel) UIBackgroundContainer(net.malisis.core.client.gui.component.container.UIBackgroundContainer) World(net.minecraft.world.World) DecimalFormat(java.text.DecimalFormat) PropertyInteger(net.minecraft.block.properties.PropertyInteger) Hydration(com.almuradev.content.type.block.type.crop.processor.hydration.Hydration) BlockPos(net.minecraft.util.math.BlockPos) Tuple(org.spongepowered.api.util.Tuple) Mouse(org.lwjgl.input.Mouse) UISeparator(net.malisis.core.client.gui.component.decoration.UISeparator) IBlockState(net.minecraft.block.state.IBlockState) TextSerializers(org.spongepowered.api.text.serializer.TextSerializers) UIImage(net.malisis.core.client.gui.component.decoration.UIImage) EnumSkyBlock(net.minecraft.world.EnumSkyBlock) Optional(java.util.Optional) CropBlockImpl(com.almuradev.content.type.block.type.crop.CropBlockImpl) DoubleRange(com.almuradev.toolbox.util.math.DoubleRange) UISlimScrollbar(net.malisis.core.client.gui.component.control.UISlimScrollbar) RangeStateValue(com.almuradev.content.type.block.state.value.RangeStateValue) DoubleRange(com.almuradev.toolbox.util.math.DoubleRange) Hydration(com.almuradev.content.type.block.type.crop.processor.hydration.Hydration) IProperty(net.minecraft.block.properties.IProperty) TextColor(org.spongepowered.api.text.format.TextColor)

Example 28 with IProperty

use of net.minecraft.block.properties.IProperty in project Almura by AlmuraDev.

the class LookingDebugPanel method renderItemStackFromBlock.

private void renderItemStackFromBlock(final IBlockState state, final ItemStack pickStack) {
    this.clipContent = false;
    // Draw what we know of
    if (!pickStack.isEmpty()) {
        this.drawItem(pickStack, 4, this.autoHeight + 4);
        if (pickStack.getItem() instanceof ItemBlock) {
            this.drawText(Text.of(TextColors.WHITE, Block.REGISTRY.getNameForObject(state.getBlock())), 24, this.autoHeight - 14, false, true);
        } else {
            this.drawText(Text.of(TextColors.WHITE, Block.REGISTRY.getNameForObject(state.getBlock())), 24, this.autoHeight - 14, false, true);
        }
    } else {
        this.drawText(Text.of(TextColors.WHITE, Block.REGISTRY.getNameForObject(state.getBlock())), 24, this.autoHeight + 3, false, true);
    }
    final Map<IProperty<?>, Comparable<?>> properties = state.getProperties();
    final boolean hasProperties = !properties.isEmpty();
    if (hasProperties) {
        this.autoHeight -= 2;
    }
    for (final Map.Entry<IProperty<?>, Comparable<?>> entry : properties.entrySet()) {
        final IProperty<?> property = entry.getKey();
        final String name = property.getName();
        final Comparable<?> value = entry.getValue();
        final String describedValue = getName(property, value);
        if (value instanceof Boolean) {
            this.drawText(Text.of(TextColors.WHITE, name, ": ", ((Boolean) value) ? TextColors.GREEN : TextColors.RED, describedValue), 24, this.autoHeight);
        } else {
            this.drawProperty(name, describedValue, 24, pickStack.isEmpty() ? this.autoHeight + 13 : this.autoHeight);
        }
    }
    if (hasProperties) {
        this.autoHeight -= 4;
    }
}
Also used : IProperty(net.minecraft.block.properties.IProperty) NBTTagString(net.minecraft.nbt.NBTTagString) ItemBlock(net.minecraft.item.ItemBlock) Map(java.util.Map)

Example 29 with IProperty

use of net.minecraft.block.properties.IProperty in project Almura by AlmuraDev.

the class StatefulLazyBlockState method resolveProperties.

private <T extends Comparable<T>> Map<IProperty<? extends Comparable<?>>, StateValue<? extends Comparable<?>>> resolveProperties(final Map<String, StateValue<? extends Comparable<?>>> source) {
    final Block block = (Block) this.block.require();
    final Map<IProperty<? extends Comparable<?>>, StateValue<? extends Comparable<?>>> target = new HashMap<>();
    final BlockStateContainer definition = block.getBlockState();
    for (final Map.Entry<String, StateValue<? extends Comparable<?>>> entry : source.entrySet()) {
        @Nullable final IProperty<T> property = (IProperty<T>) definition.getProperty(entry.getKey());
        if (property != null) {
            target.put(property, entry.getValue());
        }
    }
    return target;
}
Also used : HashMap(java.util.HashMap) IProperty(net.minecraft.block.properties.IProperty) Block(net.minecraft.block.Block) StateValue(com.almuradev.content.type.block.state.value.StateValue) HashMap(java.util.HashMap) Map(java.util.Map) BlockStateContainer(net.minecraft.block.state.BlockStateContainer) Nullable(javax.annotation.Nullable)

Aggregations

IProperty (net.minecraft.block.properties.IProperty)29 IBlockState (net.minecraft.block.state.IBlockState)19 ItemStack (net.minecraft.item.ItemStack)8 Block (net.minecraft.block.Block)7 ResourceLocation (net.minecraft.util.ResourceLocation)6 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)6 DrawBlock (com.microsoft.Malmo.Schemas.DrawBlock)5 TileEntity (net.minecraft.tileentity.TileEntity)5 BlockStateContainer (net.minecraft.block.state.BlockStateContainer)4 JsonObject (com.google.gson.JsonObject)3 Variation (com.microsoft.Malmo.Schemas.Variation)3 ItemBlock (net.minecraft.item.ItemBlock)3 ComparableItemStack (blusunrize.immersiveengineering.api.ComparableItemStack)2 StateValue (com.almuradev.content.type.block.state.value.StateValue)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 BlockType (com.microsoft.Malmo.Schemas.BlockType)2 Colour (com.microsoft.Malmo.Schemas.Colour)2 DrawItem (com.microsoft.Malmo.Schemas.DrawItem)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2