-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add turntable, clean up some internal code
- Loading branch information
1 parent
f76d1d6
commit 9f1e665
Showing
26 changed files
with
809 additions
and
102 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
145 changes: 145 additions & 0 deletions
145
src/main/java/com/eerussianguy/firmalife/blocks/BlockTurntable.java
This file contains 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,145 @@ | ||
package com.eerussianguy.firmalife.blocks; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
import net.minecraft.block.material.Material; | ||
import net.minecraft.block.state.BlockStateContainer; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.init.Items; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.util.EnumHand; | ||
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.items.CapabilityItemHandler; | ||
import net.minecraftforge.items.IItemHandler; | ||
import net.minecraftforge.items.ItemHandlerHelper; | ||
|
||
import com.eerussianguy.firmalife.te.TETurntable; | ||
import mcp.MethodsReturnNonnullByDefault; | ||
import net.dries007.tfc.util.Helpers; | ||
|
||
import static com.eerussianguy.firmalife.init.StatePropertiesFL.CLAY; | ||
|
||
@ParametersAreNonnullByDefault | ||
@MethodsReturnNonnullByDefault | ||
public class BlockTurntable extends BlockNonCube | ||
{ | ||
private static final AxisAlignedBB SHAPE = new AxisAlignedBB(4.0D / 16, 0.0D, 4.0D / 16, 12.0D / 16, 5.0D / 16, 12.0D / 16); | ||
|
||
public BlockTurntable() | ||
{ | ||
super(Material.IRON); | ||
setHardness(1.0F); | ||
setResistance(1.0F); | ||
setDefaultState(getBlockState().getBaseState().withProperty(CLAY, 0)); | ||
} | ||
|
||
@Override | ||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) | ||
{ | ||
if (!world.isRemote && hand == EnumHand.MAIN_HAND) | ||
{ | ||
ItemStack held = player.getHeldItem(hand); | ||
if (player.isSneaking()) | ||
{ | ||
TETurntable te = Helpers.getTE(world, pos, TETurntable.class); | ||
if (te != null && te.hasPottery()) te.rotate(); | ||
return true; | ||
} | ||
if (held.getItem() == Items.CLAY_BALL) | ||
{ | ||
int clay = state.getValue(CLAY); | ||
if (clay < 4 && held.getCount() > 5) | ||
{ | ||
held.shrink(5); | ||
world.setBlockState(pos, state.withProperty(CLAY, clay + 1)); | ||
return true; | ||
} | ||
} | ||
else | ||
{ | ||
TETurntable te = Helpers.getTE(world, pos, TETurntable.class); | ||
if (te != null) | ||
{ | ||
IItemHandler cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); | ||
if (cap != null) | ||
{ | ||
ItemStack invStack = cap.getStackInSlot(0); | ||
if (invStack.isEmpty() && TETurntable.isPottery(held)) | ||
{ | ||
ItemStack leftover = cap.insertItem(0, held.splitStack(1), false); | ||
ItemHandlerHelper.giveItemToPlayer(player, leftover); | ||
return true; | ||
} | ||
else if (!invStack.isEmpty() && held.isEmpty()) | ||
{ | ||
ItemStack leftover = cap.extractItem(0, 1, false); | ||
ItemHandlerHelper.giveItemToPlayer(player, leftover); | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("deprecation") | ||
public IBlockState getStateFromMeta(int meta) | ||
{ | ||
return getDefaultState().withProperty(CLAY, meta); | ||
} | ||
|
||
@Override | ||
public int getMetaFromState(IBlockState state) | ||
{ | ||
return state.getValue(CLAY); | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
protected BlockStateContainer createBlockState() | ||
{ | ||
return new BlockStateContainer(this, CLAY); | ||
} | ||
|
||
@Override | ||
public boolean hasTileEntity(IBlockState state) | ||
{ | ||
return true; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public TileEntity createTileEntity(World world, IBlockState state) | ||
{ | ||
return new TETurntable(); | ||
} | ||
|
||
@Override | ||
public void breakBlock(World world, BlockPos pos, IBlockState state) | ||
{ | ||
TETurntable te = Helpers.getTE(world, pos, TETurntable.class); | ||
if (te != null) | ||
{ | ||
te.onBreakBlock(world, pos, state); | ||
} | ||
super.breakBlock(world, pos, state); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("deprecation") | ||
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) | ||
{ | ||
return SHAPE; | ||
} | ||
} |
This file contains 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 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 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
55 changes: 55 additions & 0 deletions
55
src/main/java/com/eerussianguy/firmalife/recipe/SandwichBasedRecipe.java
This file contains 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,55 @@ | ||
package com.eerussianguy.firmalife.recipe; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.annotation.Nonnull; | ||
|
||
import net.minecraft.inventory.InventoryCrafting; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.common.crafting.CraftingHelper; | ||
|
||
import net.dries007.tfc.api.capability.food.CapabilityFood; | ||
import net.dries007.tfc.api.capability.food.FoodData; | ||
import net.dries007.tfc.api.capability.food.IFood; | ||
import net.dries007.tfc.objects.recipes.ShapedDamageRecipe; | ||
|
||
public abstract class SandwichBasedRecipe extends ShapedDamageRecipe | ||
{ | ||
public SandwichBasedRecipe(ResourceLocation group, CraftingHelper.ShapedPrimer input, @Nonnull ItemStack result, int damage) | ||
{ | ||
super(group, input, result, damage); | ||
} | ||
|
||
@Override | ||
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World world) | ||
{ | ||
if (super.matches(inv, world)) | ||
{ | ||
List<FoodData> ingredients = new ArrayList<>(); | ||
getIngredients(inv, ingredients); | ||
return ingredients.size() > 0; | ||
} | ||
return false; | ||
} | ||
|
||
protected void getIngredients(InventoryCrafting inv, List<FoodData> ingredients) | ||
{ | ||
for (int i = 0; i < inv.getSizeInventory(); i++) | ||
{ | ||
ItemStack ingredientStack = inv.getStackInSlot(i); | ||
IFood ingredientCap = ingredientStack.getCapability(CapabilityFood.CAPABILITY, null); | ||
if (ingredientCap != null) | ||
{ | ||
if (ingredientCap.isRotten()) | ||
{ | ||
// Found a rotten ingredient, aborting | ||
ingredients.clear(); | ||
return; | ||
} | ||
ingredients.add(ingredientCap.getData()); | ||
} | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.