mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-19 19:49:41 +00:00
Clean up PR formatting
This commit is contained in:
1 parent
c497bb516e
commit
214328c239
2 files changed
+43
-45
No files matched your search
@@ -1,7 +1,5 @@
|
||||
package slimeknights.mantle.block;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.BlockSlab;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
@@ -15,6 +13,8 @@ import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class EnumBlockSlab<E extends Enum<E> & EnumBlock.IEnumMeta & IStringSerializable> extends BlockSlab {
|
||||
|
||||
public final PropertyEnum<E> prop;
|
||||
@@ -57,25 +57,24 @@ public abstract class EnumBlockSlab<E extends Enum<E> & EnumBlock.IEnumMeta & IS
|
||||
*/
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return this.getDefaultState().withProperty(prop, fromMeta(meta & 7))
|
||||
.withProperty(HALF, (meta & 8) == 0 ? BlockSlab.EnumBlockHalf.BOTTOM : BlockSlab.EnumBlockHalf.TOP);
|
||||
return this.getDefaultState()
|
||||
.withProperty(prop, fromMeta(meta & 7))
|
||||
.withProperty(HALF, (meta & 8) == 0 ? BlockSlab.EnumBlockHalf.BOTTOM : BlockSlab.EnumBlockHalf.TOP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the BlockState into the correct metadata value
|
||||
*/
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state)
|
||||
{
|
||||
int i = 0;
|
||||
i = i | state.getValue(prop).getMeta();
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
int i = 0;
|
||||
i = i | state.getValue(prop).getMeta();
|
||||
|
||||
if (state.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP)
|
||||
{
|
||||
i |= 8;
|
||||
}
|
||||
if(state.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP) {
|
||||
i |= 8;
|
||||
}
|
||||
|
||||
return i;
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,29 +89,30 @@ public abstract class EnumBlockSlab<E extends Enum<E> & EnumBlock.IEnumMeta & IS
|
||||
|
||||
return values[meta];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IProperty<?> getVariantProperty() {
|
||||
return prop;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Comparable<?> getTypeForItem(ItemStack stack) {
|
||||
return fromMeta(stack.getItemDamage() & 7);
|
||||
return fromMeta(stack.getItemDamage() & 7);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(int meta) {
|
||||
return super.getUnlocalizedName() + "." + fromMeta(meta & 7).getName();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the full variant of the slab, as double slabs are not used here
|
||||
*
|
||||
* @param state Input slab state, in most cases state.getValue() with a switch is all you need
|
||||
* @return An IBlockState of the full block
|
||||
*/
|
||||
public abstract IBlockState getFullBlock(IBlockState state);
|
||||
|
||||
|
||||
// all our slabs are single
|
||||
@Override
|
||||
public boolean isDouble() {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package slimeknights.mantle.item;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockSlab;
|
||||
import net.minecraft.block.SoundType;
|
||||
@@ -22,10 +20,13 @@ import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.fml.common.registry.GameData;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import slimeknights.mantle.block.EnumBlockSlab;
|
||||
|
||||
public class ItemBlockSlab extends ItemBlockMeta {
|
||||
|
||||
|
||||
public EnumBlockSlab<?> slab;
|
||||
|
||||
public ItemBlockSlab(EnumBlockSlab<?> block) {
|
||||
@@ -39,18 +40,18 @@ public class ItemBlockSlab extends ItemBlockMeta {
|
||||
@Override
|
||||
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
||||
// don't place the slab if unable to edit
|
||||
if (stack.stackSize != 0 && player.canPlayerEdit(pos.offset(facing), facing, stack)) {
|
||||
|
||||
if(stack.stackSize != 0 && player.canPlayerEdit(pos.offset(facing), facing, stack)) {
|
||||
|
||||
// try placing the slab at the current position
|
||||
// note that this requires the slab to be extended on the side the block was clicked
|
||||
if (tryPlace(player, stack, world, pos, facing)) {
|
||||
if(tryPlace(player, stack, world, pos, facing)) {
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
// otherwise. try and place it in the block in front
|
||||
else if (this.tryPlace(player, stack, world, pos.offset(facing), null)) {
|
||||
else if(this.tryPlace(player, stack, world, pos.offset(facing), null)) {
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
return super.onItemUse(stack, player, world, pos, hand, facing, hitX, hitY, hitZ);
|
||||
}
|
||||
else {
|
||||
@@ -60,17 +61,16 @@ public class ItemBlockSlab extends ItemBlockMeta {
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean canPlaceBlockOnSide(World world, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack)
|
||||
{
|
||||
public boolean canPlaceBlockOnSide(World world, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack) {
|
||||
BlockPos oldPos = pos;
|
||||
Comparable<?> type = this.slab.getTypeForItem(stack);
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
|
||||
// first, try placing on the same block
|
||||
if (state.getBlock() == this.slab) {
|
||||
if(state.getBlock() == this.slab) {
|
||||
boolean flag = state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP;
|
||||
|
||||
if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && type == state.getValue(this.slab.prop) && this.slab.getFullBlock(state) != null) {
|
||||
if((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && type == state.getValue(this.slab.prop) && this.slab.getFullBlock(state) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -78,31 +78,31 @@ public class ItemBlockSlab extends ItemBlockMeta {
|
||||
// if that does not work, offset by one and try same type
|
||||
pos = pos.offset(side);
|
||||
state = world.getBlockState(pos);
|
||||
return state.getBlock() == this.slab && type == state.getValue(this.slab.prop) ? true : super.canPlaceBlockOnSide(world, oldPos, side, player, stack);
|
||||
return state.getBlock() == this.slab && type == state.getValue(this.slab.prop) || super.canPlaceBlockOnSide(world, oldPos, side, player, stack);
|
||||
}
|
||||
|
||||
private boolean tryPlace(EntityPlayer player, ItemStack stack, World worldIn, BlockPos pos, EnumFacing facing) {
|
||||
IBlockState state = worldIn.getBlockState(pos);
|
||||
Comparable<?> type = this.slab.getTypeForItem(stack);
|
||||
|
||||
if (state.getBlock() == this.slab) {
|
||||
if(state.getBlock() == this.slab) {
|
||||
BlockSlab.EnumBlockHalf half = state.getValue(BlockSlab.HALF);
|
||||
|
||||
if (type == state.getValue(this.slab.prop)
|
||||
&& (facing == null
|
||||
|| facing == EnumFacing.UP && half == BlockSlab.EnumBlockHalf.BOTTOM
|
||||
|| facing == EnumFacing.DOWN && half == BlockSlab.EnumBlockHalf.TOP)) {
|
||||
|
||||
if(type == state.getValue(this.slab.prop)
|
||||
&& (facing == null
|
||||
|| facing == EnumFacing.UP && half == BlockSlab.EnumBlockHalf.BOTTOM
|
||||
|| facing == EnumFacing.DOWN && half == BlockSlab.EnumBlockHalf.TOP)) {
|
||||
|
||||
IBlockState fullBlock = this.slab.getFullBlock(state);
|
||||
if(fullBlock != null) {
|
||||
AxisAlignedBB axisalignedbb = fullBlock.getCollisionBoundingBox(worldIn, pos);
|
||||
|
||||
if (axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(pos)) && worldIn.setBlockState(pos, fullBlock, 11)) {
|
||||
|
||||
if(axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(pos)) && worldIn.setBlockState(pos, fullBlock, 11)) {
|
||||
SoundType soundtype = fullBlock.getBlock().getSoundType();
|
||||
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
|
||||
--stack.stackSize;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,7 @@ public class ItemBlockSlab extends ItemBlockMeta {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// adds the "half=bottom" to the item model, so it does not error
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -123,10 +123,8 @@ public class ItemBlockSlab extends ItemBlockMeta {
|
||||
int meta = block.getMetaFromState(block.getDefaultState().withProperty(mappingProperty, o));
|
||||
String name = mappingProperty.getName(o);
|
||||
|
||||
ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(loc, "half=bottom,"
|
||||
+ mappingProperty.getName()
|
||||
+ "=" + name));
|
||||
ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(loc, "half=bottom," + mappingProperty.getName() + "=" + name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user