Skip to content

Commit

Permalink
Clean up deprecation warnings and add a few comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightMiner committed Dec 15, 2019
1 parent 6ff3a66 commit e1e140a
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 176 deletions.
Expand Up @@ -70,29 +70,21 @@ protected ExtendedBlockState createBlockState() {
return new ExtendedBlockState(this, new IProperty<?>[]{TYPE, FACING}, new IUnlistedProperty[]{TEXTURE, BOOKS});
}

/**
* Convert the given metadata into a BlockState for this Block
*/
@Deprecated
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState()
.withProperty(TYPE, BookshelfType.fromMeta(meta & 3))
.withProperty(FACING, EnumFacing.getHorizontal(meta >> 2));
}

/**
* Convert the BlockState into the correct metadata value
*/
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(FACING).getHorizontalIndex() << 2
| state.getValue(TYPE).getMeta();
}

/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
@Deprecated
@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
return this.getStateFromMeta(meta).withProperty(FACING, placer.getHorizontalFacing().getOpposite());
Expand Down Expand Up @@ -153,6 +145,14 @@ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, En
return true;
}

/**
* Called when the shelf is clicked to determine the clicked book
* @param facing Side clicked
* @param clickX Click X coordinate, block reletive
* @param clickY Click Y coordinate, block relative
* @param clickZ Click Z coordinate, block relative
* @return Clicked book index
*/
private static int bookClicked(EnumFacing facing, float clickX, float clickY, float clickZ) {
// if we did not click between the shelves, ignore
if(clickY < 0.0625 || clickY > 0.9375) {
Expand Down Expand Up @@ -225,6 +225,7 @@ private static int bookClicked(EnumFacing facing, float clickX, float clickY, fl
TRACE_BOUNDS = builder.build();
}

@Deprecated
@Nonnull
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
Expand All @@ -242,13 +243,11 @@ public RayTraceResult collisionRayTrace(IBlockState state, @Nonnull World world,
return Util.closestResult(list, end);
}


/*
* Redstone
*/

/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
// if powered, send updates for power
Expand All @@ -260,11 +259,13 @@ public void breakBlock(World world, BlockPos pos, IBlockState state) {
super.breakBlock(world, pos, state);
}

@Deprecated
@Override
public int getWeakPower(IBlockState state, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
return getPower(state, blockAccess, pos);
}

@Deprecated
@Override
public int getStrongPower(IBlockState state, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
if (state.getValue(FACING) != side) {
Expand All @@ -275,6 +276,13 @@ public int getStrongPower(IBlockState state, IBlockAccess blockAccess, BlockPos

}

/**
* Gets the powered state of the block
* @param state Existing state
* @param blockAccess World access
* @param pos Position to check
* @return Power level between 0 and 15
*/
private int getPower(IBlockState state, IBlockAccess blockAccess, BlockPos pos) {
if(InspirationsBuilding.redstoneBook == null) {
return 0;
Expand All @@ -287,9 +295,7 @@ private int getPower(IBlockState state, IBlockAccess blockAccess, BlockPos pos)
return 0;
}

/**
* Can this block provide power. Only wire currently seems to have this change based on its state.
*/
@Deprecated
@Override
public boolean canProvidePower(IBlockState state) {
// ensure we have the redstone book, since it comes from the redstone module
Expand All @@ -300,6 +306,7 @@ public boolean canProvidePower(IBlockState state) {
/*
* Block properties
*/

@Override
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer() {
Expand All @@ -319,28 +326,32 @@ public IBlockState getExtendedState(@Nonnull IBlockState state, IBlockAccess wor
return super.getExtendedState(state, world, pos);
}

@Override
@Deprecated
@Override
public BlockFaceShape getBlockFaceShape(IBlockAccess world, IBlockState state, BlockPos pos, EnumFacing side) {
// allows placing stuff on the back
return side == state.getValue(FACING).getOpposite() ? BlockFaceShape.SOLID : BlockFaceShape.UNDEFINED;
}

@Deprecated
@Override
public boolean isFullCube(IBlockState state) {
return false;
}

@Deprecated
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}

@Deprecated
@Override
public IBlockState withRotation(IBlockState state, Rotation rot) {
return state.withProperty(FACING, rot.rotate(state.getValue(FACING)));
}

@Deprecated
@Override
public IBlockState withMirror(IBlockState state, Mirror mirror) {
return state.withRotation(mirror.toRotation(state.getValue(FACING)));
Expand Down
@@ -1,9 +1,5 @@
package knightminer.inspirations.building.block;

import java.util.Locale;

import javax.annotation.Nonnull;

import knightminer.inspirations.building.tileentity.TileEnlightenedBush;
import knightminer.inspirations.library.client.ClientUtil;
import knightminer.inspirations.library.util.TextureBlockUtil;
Expand Down Expand Up @@ -32,6 +28,9 @@
import slimeknights.mantle.block.EnumBlock;
import slimeknights.mantle.property.PropertyString;

import javax.annotation.Nonnull;
import java.util.Locale;

public class BlockEnlightenedBush extends EnumBlock<BlockEnlightenedBush.LightsType> implements ITileEntityProvider {

public static final PropertyEnum<LightsType> LIGHTS = PropertyEnum.create("lights", LightsType.class);
Expand Down Expand Up @@ -68,11 +67,13 @@ public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
/*
* Properties
*/
@Deprecated
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}

@Deprecated
@Override
public boolean causesSuffocation(IBlockState state) {
return false;
Expand Down
@@ -1,11 +1,5 @@
package knightminer.inspirations.building.block;

import java.util.Locale;
import java.util.Random;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import net.minecraft.block.Block;
import net.minecraft.block.BlockBush;
import net.minecraft.block.BlockDoublePlant.EnumPlantType;
Expand All @@ -24,6 +18,11 @@
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Locale;
import java.util.Random;

public class BlockFlower extends BlockBush implements IGrowable {
public static final PropertyEnum<FlowerType> TYPE = PropertyEnum.create("type", FlowerType.class);

Expand All @@ -41,6 +40,7 @@ protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, TYPE);
}

@Deprecated
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(TYPE, FlowerType.fromMeta(meta));
Expand All @@ -51,10 +51,6 @@ public int getMetaFromState(IBlockState state) {
return state.getValue(TYPE).getMeta();
}

/**
* Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
* returns the metadata of the dropped item based on the old metadata of the block.
*/
@Override
public int damageDropped(IBlockState state) {
return state.getValue(TYPE).getMeta();
Expand Down
@@ -1,7 +1,5 @@
package knightminer.inspirations.building.block;

import java.util.Random;

import knightminer.inspirations.building.InspirationsBuilding;
import net.minecraft.block.BlockDoor;
import net.minecraft.block.SoundType;
Expand All @@ -15,6 +13,8 @@
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import java.util.Random;

public class BlockGlassDoor extends BlockDoor {

public BlockGlassDoor() {
Expand All @@ -29,9 +29,6 @@ public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, Ent
// honestly have no idea what this code was doing, but it broke silk touching the door and it seems to work without it
}

/**
* Get the Item that this Block should drop when harvested.
*/
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return InspirationsBuilding.glassDoorItem;
Expand All @@ -52,17 +49,14 @@ protected ItemStack getSilkTouchDrop(IBlockState state) {
return new ItemStack(InspirationsBuilding.glassDoorItem);
}

/**
* Returns the quantity of items to drop on block destruction.
*/
@Override
public int quantityDropped(Random random) {
return 0;
}

@Deprecated
@Override
protected boolean canSilkHarvest() {
return true;
}

}
@@ -1,11 +1,11 @@
package knightminer.inspirations.building.block;

import java.util.Random;

import net.minecraft.block.BlockTrapDoor;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;

import java.util.Random;

public class BlockGlassTrapdoor extends BlockTrapDoor {

public BlockGlassTrapdoor() {
Expand All @@ -23,6 +23,7 @@ public int quantityDropped(Random random) {
return 0;
}

@Deprecated
@Override
protected boolean canSilkHarvest() {
return true;
Expand Down
@@ -1,7 +1,5 @@
package knightminer.inspirations.building.block;

import java.util.Locale;

import net.minecraft.block.BlockFalling;
import net.minecraft.block.BlockSapling;
import net.minecraft.block.SoundType;
Expand All @@ -21,6 +19,8 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.Locale;

public class BlockMulch extends BlockFalling {

protected static final AxisAlignedBB BOUNDS = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.9375D, 1.0D);
Expand All @@ -36,6 +36,7 @@ public BlockMulch() {
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}


/*
* Types
*/
Expand All @@ -45,18 +46,13 @@ protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, COLOR);
}

/**
* Convert the given metadata into a BlockState for this Block
*/
@Deprecated
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState()
.withProperty(COLOR, MulchColor.fromMeta(meta));
}

/**
* Convert the BlockState into the correct metadata value
*/
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(COLOR).getMeta();
Expand Down Expand Up @@ -87,7 +83,6 @@ public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos p
return plantable.getPlantType(world, pos.offset(direction)) == EnumPlantType.Plains && !(plantable instanceof BlockSapling);
}


public static enum MulchColor implements IStringSerializable {
PLAIN,
BROWN,
Expand Down

0 comments on commit e1e140a

Please sign in to comment.