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){ public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit){
if (!world.isRemote) { if (!world.isRemote) {
if (world.getTileEntity(pos) instanceof TileEntityBioReactor) { 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; return ActionResultType.SUCCESS;

View file

@ -1,20 +1,18 @@
package de.ellpeck.actuallyadditions.common.blocks; 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.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.common.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.common.tile.TileEntityCanolaPress; import de.ellpeck.actuallyadditions.common.tile.TileEntityCanolaPress;
import net.minecraft.block.Block; import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.ActionResultType;
import net.minecraft.util.EnumHand; import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos; 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.World;
import net.minecraftforge.common.ToolType;
import javax.annotation.Nullable;
public class BlockCanolaPress extends BlockContainerBase { public class BlockCanolaPress extends BlockContainerBase {
@ -22,32 +20,35 @@ public class BlockCanolaPress extends BlockContainerBase {
super(STONE_PROPS); super(STONE_PROPS);
} }
@Override // @Override
public boolean isFullCube(IBlockState state) { // public boolean isFullCube(IBlockState state) {
return false; // return false;
} // }
//
// @Override
// public boolean isOpaqueCube(IBlockState state) {
// return false;
// }
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}
@Nullable
@Override @Override
public TileEntity createNewTileEntity(World world, int par2) { public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return new TileEntityCanolaPress(); return new TileEntityCanolaPress();
} }
@Override @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) { if (!world.isRemote) {
TileEntityCanolaPress press = (TileEntityCanolaPress) world.getTileEntity(pos); TileEntityCanolaPress press = (TileEntityCanolaPress) world.getTileEntity(pos);
if (press != null) { if (press != null) {
if (!this.tryUseItemOnTank(player, hand, press.tank)) { 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; 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.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.common.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.common.tile.TileEntityCoalGenerator; import de.ellpeck.actuallyadditions.common.tile.TileEntityCoalGenerator;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal; import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.block.state.IBlockState; import net.minecraft.particles.ParticleTypes;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Mirror; import net.minecraft.util.ActionResultType;
import net.minecraft.util.Rotation; import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos; 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.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.ToolType; 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; import java.util.Random;
public class BlockCoalGenerator extends BlockContainerBase { public class BlockCoalGenerator extends BlockContainerBase {
public BlockCoalGenerator() { public BlockCoalGenerator() {
super(Block.Properties.create(Material.ROCK) super(Block.Properties.create(Material.ROCK)
.hardnessAndResistance(1.5f, 10.0f) .hardnessAndResistance(1.5f, 10.0f)
@ -35,80 +30,56 @@ public class BlockCoalGenerator extends BlockContainerBase {
.tickRandomly()); .tickRandomly());
} }
@Override // @Override
public boolean isFullCube(IBlockState state) { // public boolean isFullCube(IBlockState state) {
return false; // return false;
} // }
//
// @Override
// public boolean isOpaqueCube(IBlockState state) {
// return false;
// }
@Nullable
@Override @Override
public boolean isOpaqueCube(IBlockState state) { public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return false;
}
@Override
public TileEntity createNewTileEntity(World world, int par2) {
return new TileEntityCoalGenerator(); return new TileEntityCoalGenerator();
} }
@Override @Override
@SideOnly(Side.CLIENT) public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) {
TileEntity tile = world.getTileEntity(pos); TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityCoalGenerator) { if (tile instanceof TileEntityCoalGenerator) {
if (((TileEntityCoalGenerator) tile).currentBurnTime > 0) { if (((TileEntityCoalGenerator) tile).currentBurnTime > 0) {
for (int i = 0; i < 5; i++) { 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 @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) { if (!world.isRemote) {
TileEntityCoalGenerator press = (TileEntityCoalGenerator) world.getTileEntity(pos); TileEntityCoalGenerator press = (TileEntityCoalGenerator) world.getTileEntity(pos);
if (press != null) { 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 true;
} }
@Override return ActionResultType.SUCCESS;
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) { }
world.setBlockState(pos, state.withProperty(BlockHorizontal.FACING, player.getHorizontalFacing().getOpposite()), 2); return super.onBlockActivated(state, world, pos, player, hand, hit);
super.onBlockPlacedBy(world, pos, state, player, stack);
} }
@Override // @Override
public EnumRarity getRarity(ItemStack stack) { // public IBlockState withRotation(IBlockState state, Rotation rot) {
return EnumRarity.RARE; // return state.withProperty(BlockHorizontal.FACING, rot.rotate(state.getValue(BlockHorizontal.FACING)));
} // }
//
@Override // @Override
public IBlockState getStateFromMeta(int meta) { // public IBlockState withMirror(IBlockState state, Mirror mirror) {
return this.getDefaultState().withProperty(BlockHorizontal.FACING, EnumFacing.byHorizontalIndex(meta)); // return this.withRotation(state, mirror.toRotation(state.getValue(BlockHorizontal.FACING)));
} // }
@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)));
}
} }

View file

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

View file

@ -13,6 +13,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank; import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.capability.templates.FluidTank;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; 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.FluidRegistry;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank; import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.capability.templates.FluidTank;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreIngredient; import net.minecraftforge.oredict.OreIngredient;