@Override public BlockMaterial getMaterial(BlockType blockType) { return materialMap.computeIfAbsent(Block.getBlockFromName(blockType.getId()).getDefaultState().getMaterial(), m -> new ForgeBlockMaterial(m, super.getMaterial(blockType))); }
private boolean canReplace( World w, IBlockState state, Block block, BlockPos pos ) { return block.isReplaceable( w, pos ) && !( block instanceof IFluidBlock ) && !( block instanceof BlockLiquid ) && !state.getMaterial().isLiquid(); }
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; }
public static void breakOnAllCursors(EntityPlayer player, Item item, ItemStack stack, BlockPos pos, EnumFacing side) { ItemStack lokiRing = getLokiRing(player); if(lokiRing.isEmpty() || player.world.isRemote || !(item instanceof ISequentialBreaker)) return; List<BlockPos> cursors = getCursorList(lokiRing); ISequentialBreaker breaker = (ISequentialBreaker) item; boolean dispose = breaker.disposeOfTrashBlocks(stack); for (BlockPos offset : cursors) { BlockPos coords = pos.add(offset); IBlockState state = player.world.getBlockState(coords); breaker.breakOtherBlock(player, stack, coords, pos, side); ToolCommons.removeBlockWithDrops(player, stack, player.world, coords, s -> s.getBlock() == state.getBlock() && s.getMaterial() == state.getMaterial(), dispose); } }
@Override public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, EntityPlayer player) { World world = player.world; Material mat = world.getBlockState(pos).getMaterial(); if (!ToolCommons.materialsShovel.contains(mat)) return false; RayTraceResult block = ToolCommons.raytraceFromEntity(world, player, true, 10); if (block == null) return false; Block blk = world.getBlockState(pos).getBlock(); if(blk instanceof BlockFalling) ToolCommons.removeBlocksInIteration(player, stack, world, pos, new Vec3i(0, -12, 0), new Vec3i(1, 12, 1), state -> state.getBlock() == blk, false); return false; }
@Override public boolean shouldSideBeRendered( final IBlockState state, final IBlockAccess w, final BlockPos pos, final EnumFacing side ) { BlockPos adjacentPos = pos.offset( side ); final Material mat = w.getBlockState( adjacentPos ).getMaterial(); if( mat == Material.GLASS || mat == AEGlassMaterial.INSTANCE ) { if( w.getBlockState( adjacentPos ).getRenderType() == this.getRenderType( state ) ) { return false; } } return w.getBlockState( pos ).shouldSideBeRendered( w, adjacentPos, side ); }
private boolean isPlant(BlockPos pos) { IBlockState state = supertile.getWorld().getBlockState(pos); Block block = state.getBlock(); if(block == Blocks.GRASS || block == Blocks.LEAVES || block == Blocks.LEAVES2 || block instanceof BlockBush && !(block instanceof BlockCrops) && !(block instanceof BlockSapling)) return false; Material mat = state.getMaterial(); return mat != null && (mat == Material.PLANTS || mat == Material.CACTUS || mat == Material.GRASS || mat == Material.LEAVES || mat == Material.GOURD) && block instanceof IGrowable && ((IGrowable) block).canGrow(supertile.getWorld(), pos, supertile.getWorld().getBlockState(pos), supertile.getWorld().isRemote); }
Material mat = world.getBlockState(pos).getMaterial(); if(!MATERIALS.contains(mat)) return; Vec3i endDiff = new Vec3i(doX ? range : 0, doY ? rangeY * 2 - 1 : 0, doZ ? range : 0); ToolCommons.removeBlocksInIteration(player, stack, world, pos, beginDiff, endDiff, state -> MATERIALS.contains(state.getMaterial()), isTipped(stack));
@Override public ActionResult<ItemStack> onItemRightClick( final World w, final EntityPlayer p, final EnumHand hand ) { final RayTraceResult target = this.rayTrace( w, p, true ); if( target == null ) { return new ActionResult<>( EnumActionResult.FAIL, p.getHeldItem( hand ) ); } else { if( target.typeOfHit == RayTraceResult.Type.BLOCK ) { final IBlockState state = w.getBlockState( target.getBlockPos() ); if( state.getMaterial() == Material.LAVA || state.getMaterial() == Material.WATER ) { if( Platform.hasPermissions( new DimensionalCoord( w, target.getBlockPos() ), p ) ) { this.onItemUse( p, w, target.getBlockPos(), hand, EnumFacing.UP, 0.0F, 0.0F, 0.0F ); } } } } return new ActionResult<>( EnumActionResult.SUCCESS, p.getHeldItem( hand ) ); }
/** * 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 ); }
@SubscribeEvent public void onBlockDrops(HarvestDropsEvent event) { if(event.getHarvester() != null && event.getState() != null && event.getDrops() != null && event.getDrops().isEmpty() && !event.getHarvester().getHeldItemMainhand().isEmpty() && event.getHarvester().getHeldItemMainhand().getItem() == this && event.getState().getMaterial() == Material.GLASS && event.getState().getBlock().canSilkHarvest(event.getWorld(), event.getPos(), event.getState(), event.getHarvester())) event.getDrops().add(new ItemStack(event.getState().getBlock(), 1, event.getState().getBlock().getMetaFromState(event.getState()))); }
IBlockState state = entity.world.getBlockState(pos.getBlockPos()); Material mat = state.getMaterial(); if(ToolCommons.materialsPick.contains(mat)) typeToFind = ToolType.PICK;
@Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { TileEntity tile = world.getTileEntity(pos); if(world.isRemote) return true; ItemStack currentStack = player.getHeldItem(hand); if(!currentStack.isEmpty() && Block.getBlockFromItem(currentStack.getItem()) != null && tile instanceof TileCamo) { TileCamo camo = (TileCamo) tile; IBlockState changeState = Block.getBlockFromItem(currentStack.getItem()).getStateForPlacement(world, pos, side, hitX, hitY, hitZ, currentStack.getItemDamage(), player); if(isValidBlock(changeState) && !(changeState.getBlock() instanceof BlockCamo) && changeState.getMaterial() != Material.AIR) { camo.camoState = changeState; world.notifyBlockUpdate(pos, state, state, 8); return true; } } return false; }
@Override public void onUpdate() { super.onUpdate(); if(!supertile.getWorld().isRemote && mana == 0) { List<EntityTNTPrimed> tnts = supertile.getWorld().getEntitiesWithinAABB(EntityTNTPrimed.class, new AxisAlignedBB(supertile.getPos().add(-RANGE, -RANGE, -RANGE), supertile.getPos().add(RANGE + 1, RANGE + 1, RANGE + 1))); for(EntityTNTPrimed tnt : tnts) { if(tnt.getFuse() == 1 && !tnt.isDead && !supertile.getWorld().getBlockState(new BlockPos(tnt)).getMaterial().isLiquid()) { tnt.playSound(SoundEvents.ENTITY_GENERIC_EXPLODE, 0.2F, (1F + (supertile.getWorld().rand.nextFloat() - supertile.getWorld().rand.nextFloat()) * 0.2F) * 0.7F); tnt.setDead(); mana += getMaxMana(); sync(); getWorld().addBlockEvent(getPos(), supertile.getBlockType(), EXPLODE_EFFECT_EVENT, tnt.getEntityId()); break; } } } }
@Override public void onUpdate() { super.onUpdate(); if(supertile.getWorld().isRemote || redstoneSignal > 0) return; if(ticksExisted % 30 == 0 && mana >= COST) { BlockPos pos = new BlockPos( supertile.getPos().getX() - RANGE + supertile.getWorld().rand.nextInt(RANGE * 2 + 1), supertile.getPos().getY() + RANGE, supertile.getPos().getZ() - RANGE + supertile.getWorld().rand.nextInt(RANGE * 2 + 1) ); BlockPos up = pos.up(); for(int i = 0; i < RANGE * 2; i++) { IBlockState stateAbove = supertile.getWorld().getBlockState(up); Block blockAbove = stateAbove.getBlock(); if((supertile.getWorld().isAirBlock(up) || blockAbove.isReplaceable(supertile.getWorld(), up)) && stateAbove.getMaterial() != Material.WATER && ModBlocks.flower.canPlaceBlockAt(supertile.getWorld(), up)) { EnumDyeColor color = EnumDyeColor.byMetadata(supertile.getWorld().rand.nextInt(16)); IBlockState state = ModBlocks.flower.getDefaultState().withProperty(BotaniaStateProps.COLOR, color); if(ConfigHandler.blockBreakParticles) supertile.getWorld().playEvent(2001, up, Block.getStateId(state)); supertile.getWorld().setBlockState(up, state, 1 | 2); mana -= COST; sync(); break; } up = pos; pos = pos.down(); } } }
@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; }
if(rtr != null) { if (rtr.typeOfHit == net.minecraft.util.math.RayTraceResult.Type.BLOCK) { if(event.getWorld().getBlockState(rtr.getBlockPos()).getMaterial() == Material.WATER) { if(!event.getWorld().isRemote) { equipped.shrink(1);
@Override public void onUpdate() { super.onUpdate(); if(supertile.getWorld().isRemote) return; if(ticksExisted % 200 == 0) sync(); if(mana > COST_PER_TICK) { mana -= COST_PER_TICK; if(ticksExisted % 10 == 0 && range < getRange()) range++; for(BlockPos pos : BlockPos.getAllInBoxMutable(getPos().add(-range, -range, -range), getPos().add(range, range, range))) { if(getPos().distanceSq(pos) < range * range) { IBlockState state = supertile.getWorld().getBlockState(pos); if(state.getMaterial() == Material.WATER) { supertile.getWorld().setBlockState(pos, ModBlocks.fakeAir.getDefaultState(), 2); TileFakeAir air = (TileFakeAir) supertile.getWorld().getTileEntity(pos); air.setFlower(supertile); } } } } }
final Material mat = state.getMaterial();
if( lava && j < y && w.getBlockState( i, j, k ).getMaterial().isSolid() )