/* * This file is part of GoodTime-Industrial, licensed under MIT License (MIT). * * Copyright (c) 2015 GoodTime Studio <https://github.com/GoodTimeStudio> * Copyright (c) contributors * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package com.mcgoodtime.productionline.blocks; import net.minecraft.block.BlockBush; import net.minecraft.block.BlockLiquid; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityBoat; import net.minecraft.init.Blocks; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.List; import java.util.Random; import static com.mcgoodtime.productionline.core.ProductionLine.*; /** * Yeah the water hyacinth block... For fun. * * @author liach */ public class BlockWaterHyacinth extends BlockBush { private final AxisAlignedBB box = new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 0.09375D, 0.9375D); public BlockWaterHyacinth() { super(Material.PLANTS); this.setUnlocalizedName("productionline.block.WaterHyacinth"); this.setCreativeTab(creativeTabPL); //this.setBlockTextureName(ProductionLine.RESOURCE_DOMAIN + ":" + "BlockWaterHyacinth"); this.setHardness(0.0F); this.setResistance(0.0F); this.setSoundType(SoundType.PLANT); this.setTickRandomly(true); } @Override public void randomTick(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull Random rand) { int changedX = rand.nextInt(5) - 3 + pos.getX(); int changedZ = rand.nextInt(5) - 3 + pos.getZ(); BlockPos check = new BlockPos(changedX, pos.getY(), changedZ); if ((world.isAirBlock(check)) && (this.canSustainBush(world.getBlockState(check.down())))) { world.setBlockState(pos, getDefaultState()); } } public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) { if (pos.getY() >= 0 && pos.getY() < 256) { IBlockState iblockstate = worldIn.getBlockState(pos.down()); Material material = iblockstate.getMaterial(); return material == Material.WATER && iblockstate.getValue(BlockLiquid.LEVEL) == 0 || material == Material.ICE; } else { return false; } } @Override protected boolean canSustainBush(IBlockState state) { return state.getBlock() == Blocks.WATER || state.getMaterial() == Material.ICE; } @Override @SuppressWarnings("deprecation") public void addCollisionBoxToList(IBlockState state, @Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull AxisAlignedBB entityBox, @Nonnull List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn) { if (!(entityIn instanceof EntityBoat)) { addCollisionBoxToList(pos, entityBox, collidingBoxes, box); } } /** * Called When an Entity Collided with the Block */ @Override public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) { super.onEntityCollidedWithBlock(worldIn, pos, state, entityIn); if (entityIn instanceof EntityBoat) { worldIn.destroyBlock(new BlockPos(pos), true); } } @Nonnull @Override public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return box; } }