Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Lots of fixes.
  • Loading branch information
alcatrazEscapee committed Jul 3, 2018
1 parent fbacd3c commit dfab991
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 23 deletions.
23 changes: 11 additions & 12 deletions src/main/java/net/dries007/tfc/CommonEventHandler.java
Expand Up @@ -137,7 +137,7 @@ If nothing happens (as per vanilla behavior, even if this event causes something
}
}
}
if (Helpers.doesStackMatchOre(stack, "logWood"))
if (Helpers.doesStackMatchOre(stack, "logWood") && player.isSneaking())
{
EnumFacing facing = event.getFace();
if (facing != null)
Expand Down Expand Up @@ -213,17 +213,6 @@ If nothing happens (as per vanilla behavior, even if this event causes something
return;
}

// Ingots are taken care of here
if (stack.getItem() instanceof IPlacableItem)
{
IPlacableItem item = (IPlacableItem) stack.getItem();
if (item.placeItemInWorld(world, pos, stack, event.getFace(), player))
{
player.setHeldItem(event.getHand(), Helpers.consumeItem(stack, player, 1));
return;
}
}

// Kiln Pottery
IFireable fireable = IFireable.fromItem(event.getItemStack().getItem());
if (fireable != null && event.getEntityPlayer().isSneaking() && event.getFace() == EnumFacing.UP)
Expand All @@ -248,5 +237,15 @@ If nothing happens (as per vanilla behavior, even if this event causes something
event.setCanceled(true);
}
}

// All items that can should use this implementation instead of the other exceptions (which are for items that can't implement IPlacableItem)
if (stack.getItem() instanceof IPlacableItem)
{
IPlacableItem item = (IPlacableItem) stack.getItem();
if (item.placeItemInWorld(world, pos, stack, event.getFace(), player))
{
player.setHeldItem(event.getHand(), Helpers.consumeItem(stack, player, 1));
}
}
}
}
Expand Up @@ -12,16 +12,17 @@

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import mcp.MethodsReturnNonnullByDefault;
import net.dries007.tfc.objects.Metal;
Expand All @@ -44,21 +45,26 @@ public static ItemStack get(Metal metal, int amount)
}

public final Metal metal;
private static final AxisAlignedBB ANVIL_AABB = new AxisAlignedBB(0.1875d, 0d, 0d, 0.625d, 0.625, 1d);

public BlockAnvilTFC(Metal metal)
{
super(Material.IRON);

this.metal = metal;
if (MAP.put(metal, this) != null) throw new IllegalStateException("There can only be one.");

setHardness(3.0F);
setResistance(10F);
setHarvestLevel("pickaxe", 0);
}

@Override
/*@Override
@SuppressWarnings("deprecation")
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}*/

@Override
@SuppressWarnings("deprecation")
Expand All @@ -78,4 +84,19 @@ public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World wo
{
return new ItemStack(ItemAnvil.get(metal, Metal.ItemType.ANVIL));
}

@Override
@SuppressWarnings("deprecation")
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return ANVIL_AABB;
}

@SideOnly(Side.CLIENT)
@Override
@SuppressWarnings("deprecation")
public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World worldIn, BlockPos pos)
{
return getBoundingBox(state, worldIn, pos);
}
}
Expand Up @@ -12,14 +12,12 @@
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.InventoryHelper;
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.AxisAlignedBB;
Expand Down Expand Up @@ -62,7 +60,7 @@ public boolean isFullCube(IBlockState state)
return false;
}

@Override
/*@Override
@SuppressWarnings("deprecation")
public EnumBlockRenderType getRenderType(IBlockState state)
{
Expand All @@ -74,7 +72,7 @@ public EnumBlockRenderType getRenderType(IBlockState state)
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}*/

@Override
@SuppressWarnings("deprecation")
Expand Down
Expand Up @@ -7,21 +7,27 @@
package net.dries007.tfc.objects.blocks.metal;

import java.util.EnumMap;
import java.util.Random;
import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import mcp.MethodsReturnNonnullByDefault;
import net.dries007.tfc.objects.Metal;
import net.dries007.tfc.objects.items.metal.ItemSheet;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
Expand Down Expand Up @@ -49,6 +55,9 @@ public BlockSheet(Metal metal)
this.metal = metal;
if (MAP.put(metal, this) != null) throw new IllegalStateException("There can only be one.");

setHardness(2.5F);
setResistance(10F);
setHarvestLevel("pickaxe", 0);
this.setDefaultState(blockState.getBaseState().withProperty(FACE, EnumFacing.NORTH));
}

Expand Down Expand Up @@ -76,7 +85,30 @@ public boolean isFullCube(IBlockState state)
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return FULL_BLOCK_AABB; // todo: proper bounding box
switch (state.getValue(FACE))
{
case UP:
return new AxisAlignedBB(0d, 0d, 0d, 1d, 0.0625d, 1d);
case DOWN:
return new AxisAlignedBB(0d, 0.9375d, 0d, 1d, 1d, 1d);
case EAST:
return new AxisAlignedBB(0d, 0d, 0d, 0.0625d, 1d, 1d);
case WEST:
return new AxisAlignedBB(0.9375d, 0d, 0d, 1d, 1d, 1d);
case SOUTH:
return new AxisAlignedBB(0d, 0d, 0d, 1d, 1d, 0.0625d);
case NORTH:
return new AxisAlignedBB(0d, 0d, 0.9375d, 1d, 1d, 1d);
}
return FULL_BLOCK_AABB;
}

@SideOnly(Side.CLIENT)
@Override
@SuppressWarnings("deprecation")
public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World worldIn, BlockPos pos)
{
return getBoundingBox(state, worldIn, pos);
}

@SuppressWarnings("deprecation")
Expand All @@ -91,4 +123,10 @@ protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, FACE);
}

@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return ItemSheet.get(metal, Metal.ItemType.SHEET);
}
}
Expand Up @@ -9,8 +9,10 @@

import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

Expand Down Expand Up @@ -62,6 +64,8 @@ public boolean placeItemInWorld(World world, BlockPos pos, ItemStack stack, Enum
{
ItemAnvil anvil = (ItemAnvil) stack.getItem();
world.setBlockState(pos.offset(facing), BlockAnvilTFC.get(anvil.metal).getDefaultState());

world.playSound(null, pos.offset(facing), SoundEvents.BLOCK_ANVIL_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
return true;
}
Expand Down
Expand Up @@ -8,8 +8,10 @@
import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
Expand Down Expand Up @@ -55,6 +57,7 @@ public boolean placeItemInWorld(World world, BlockPos pos, ItemStack stack, Enum
te.setMetal(item.metal);
te.setCount(1);
}
world.playSound(null, pos.up(), SoundEvents.BLOCK_ANVIL_PLACE, SoundCategory.BLOCKS, 0.3F, 1.5F);

}
return true;
Expand Down
Expand Up @@ -6,8 +6,10 @@
package net.dries007.tfc.objects.items.metal;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

Expand All @@ -31,6 +33,7 @@ public boolean placeItemInWorld(World world, BlockPos pos, ItemStack stack, Enum
{
ItemSheet sheet = (ItemSheet) stack.getItem();
world.setBlockState(pos.offset(facing), BlockSheet.get(sheet.metal).getDefaultState().withProperty(FACE, facing));
world.playSound(null, pos.offset(facing), SoundEvents.BLOCK_METAL_PLACE, SoundCategory.BLOCKS, 1.0f, 1.0f);
return true;
}
return false;
Expand Down
Expand Up @@ -14,11 +14,10 @@
import net.dries007.tfc.objects.Size;
import net.dries007.tfc.objects.Weight;
import net.dries007.tfc.objects.items.ItemBlockTFC;
import net.dries007.tfc.util.IPlacableItem;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class ItemLogTFC extends ItemBlockTFC implements IPlacableItem
public class ItemLogTFC extends ItemBlockTFC
{
public ItemLogTFC(Block block)
{
Expand Down

0 comments on commit dfab991

Please sign in to comment.