mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-06-28 15:39:09 +02:00
109 lines
3.9 KiB
Java
109 lines
3.9 KiB
Java
/*
|
|
* This file ("BlockFluidCollector.java") is part of the Actually Additions mod for Minecraft.
|
|
* It is created and owned by Ellpeck and distributed
|
|
* under the Actually Additions License to be found at
|
|
* http://ellpeck.de/actaddlicense
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
*
|
|
* © 2015-2017 Ellpeck
|
|
*/
|
|
|
|
package de.ellpeck.actuallyadditions.mod.blocks;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
|
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
|
|
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFluidCollector;
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFluidPlacer;
|
|
import net.minecraft.block.BlockDirectional;
|
|
import net.minecraft.block.SoundType;
|
|
import net.minecraft.block.material.Material;
|
|
import net.minecraft.block.state.BlockStateContainer;
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
import net.minecraft.item.EnumRarity;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraft.util.Direction;
|
|
import net.minecraft.util.Hand;
|
|
import net.minecraft.util.Mirror;
|
|
import net.minecraft.util.Rotation;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.World;
|
|
|
|
public class BlockFluidCollector extends BlockContainerBase {
|
|
|
|
private final boolean isPlacer;
|
|
|
|
public BlockFluidCollector(boolean isPlacer) {
|
|
super(Material.ROCK, this.name);
|
|
this.isPlacer = isPlacer;
|
|
this.setHarvestLevel("pickaxe", 0);
|
|
this.setHardness(1.5F);
|
|
this.setResistance(10.0F);
|
|
this.setSoundType(SoundType.STONE);
|
|
}
|
|
|
|
@Override
|
|
public TileEntity createNewTileEntity(IBlockReader worldIn) {
|
|
return this.isPlacer
|
|
? new TileEntityFluidPlacer()
|
|
: new TileEntityFluidCollector();
|
|
}
|
|
|
|
@Override
|
|
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
|
if (this.tryToggleRedstone(world, pos, player)) {
|
|
return true;
|
|
}
|
|
if (!world.isRemote) {
|
|
TileEntityFluidCollector collector = (TileEntityFluidCollector) world.getTileEntity(pos);
|
|
if (collector != null) {
|
|
if (!this.tryUseItemOnTank(player, hand, collector.tank)) {
|
|
player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.FLUID_COLLECTOR.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public EnumRarity getRarity(ItemStack stack) {
|
|
return EnumRarity.RARE;
|
|
}
|
|
|
|
@Override
|
|
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, EntityLivingBase player, ItemStack stack) {
|
|
int rotation = Direction.getDirectionFromEntityLiving(pos, player).ordinal();
|
|
world.setBlockState(pos, this.getStateFromMeta(rotation), 2);
|
|
|
|
super.onBlockPlacedBy(world, pos, state, player, stack);
|
|
}
|
|
|
|
@Override
|
|
public BlockState getStateFromMeta(int meta) {
|
|
return this.getDefaultState().withProperty(BlockDirectional.FACING, Direction.byIndex(meta));
|
|
}
|
|
|
|
@Override
|
|
public int getMetaFromState(BlockState state) {
|
|
return state.getValue(BlockDirectional.FACING).getIndex();
|
|
}
|
|
|
|
@Override
|
|
protected BlockStateContainer createBlockState() {
|
|
return new BlockStateContainer(this, BlockDirectional.FACING);
|
|
}
|
|
|
|
@Override
|
|
public BlockState withRotation(BlockState state, Rotation rot) {
|
|
return state.withProperty(BlockDirectional.FACING, rot.rotate(state.getValue(BlockDirectional.FACING)));
|
|
}
|
|
|
|
@Override
|
|
public BlockState withMirror(BlockState state, Mirror mirror) {
|
|
return this.withRotation(state, mirror.toRotation(state.getValue(BlockDirectional.FACING)));
|
|
}
|
|
}
|