Skip to content

Commit

Permalink
add turntable, clean up some internal code
Browse files Browse the repository at this point in the history
  • Loading branch information
eerussianguy committed Jan 19, 2022
1 parent f76d1d6 commit 9f1e665
Show file tree
Hide file tree
Showing 26 changed files with 809 additions and 102 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ repositories {
}
}

version = "0.5.0"
version = "0.5.1"
group = 'com.eerussianguy.firmalife'
archivesBaseName = 'firmalife'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.eerussianguy.firmalife.te.TELeafMat;
import com.eerussianguy.firmalife.te.TEOven;
import com.eerussianguy.firmalife.te.TEString;
import com.eerussianguy.firmalife.te.TETurntable;
import net.dries007.tfc.api.capability.IMoldHandler;
import net.dries007.tfc.api.registries.TFCRegistries;
import net.dries007.tfc.api.types.Metal;
Expand Down Expand Up @@ -74,6 +75,7 @@ public static void registerModels(ModelRegistryEvent event)
ModelLoader.setCustomStateMapper(leaves, new StateMap.Builder().ignore(BlockFruitTreeLeaves.DECAYABLE).ignore(BlockFruitTreeLeaves.HARVESTABLE).build());
ModelLoader.setCustomStateMapper(BlocksFL.SPOUT, new StateMap.Builder().ignore(StatePropertiesFL.WATERED).ignore(StatePropertiesFL.NEEDS_SOURCE).build());
ModelLoader.setCustomStateMapper(BlocksFL.SPRINKLER, new StateMap.Builder().ignore(StatePropertiesFL.WATERED).ignore(StatePropertiesFL.NEEDS_SOURCE).build());
ModelLoader.setCustomStateMapper(BlocksFL.TURNTABLE, new StateMap.Builder().ignore(StatePropertiesFL.CLAY).build());

ModelLoader.setCustomModelResourceLocation(ItemsFL.CHEESECLOTH, 0, new ModelResourceLocation(ItemsFL.CHEESECLOTH.getRegistryName(), "inventory"));
ModelLoader.setCustomModelResourceLocation(ItemsFL.CRACKED_COCONUT, 0, new ModelResourceLocation(ItemsFL.CRACKED_COCONUT.getRegistryName(), "inventory"));
Expand Down Expand Up @@ -137,6 +139,7 @@ public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack)
ClientRegistry.bindTileEntitySpecialRenderer(TEOven.class, new TESROven());
ClientRegistry.bindTileEntitySpecialRenderer(TEString.class, new TESRString());
ClientRegistry.bindTileEntitySpecialRenderer(TELeafMat.class, new TESRLeafMat());
ClientRegistry.bindTileEntitySpecialRenderer(TETurntable.class, new TESRTurntable());
}

@SuppressWarnings("deprecation")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/eerussianguy/firmalife/FirmaLife.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class FirmaLife
{
public static final String MOD_ID = "firmalife";
public static final String MODNAME = "FirmaLife";
public static final String MODVERSION = "0.5.0";
public static final String MODVERSION = "0.5.1";

@Mod.Instance
private static FirmaLife INSTANCE = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, Ent
}

@Override
public boolean hasTileEntity(IBlockState state) { return true; }
public boolean hasTileEntity(IBlockState state)
{
return true;
}

@Override
public TileEntity createTileEntity(World world, IBlockState state)
Expand Down Expand Up @@ -124,8 +127,6 @@ public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos

}

//Lifted from BlockFlowerPot

@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest)
{
Expand Down
145 changes: 145 additions & 0 deletions src/main/java/com/eerussianguy/firmalife/blocks/BlockTurntable.java
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ public class StatePropertiesFL
public static final PropertyInteger JARS = PropertyInteger.create("jars", 1, 4);
public static final PropertyInteger WEDGES = PropertyInteger.create("wedges", 0, 3);
public static final PropertyEnum<AgingFL> AGE = PropertyEnum.create("age", AgingFL.class);
public static final PropertyInteger CLAY = PropertyInteger.create("clay", 0, 4);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public ItemBlockRot(Block b)
super(b);
}


@Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt)
{
Expand All @@ -57,7 +56,7 @@ public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos p
{
long currentTime = CalendarTFC.PLAYER_TIME.getTicks();
te.resetCounter(); //te counter is at currentTime
te.reduceCounter(foodCreationDate - currentTime); //teCounter is now at foodCrationDate
te.reduceCounter(foodCreationDate - currentTime); //teCounter is now at foodCreationDate
}
}
return result;
Expand Down
33 changes: 1 addition & 32 deletions src/main/java/com/eerussianguy/firmalife/recipe/PizzaRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import net.dries007.tfc.objects.recipes.ShapedDamageRecipe;
import net.dries007.tfc.util.calendar.CalendarTFC;

public class PizzaRecipe extends ShapedDamageRecipe
public class PizzaRecipe extends SandwichBasedRecipe
{
public PizzaRecipe(ResourceLocation group, CraftingHelper.ShapedPrimer input, @Nonnull ItemStack result, int damage)
{
Expand All @@ -49,37 +49,6 @@ public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv)
return output;
}

@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;
}

private 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());
}
}
}

@SuppressWarnings("unused")
public static class Factory implements IRecipeFactory
{
Expand Down
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());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import net.dries007.tfc.util.calendar.CalendarTFC;

@SuppressWarnings("unused")
public class TrailMixRecipe extends ShapedDamageRecipe
public class TrailMixRecipe extends SandwichBasedRecipe
{
public TrailMixRecipe(ResourceLocation group, CraftingHelper.ShapedPrimer input, @Nonnull ItemStack result, int damage)
{
Expand All @@ -50,37 +50,6 @@ public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv)
return output;
}

@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;
}

private 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());
}
}
}

@SuppressWarnings("unused")
public static class Factory implements IRecipeFactory
{
Expand Down
Loading

0 comments on commit 9f1e665

Please sign in to comment.