More block porting work :D

This commit is contained in:
Michael 2020-09-09 17:16:41 +01:00
parent f44c4de74a
commit 2ae9ed307e
No known key found for this signature in database
GPG Key ID: 971C5B254742488F
6 changed files with 122 additions and 174 deletions

View File

@ -27,7 +27,8 @@ public class BlockBioReactor extends BlockContainerBase {
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit){
if (!world.isRemote) {
if (world.getTileEntity(pos) instanceof TileEntityBioReactor) {
// todo open gui: player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.BIO_REACTOR.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
// todo open gui:
// player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.BIO_REACTOR.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
}
}
return ActionResultType.SUCCESS;

View File

@ -1,20 +1,18 @@
package de.ellpeck.actuallyadditions.common.blocks;
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
import de.ellpeck.actuallyadditions.common.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.common.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.common.tile.TileEntityCanolaPress;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.common.ToolType;
import javax.annotation.Nullable;
public class BlockCanolaPress extends BlockContainerBase {
@ -22,32 +20,35 @@ public class BlockCanolaPress extends BlockContainerBase {
super(STONE_PROPS);
}
@Override
public boolean isFullCube(IBlockState state) {
return false;
}
// @Override
// public boolean isFullCube(IBlockState state) {
// return false;
// }
//
// @Override
// public boolean isOpaqueCube(IBlockState state) {
// return false;
// }
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}
@Nullable
@Override
public TileEntity createNewTileEntity(World world, int par2) {
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return new TileEntityCanolaPress();
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float par7, float par8, float par9) {
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
if (!world.isRemote) {
TileEntityCanolaPress press = (TileEntityCanolaPress) world.getTileEntity(pos);
if (press != null) {
if (!this.tryUseItemOnTank(player, hand, press.tank)) {
player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.CANOLA_PRESS.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
// todo: add back
// player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.CANOLA_PRESS.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
}
}
return true;
return ActionResultType.SUCCESS;
}
return true;
return super.onBlockActivated(state, world, pos, player, hand, hit);
}
}

View File

@ -1,32 +1,27 @@
package de.ellpeck.actuallyadditions.common.blocks;
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
import de.ellpeck.actuallyadditions.common.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.common.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.common.tile.TileEntityCoalGenerator;
import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.ToolType;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
import java.util.Random;
public class BlockCoalGenerator extends BlockContainerBase {
public BlockCoalGenerator() {
super(Block.Properties.create(Material.ROCK)
.hardnessAndResistance(1.5f, 10.0f)
@ -35,80 +30,56 @@ public class BlockCoalGenerator extends BlockContainerBase {
.tickRandomly());
}
@Override
public boolean isFullCube(IBlockState state) {
return false;
}
// @Override
// public boolean isFullCube(IBlockState state) {
// return false;
// }
//
// @Override
// public boolean isOpaqueCube(IBlockState state) {
// return false;
// }
@Nullable
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}
@Override
public TileEntity createNewTileEntity(World world, int par2) {
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return new TileEntityCoalGenerator();
}
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) {
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityCoalGenerator) {
if (((TileEntityCoalGenerator) tile).currentBurnTime > 0) {
for (int i = 0; i < 5; i++) {
world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, (double) pos.getX() + 0.5F, (double) pos.getY() + 1.0F, (double) pos.getZ() + 0.5F, 0.0D, 0.0D, 0.0D);
// todo: check count and speed params
world.spawnParticle(ParticleTypes.SMOKE, (double) pos.getX() + 0.5F, (double) pos.getY() + 1.0F, (double) pos.getZ() + 0.5F, i,0.0D, 0.0D, 0.0D, 1);
}
}
}
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9) {
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
if (!world.isRemote) {
TileEntityCoalGenerator press = (TileEntityCoalGenerator) world.getTileEntity(pos);
if (press != null) {
player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.COAL_GENERATOR.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
// todo: add back
// player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.COAL_GENERATOR.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
}
return true;
return ActionResultType.SUCCESS;
}
return true;
return super.onBlockActivated(state, world, pos, player, hand, hit);
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
world.setBlockState(pos, state.withProperty(BlockHorizontal.FACING, player.getHorizontalFacing().getOpposite()), 2);
super.onBlockPlacedBy(world, pos, state, player, stack);
}
@Override
public EnumRarity getRarity(ItemStack stack) {
return EnumRarity.RARE;
}
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(BlockHorizontal.FACING, EnumFacing.byHorizontalIndex(meta));
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(BlockHorizontal.FACING).getHorizontalIndex();
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, BlockHorizontal.FACING);
}
@Override
public IBlockState withRotation(IBlockState state, Rotation rot) {
return state.withProperty(BlockHorizontal.FACING, rot.rotate(state.getValue(BlockHorizontal.FACING)));
}
@Override
public IBlockState withMirror(IBlockState state, Mirror mirror) {
return this.withRotation(state, mirror.toRotation(state.getValue(BlockHorizontal.FACING)));
}
// @Override
// public IBlockState withRotation(IBlockState state, Rotation rot) {
// return state.withProperty(BlockHorizontal.FACING, rot.rotate(state.getValue(BlockHorizontal.FACING)));
// }
//
// @Override
// public IBlockState withMirror(IBlockState state, Mirror mirror) {
// return this.withRotation(state, mirror.toRotation(state.getValue(BlockHorizontal.FACING)));
// }
}

View File

@ -1,123 +1,96 @@
package de.ellpeck.actuallyadditions.common.blocks;
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
import de.ellpeck.actuallyadditions.common.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.common.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.common.tile.TileEntityCoffeeMachine;
import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.common.ToolType;
import javax.annotation.Nullable;
public class BlockCoffeeMachine extends BlockContainerBase {
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
private static final AxisAlignedBB AABB = new AxisAlignedBB(0.0625, 0, 0.0625, 1 - 0.0625, 1 - 0.0625 * 2, 1 - 0.0625);
// private static final AxisAlignedBB AABB = new AxisAlignedBB(0.0625, 0, 0.0625, 1 - 0.0625, 1 - 0.0625 * 2, 1 - 0.0625);
private static final VoxelShape SHAPE = Block.makeCuboidShape(1, 0, 1, 15, 14, 15); // might be wrong, correct is above
public BlockCoffeeMachine() {
super(Block.Properties.create(Material.ROCK)
.hardnessAndResistance(1.5f, 10.0f)
.harvestTool(ToolType.PICKAXE)
.sound(SoundType.STONE));
super(STONE_PROPS);
setDefaultState(getStateContainer().getBaseState().with(FACING, Direction.SOUTH));
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
return AABB;
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE;
}
@Override
public boolean isFullCube(IBlockState state) {
return false;
}
// @Override
// public boolean isFullCube(IBlockState state) {
// return false;
// }
//
// @Override
// public boolean isOpaqueCube(IBlockState state) {
// return false;
// }
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing f6, float f7, float f8, float f9) {
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
if (!world.isRemote) {
TileEntityCoffeeMachine machine = (TileEntityCoffeeMachine) world.getTileEntity(pos);
if (machine != null) {
if (!this.tryUseItemOnTank(player, hand, machine.tank)) {
player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.COFFEE_MACHINE.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
// todo: add back
// player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.COFFEE_MACHINE.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
}
}
return true;
return ActionResultType.SUCCESS;
}
return true;
return super.onBlockActivated(state, world, pos, player, hand, hit);
}
@Nullable
@Override
public TileEntity createNewTileEntity(World world, int meta) {
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return new TileEntityCoffeeMachine();
}
@Override
public EnumRarity getRarity(ItemStack stack) {
return EnumRarity.EPIC;
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder);
builder.add(FACING);
}
@Nullable
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
int rotation = MathHelper.floor(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
if (rotation == 0) {
world.setBlockState(pos, this.getStateFromMeta(0), 2);
}
if (rotation == 1) {
world.setBlockState(pos, this.getStateFromMeta(3), 2);
}
if (rotation == 2) {
world.setBlockState(pos, this.getStateFromMeta(1), 2);
}
if (rotation == 3) {
world.setBlockState(pos, this.getStateFromMeta(2), 2);
}
super.onBlockPlacedBy(world, pos, state, player, stack);
public BlockState getStateForPlacement(BlockItemUseContext context) {
return getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite());
}
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(BlockHorizontal.FACING, EnumFacing.byHorizontalIndex(meta));
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(BlockHorizontal.FACING).getHorizontalIndex();
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, BlockHorizontal.FACING);
}
@Override
public IBlockState withRotation(IBlockState state, Rotation rot) {
return state.withProperty(BlockHorizontal.FACING, rot.rotate(state.getValue(BlockHorizontal.FACING)));
}
@Override
public IBlockState withMirror(IBlockState state, Mirror mirror) {
return this.withRotation(state, mirror.toRotation(state.getValue(BlockHorizontal.FACING)));
}
// @Override
// public IBlockState withRotation(IBlockState state, Rotation rot) {
// return state.withProperty(BlockHorizontal.FACING, rot.rotate(state.getValue(BlockHorizontal.FACING)));
// }
//
// @Override
// public IBlockState withMirror(IBlockState state, Mirror mirror) {
// return this.withRotation(state, mirror.toRotation(state.getValue(BlockHorizontal.FACING)));
// }
}

View File

@ -13,6 +13,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.capability.templates.FluidTank;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

View File

@ -19,6 +19,7 @@ import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.capability.templates.FluidTank;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreIngredient;