-
Notifications
You must be signed in to change notification settings - Fork 0
Grinder Block #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tanvirt
wants to merge
19
commits into
dev
Choose a base branch
from
grinder-block
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Grinder Block #96
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c9b42b9
Untrack log files
tanvirt e8d0e9f
Created all necessary classes for grinder. Broken
tanvirt e431f05
Grinder is operational
tanvirt 31d8119
Refactoring and code cleanup
tanvirt 55e2541
Merge with dev
tanvirt 2e475ed
Merge with dev
tanvirt 6344b6e
Merge with dev
tanvirt c3c6d4e
Some refactoring
tanvirt 98f6e54
Make grinding time customizable
tanvirt 5449797
Refactor grinder update on tick
tanvirt fdc9adc
Fix loading bar bug
tanvirt 78e9f8e
Minor formatting changes
tanvirt 621b14a
Refactor container slot transfer
tanvirt fae8084
Remove unnecessary comments
tanvirt ad7ae27
Fix parameter names
tanvirt 309eb83
Remove unused variable
tanvirt 5b1fada
Minor refactoring
tanvirt 2641b65
Removed ISidedInventory dependency
tanvirt 4f6a74f
Merge with dev
tanvirt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,3 +70,4 @@ gradle/ | |
| gradlew | ||
| gradlew.bat | ||
| logs/ | ||
| !/run/eula.txt | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula). | ||
| #Sun Mar 12 21:15:07 CDT 2017 | ||
| eula=true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
231 changes: 231 additions & 0 deletions
231
src/main/java/com/quantumindustries/minecraft/mod/blocks/grinder/BlockGrinder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,231 @@ | ||
| package com.quantumindustries.minecraft.mod.blocks.grinder; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| import com.quantumindustries.minecraft.mod.CustomMod; | ||
| import com.quantumindustries.minecraft.mod.blocks.ModBlocks; | ||
| import com.quantumindustries.minecraft.mod.tileentities.BlockContainerTileEntity; | ||
| import net.minecraft.block.SoundType; | ||
| import net.minecraft.block.material.Material; | ||
| import net.minecraft.block.properties.IProperty; | ||
| import net.minecraft.block.properties.PropertyDirection; | ||
| 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.inventory.InventoryHelper; | ||
| import net.minecraft.item.Item; | ||
| import net.minecraft.item.ItemStack; | ||
| import net.minecraft.tileentity.TileEntity; | ||
| import net.minecraft.util.EnumBlockRenderType; | ||
| import net.minecraft.util.EnumFacing; | ||
| import net.minecraft.util.EnumHand; | ||
| import net.minecraft.util.math.BlockPos; | ||
| import net.minecraft.util.math.RayTraceResult; | ||
| import net.minecraft.world.World; | ||
| import net.minecraftforge.fml.relauncher.Side; | ||
| import net.minecraftforge.fml.relauncher.SideOnly; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| public class BlockGrinder extends BlockContainerTileEntity<TileEntityGrinder> { | ||
|
|
||
| public static final PropertyDirection FACING = PropertyDirection.create( | ||
| "facing", EnumFacing.Plane.HORIZONTAL | ||
| ); | ||
| private boolean hasTileEntity; | ||
|
|
||
| public BlockGrinder() { | ||
| super(Material.ROCK, "blockGrinder"); | ||
| setDefaultState(blockState.getBaseState().withProperty( | ||
| FACING, | ||
| EnumFacing.NORTH | ||
| )); | ||
| hasTileEntity = false; | ||
| blockSoundType = SoundType.SNOW; | ||
| blockParticleGravity = 1.0f; | ||
| slipperiness = 0.6f; | ||
| lightOpacity = 20; | ||
| setTickRandomly(false); | ||
| useNeighborBrightness = false; | ||
| } | ||
|
|
||
| @Override | ||
| public Item getItemDropped(IBlockState state, Random rand, int fortune) { | ||
| return Item.getItemFromBlock(ModBlocks.blockGrinder); | ||
| } | ||
|
|
||
| @Override | ||
| public void onBlockAdded(World world, BlockPos blockPos, IBlockState blockState) { | ||
| if(!world.isRemote) { | ||
| EnumFacing enumFacing = getUnblockedFace( | ||
| world, | ||
| blockPos, | ||
| blockState | ||
| ); | ||
|
|
||
| world.setBlockState( | ||
| blockPos, | ||
| blockState.withProperty(FACING, enumFacing), | ||
| 2 | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onBlockActivated(World world, BlockPos blockPos, | ||
| IBlockState blockState, EntityPlayer player, | ||
| EnumHand hand, ItemStack stack, EnumFacing facing, | ||
| float hitX, float hitY, float hitZ) { | ||
| if(!world.isRemote) { | ||
| player.openGui( | ||
| CustomMod.instance, | ||
| CustomMod.GUI.GRINDER.ordinal(), | ||
| world, | ||
| blockPos.getX(), | ||
| blockPos.getY(), | ||
| blockPos.getZ() | ||
| ); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public TileEntity createNewTileEntity(World worldIn, int meta) { | ||
| return new TileEntityGrinder(); | ||
| } | ||
|
|
||
| @Override | ||
| public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, | ||
| float hitX, float hitY, float hitZ, int meta, | ||
| EntityLivingBase placer, ItemStack stack) { | ||
| return getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()); | ||
| } | ||
|
|
||
| @Override | ||
| public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, | ||
| EntityLivingBase placer, ItemStack stack) { | ||
| worldIn.setBlockState(pos, state.withProperty( | ||
| FACING, | ||
| placer.getHorizontalFacing().getOpposite()), | ||
| 2 | ||
| ); | ||
|
|
||
| if(stack.hasDisplayName()) { | ||
| TileEntity tileEntity = worldIn.getTileEntity(pos); | ||
|
|
||
| if(tileEntity instanceof TileEntityGrinder) { | ||
| ((TileEntityGrinder) tileEntity).setCustomInventoryName(stack.getDisplayName()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { | ||
| if(!hasTileEntity) { | ||
| TileEntity tileEntity = worldIn.getTileEntity(pos); | ||
|
|
||
| if(tileEntity instanceof TileEntityGrinder) { | ||
| InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityGrinder) tileEntity); | ||
| worldIn.updateComparatorOutputLevel(pos, this); | ||
| } | ||
| } | ||
|
|
||
| super.breakBlock(worldIn, pos, state); | ||
| } | ||
|
|
||
| @Override | ||
| @SideOnly(Side.CLIENT) | ||
| public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, | ||
| BlockPos pos, EntityPlayer player) { | ||
| return new ItemStack(Item.getItemFromBlock(ModBlocks.blockGrinder)); | ||
| } | ||
|
|
||
| @Override | ||
| public EnumBlockRenderType getRenderType(IBlockState blockState) { | ||
| return EnumBlockRenderType.MODEL; | ||
| } | ||
|
|
||
| @SuppressWarnings("deprecation") | ||
| @Override | ||
| public IBlockState getStateFromMeta(int meta) { | ||
| EnumFacing enumFacing = EnumFacing.getFront(meta); | ||
|
|
||
| if(enumFacing.getAxis() == EnumFacing.Axis.Y) { | ||
| enumFacing = EnumFacing.NORTH; | ||
| } | ||
|
|
||
| return getDefaultState().withProperty(FACING, enumFacing); | ||
| } | ||
|
|
||
| @Override | ||
| public int getMetaFromState(IBlockState state) { | ||
| return state.getValue(FACING).getIndex(); | ||
| } | ||
|
|
||
| @Override | ||
| public Class<TileEntityGrinder> getTileEntityClass() { | ||
| return TileEntityGrinder.class; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public TileEntityGrinder createTileEntity(World world, IBlockState state) { | ||
| return new TileEntityGrinder(); | ||
| } | ||
|
|
||
| @Override | ||
| protected BlockStateContainer createBlockState() { | ||
| return new BlockStateContainer(this, new IProperty[] { FACING }); | ||
| } | ||
|
|
||
| private EnumFacing getUnblockedFace(World world, BlockPos blockPos, IBlockState blockState) { | ||
| IBlockState blockToNorth = world.getBlockState(blockPos.north()); | ||
| IBlockState blockToSouth = world.getBlockState(blockPos.south()); | ||
| IBlockState blockToWest = world.getBlockState(blockPos.west()); | ||
| IBlockState blockToEast = world.getBlockState(blockPos.east()); | ||
|
|
||
| EnumFacing enumFacing = blockState.getValue(FACING); | ||
|
|
||
| if(shouldFaceSouth(blockToNorth, blockToSouth, enumFacing)) { | ||
| enumFacing = EnumFacing.SOUTH; | ||
| } | ||
| else if(shouldFaceNorth(blockToNorth, blockToSouth, enumFacing)) { | ||
| enumFacing = EnumFacing.NORTH; | ||
| } | ||
| else if(shouldFaceEast(blockToWest, blockToEast, enumFacing)) { | ||
| enumFacing = EnumFacing.EAST; | ||
| } | ||
| else if(shouldFaceWest(blockToWest, blockToEast, enumFacing)) { | ||
| enumFacing = EnumFacing.WEST; | ||
| } | ||
|
|
||
| return enumFacing; | ||
| } | ||
|
|
||
| private boolean shouldFaceSouth(IBlockState blockToNorth, IBlockState blockToSouth, EnumFacing enumFacing) { | ||
| return enumFacing == EnumFacing.NORTH && | ||
| blockToNorth.isFullBlock() && | ||
| !blockToSouth.isFullBlock(); | ||
| } | ||
|
|
||
| private boolean shouldFaceNorth(IBlockState blockToNorth, IBlockState blockToSouth, EnumFacing enumFacing) { | ||
| return enumFacing == EnumFacing.SOUTH && | ||
| blockToSouth.isFullBlock() && | ||
| !blockToNorth.isFullBlock(); | ||
| } | ||
|
|
||
| private boolean shouldFaceEast(IBlockState blockToWest, IBlockState blockToEast, EnumFacing enumFacing) { | ||
| return enumFacing == EnumFacing.WEST && | ||
| blockToWest.isFullBlock() && | ||
| !blockToEast.isFullBlock(); | ||
| } | ||
|
|
||
| private boolean shouldFaceWest(IBlockState blockToWest, IBlockState blockToEast, EnumFacing enumFacing) { | ||
| return enumFacing == EnumFacing.EAST && | ||
| blockToEast.isFullBlock() && | ||
| !blockToWest.isFullBlock(); | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you have an inconsistency now because you were doing
World parWorldstyled variable names and now they are theWorld worldstyle. I prefer theWorld worldbut we definitely have to be consistent.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refer to my prior blame of IntelliJ and Forge