public BlockLivingSlab(boolean full, IBlockState state) { super(full, state.getMaterial(), state.getBlock().getTranslationKey().replaceAll("tile.", "") + state.getBlock().getMetaFromState(state) + "Slab" + (full ? "Full" : "")); setSoundType(state.getBlock().getSoundType()); sourceState = state; }
@Override public int damageDropped(IBlockState state) { QuartzVariant variant = state.getValue(BotaniaStateProps.QUARTZ_VARIANT); if (variant == QuartzVariant.PILLAR_X || variant == QuartzVariant.PILLAR_Z) { state = state.withProperty(BotaniaStateProps.QUARTZ_VARIANT, QuartzVariant.PILLAR_Y); } return getMetaFromState(state); }
/** * Determines if a block side can contain a glow. * Returns true if the block side is solid and the block at the given BlockPos is not a liquid */ protected boolean canBlockStay(World world, BlockPos pos, EnumFacing facing) { BlockPos placedOn = pos.offset(facing); boolean isSolidSide = world.getBlockState(placedOn).isSideSolid(world, placedOn, facing.getOpposite()); boolean isLiquid = world.getBlockState(pos).getBlock() instanceof BlockLiquid; return !isLiquid && isSolidSide; }
@Override public BlockState getBlock(BlockVector3 position) { World world = getWorld(); BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()); IBlockState mcState = world.getBlockState(pos); BlockType blockType = BlockType.REGISTRY.get(Block.REGISTRY.getNameForObject(mcState.getBlock()).toString()); return blockType.getState(adaptProperties(blockType, mcState.getProperties())); }
@Override public boolean shouldRefresh(World world, BlockPos pos, @Nonnull IBlockState oldState, @Nonnull IBlockState newState) { if(oldState.getBlock() != newState.getBlock()) return true; if(oldState.getBlock() != ModBlocks.spreader || newState.getBlock() != ModBlocks.spreader) return true; return oldState.getValue(BotaniaStateProps.SPREADER_VARIANT) != newState.getValue(BotaniaStateProps.SPREADER_VARIANT); }
@Nonnull @Override public IBlockState getActualState(IBlockState state, @Nonnull IBlockAccess worldIn, @Nonnull BlockPos pos) { if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER) { IBlockState iblockstate = worldIn.getBlockState(pos.down()); if (iblockstate.getBlock() == this) { PropertyEnum<EnumDyeColor> prop = second ? BotaniaStateProps.DOUBLEFLOWER_VARIANT_2 : BotaniaStateProps.DOUBLEFLOWER_VARIANT_1; state = state.withProperty(prop, iblockstate.getValue(prop)); } } return state.withProperty(VARIANT, EnumPlantType.SUNFLOWER).withProperty(FACING, EnumFacing.SOUTH); }
if(block == Blocks.PISTON_EXTENSION) { IBlockState state = getStateAt(s); boolean sticky = BlockPistonExtension.EnumPistonType.STICKY == state.getValue(BlockPistonMoving.TYPE); EnumFacing dir = state.getValue(BlockPistonMoving.FACING); Material mat = srcState.getMaterial(); if(!sticky && tile == null && mat.getPushReaction() == EnumPushReaction.NORMAL && srcState.getBlockHardness(world, pos2) != -1 && !srcState.getBlock().isAir(srcState, world, pos2)) { Material destMat = world.getBlockState(pos2.offset(dir)).getMaterial(); if(world.isAirBlock(pos2.offset(dir)) || destMat.isReplaceable()) { world.setBlockState(pos2, Blocks.AIR.getDefaultState());
/** * Checks if this plane can handle the block at the specific coordinates. */ private boolean canHandleBlock( final WorldServer w, final BlockPos pos ) { final IBlockState state = w.getBlockState( pos ); final Material material = state.getMaterial(); final float hardness = state.getBlockHardness( w, pos ); final boolean ignoreMaterials = material == Material.AIR || material == Material.LAVA || material == Material.WATER || material.isLiquid(); final boolean ignoreBlocks = state.getBlock() == Blocks.BEDROCK || state.getBlock() == Blocks.END_PORTAL || state .getBlock() == Blocks.END_PORTAL_FRAME || state.getBlock() == Blocks.COMMAND_BLOCK; return !ignoreMaterials && !ignoreBlocks && hardness >= 0f && !w.isAirBlock( pos ) && w.isBlockLoaded( pos ) && w.canMineBlockBody( Platform.getPlayer( w ), pos ); }
@SuppressWarnings({ "rawtypes", "unchecked" }) private IBlockState applyProperties(BlockStateContainer stateContainer, IBlockState newState, Map<Property<?>, Object> states) { for (Map.Entry<Property<?>, Object> state : states.entrySet()) { IProperty property = stateContainer.getProperty(state.getKey().getName()); Comparable value = (Comparable) state.getValue(); // we may need to adapt this value, depending on the source prop if (property instanceof PropertyDirection) { Direction dir = (Direction) value; value = ForgeAdapter.adapt(dir); } else if (property instanceof PropertyEnum) { String enumName = (String) value; value = ((PropertyEnum<?>) property).parseValue((String) value).or(() -> { throw new IllegalStateException("Enum property " + property.getName() + " does not contain " + enumName); }); } newState = newState.withProperty(property, value); } return newState; }
@Override public void simulateBlockMine(BlockVector3 position) { BlockPos pos = ForgeAdapter.toBlockPos(position); IBlockState state = getWorld().getBlockState(pos); state.getBlock().dropBlockAsItem(getWorld(), pos, state, 0); getWorld().setBlockToAir(pos); }
@Override @SuppressWarnings("deprecation") public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { // todo: depend on fill level? return state.getActualState(source, pos).getValue(FULL) ? FULL_BLOCK_AABB : AABB; }
@Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, RayTraceResult pos, boolean isManaBlock, boolean dead, ItemStack stack) { if(!entity.world.isRemote && !burst.isFake() && pos.getBlockPos() != null) { int harvestLevel = ConfigHandler.harvestLevelWeight; BlockPos bPos = pos.getBlockPos(); Block block = entity.world.getBlockState(bPos).getBlock(); IBlockState state = entity.world.getBlockState(bPos); int neededHarvestLevel = block.getHarvestLevel(state); if(entity.world.isAirBlock(bPos.down()) && state.getBlockHardness(entity.world, bPos) != -1 && neededHarvestLevel <= harvestLevel && entity.world.getTileEntity(bPos) == null && block.canSilkHarvest(entity.world, bPos, state, null)) { state = TECHNICAL_BLOCK_REMAP.getOrDefault(state, state); EntityFallingBlock falling = new EntityFallingBlock(entity.world, bPos.getX() + 0.5, bPos.getY(), bPos.getZ() + 0.5, state); falling.fallTime = 1; entity.world.setBlockToAir(bPos); ((WorldServer) entity.world).spawnParticle(EnumParticleTypes.FALLING_DUST, bPos.getX() + 0.5, bPos.getY() + 0.5, bPos.getZ() + 0.5, 10, 0.45, 0.45, 0.45, 5, new int[] {Block.getStateId(state)}); entity.world.spawnEntity(falling); } } return dead; }
@Override @ParametersAreNonnullByDefault public int getLightOpacity(IBlockState state, IBlockAccess world, BlockPos pos) { if (state.getBlock() instanceof BlockTurretBase) { return state.getActualState(world, pos).getValue(LIGHT_OPACITY); } return super.getLightValue(state, world, pos); }
BlockPos pos = Minecraft.getMinecraft().objectMouseOver.getBlockPos(); IBlockState state = world.getBlockState(pos); state = state.getActualState(world, pos); state = state.getBlock().getExtendedState(state, world, pos); if (state instanceof IExtendedBlockState) { try {
@Override protected ModelResourceLocation getModelResourceLocation(IBlockState state) { ResourceLocation loc = state.getBlock().getRegistryName(); if(state.getValue(BlockCustomFlowerPot.CUSTOM)) return new ModelResourceLocation(loc, "contents=custom"); LinkedHashMap<IProperty<?>, Comparable<?>> map = Maps.newLinkedHashMap(state.getProperties()); map.remove(BlockCustomFlowerPot.CUSTOM); map.remove(BlockCustomFlowerPot.LEGACY_DATA); return new ModelResourceLocation(loc, this.getPropertyString(map)); } }
protected boolean canBlockStay(World worldIn, BlockPos pos, EnumFacing facing) { boolean solid = facing.getAxis() != Axis.Y && worldIn.getBlockState(pos.offset(facing.getOpposite())).isSideSolid(worldIn, pos.offset(facing.getOpposite()), facing); IBlockState topState = worldIn.getBlockState(pos.up()); return solid || (topState.getBlock() == this && (facing.getAxis() == Axis.Y || topState.getValue(FACING) == facing)); }
protected boolean canMakeSnow(@Nonnull World world, final @Nonnull BlockPos neighborPos, final @Nonnull IBlockState neighborState) { final BlockPos belowNeighborPos = neighborPos.down(); final Block neighborBlock = neighborState.getBlock(); return neighborBlock != Blocks.SNOW_LAYER && !(neighborBlock instanceof IFluidBlock) && !(neighborBlock instanceof BlockLiquid) && neighborBlock.isReplaceable(world, neighborPos) && world.getBlockState(belowNeighborPos).isSideSolid(world, belowNeighborPos, EnumFacing.UP); }
@Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, RayTraceResult pos, boolean isManaBlock, boolean dead, ItemStack stack) { BlockPos coords = burst.getBurstSourceBlockPos(); if(!entity.world.isRemote && pos.getBlockPos() != null && !coords.equals(pos.getBlockPos()) && !burst.isFake() && !isManaBlock) { BlockPos pos_ = pos.getBlockPos().offset(pos.sideHit.getOpposite()); if(entity.world.isAirBlock(pos_) || entity.world.getBlockState(pos_).getBlock().isReplaceable(entity.world, pos_)) { IBlockState state = entity.world.getBlockState(pos.getBlockPos()); TileEntity tile = entity.world.getTileEntity(pos.getBlockPos()); if(state.getPushReaction() == EnumPushReaction.NORMAL && state.getBlock() != Blocks.OBSIDIAN && state.getBlockHardness(entity.world, pos_) >= 0 && tile == null) { entity.world.destroyBlock(pos.getBlockPos(), false); entity.world.setBlockState(pos_, state, 1 | 2); } } } return dead; }
@Nonnull @Override public ItemStack dispenseStack(IBlockSource source, ItemStack stack) { World world = source.getWorld(); EnumFacing enumfacing = world.getBlockState(source.getBlockPos()).getValue(BlockDispenser.FACING); double d0 = source.getX() + enumfacing.getXOffset() * 1.125F; double d1 = source.getY() + enumfacing.getYOffset() * 1.125F; double d2 = source.getZ() + enumfacing.getZOffset() * 1.125F; BlockPos pos = source.getBlockPos().offset(enumfacing); IBlockState state = world.getBlockState(pos); double d3; if(BlockRailBase.isRailBlock(state)) d3 = 0.0D; else { if(state.getMaterial() != Material.AIR || !BlockRailBase.isRailBlock(world.getBlockState(pos.down()))) return super.dispenseStack(source, stack); d3 = -1.0D; } EntityMinecart entityminecart = new EntityPoolMinecart(world, d0, d1 + d3, d2); if(stack.hasDisplayName()) entityminecart.setCustomNameTag(stack.getDisplayName()); world.spawnEntity(entityminecart); stack.splitStack(1); return stack; }
@Override public int getMetaFromState(IBlockState state) { switch (state.getValue(BotaniaStateProps.CARDINALS)) { case NORTH: return 0; case WEST: return 3; case EAST: return 1; case SOUTH: default: return 2; // wai vazkii senpai } }