Skip to content

Commit

Permalink
Tweaks, lots of tweaks...
Browse files Browse the repository at this point in the history
- Added config to set which blocks are considered rubber trees (defaults to DTTFC hevea and our own registered hevea in TFC, Closes #45).
- Added (finally) a way to obtain sleeves via molds (Closes #35).
- Fixed a few annoying log errors in unmolding recipes.
- Fixed russian translation file location.
- Fixed sleeve placement not searching hammer in offhand slot.
  • Loading branch information
DisasterMoo committed Jun 10, 2020
1 parent 312d840 commit bac2d4d
Show file tree
Hide file tree
Showing 18 changed files with 374 additions and 157 deletions.
4 changes: 4 additions & 0 deletions src/main/java/tfctech/TechConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public static class Tweaks
@Config.Comment({"Should TFCTech remove TFC and vanilla glass recipes?"})
@Config.LangKey("config." + MODID + ".tweaks.removeGlassRecipes")
public boolean removeGlassRecipes = true;

@Config.Comment({"Which blocks are considered valid for rubber tapping?"})
@Config.LangKey("config." + MODID + ".tweaks.validRubberTrees")
public String[] rubberTrees = new String[] {"tfc:wood/log/hevea{placed=false,axis=y}", "dynamictreestfc:branch/hevea{radius=8}"};
}

public static class Devices
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/tfctech/compat/jei/TechJEIPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ public void register(IModRegistry registry)
{
for (ItemTechMetal.ItemType type : ItemTechMetal.ItemType.values())
{
if (type.hasMold())
if (type.hasMold() && ItemTechMetal.get(metal, type) != null)
{

unmoldList.add(new UnmoldRecipeWrapper(metal, type));
castingList.add(new CastingRecipeWrapper(metal, type));
}
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/tfctech/objects/items/TechItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

import java.util.function.Function;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.google.common.collect.ImmutableList;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
Expand All @@ -28,6 +32,7 @@
import net.dries007.tfc.objects.ToolMaterialsTFC;
import net.dries007.tfc.objects.blocks.BlocksTFC;
import net.dries007.tfc.objects.blocks.stone.BlockRockVariant;
import net.dries007.tfc.objects.fluids.FluidsTFC;
import net.dries007.tfc.objects.items.ItemsTFC;
import net.dries007.tfc.objects.items.ceramics.ItemPottery;
import net.dries007.tfc.util.OreDictionaryHelper;
Expand Down Expand Up @@ -112,6 +117,11 @@ public final class TechItems
@GameRegistry.ObjectHolder("ceramics/mold/rackwheel_piece")
public static final ItemTechMold MOLD_RACKWHEEL_PIECE = getNull();

@GameRegistry.ObjectHolder("ceramics/unfired/sleeve")
public static final ItemPottery UNFIRED_SLEEVE = getNull();
@GameRegistry.ObjectHolder("ceramics/mold/sleeve")
public static final ItemTechMold MOLD_SLEEVE = getNull();


private static ImmutableList<Item> allSimpleItems;
private static ImmutableList<Item> allMetalItems;
Expand Down Expand Up @@ -167,6 +177,7 @@ public boolean hasContainerItem(@Nonnull ItemStack stack)
simpleItems.add(register(r, "wiredraw/winch", new ItemMiscTech(Size.NORMAL, Weight.MEDIUM), CT_MISC));

//Unfired is simple
simpleItems.add(register(r, "ceramics/unfired/sleeve", new ItemPottery(), CT_MISC));
simpleItems.add(register(r, "ceramics/unfired/rackwheel_piece", new ItemPottery(), CT_MISC));
simpleItems.add(register(r, "ceramics/unfired/glass_block", new ItemPottery(), CT_MISC));
simpleItems.add(register(r, "ceramics/unfired/glass_pane", new ItemPottery(), CT_MISC));
Expand All @@ -177,6 +188,44 @@ public boolean hasContainerItem(@Nonnull ItemStack stack)
ceramicItems.add(register(r, "ceramics/mold/glass_block", new ItemGlassMolder(ItemGlassMolder.BLOCK_TANK), CT_MISC));
ceramicItems.add(register(r, "ceramics/mold/glass_pane", new ItemGlassMolder(ItemGlassMolder.PANE_TANK), CT_MISC));
ceramicItems.add(register(r, "ceramics/mold/rackwheel_piece", new ItemTechMold(ItemTechMetal.ItemType.RACKWHEEL_PIECE), CT_MISC));
// This one is special since we only have 3 sleeves: tin, brass and steel
// In 1.15, refactor the mod to properly use recipes instead of this ugly code
ItemTechMold sleeveMold = new ItemTechMold(ItemTechMetal.ItemType.SLEEVE)
{
@Override
public ICapabilityProvider initCapabilities(@Nonnull ItemStack stack, @Nullable NBTTagCompound nbt)
{
return new FilledMoldCapability(nbt)
{
@Override
public int fill(FluidStack resource, boolean doFill)
{
if (resource != null)
{
Metal metal = FluidsTFC.getMetalFromFluid(resource.getFluid());
if (isValidMetal(metal))
{
return super.fill(resource, doFill);
}
}
return 0;
}

private boolean isValidMetal(@Nullable Metal metal)
{
if (metal != null)
{
//noinspection ConstantConditions
return "tin".equals(metal.getRegistryName().getPath()) ||
"brass".equals(metal.getRegistryName().getPath()) ||
"steel".equals(metal.getRegistryName().getPath());
}
return false;
}
};
}
};
ceramicItems.add(register(r, "ceramics/mold/sleeve", sleeveMold, CT_MISC));
allCeramicMoldItems = ceramicItems.build();

ImmutableList.Builder<Item> metalItems = ImmutableList.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ public int getItemStackLimit(ItemStack stack)
/**
* Copy of {@link ItemMold} FilledMoldCapability
*/
private class FilledMoldCapability extends ItemHeatHandler implements ICapabilityProvider, IMoldHandler
public class FilledMoldCapability extends ItemHeatHandler implements ICapabilityProvider, IMoldHandler
{
private final FluidTank tank;
private IFluidTankProperties[] fluidTankProperties;

FilledMoldCapability(@Nullable NBTTagCompound nbt)
public FilledMoldCapability(@Nullable NBTTagCompound nbt)
{
tank = new FluidTank(100);

Expand Down Expand Up @@ -186,7 +186,7 @@ public void addHeatInfo(@Nonnull ItemStack stack, @Nonnull List<String> text)
String desc = TextFormatting.DARK_GREEN + I18n.format(Helpers.getTypeName(metal)) + ": " + I18n.format("tfc.tooltip.units", getAmount());
if (isMolten())
{
desc += " - " + I18n.format("tfc.tooltip.liquid");
desc += I18n.format("tfc.tooltip.liquid");
}
text.add(desc);
}
Expand Down
144 changes: 105 additions & 39 deletions src/main/java/tfctech/objects/items/metal/ItemGroove.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
package tfctech.objects.items.metal;

import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import mcp.MethodsReturnNonnullByDefault;
import net.dries007.tfc.api.types.Metal;
import net.dries007.tfc.objects.blocks.wood.BlockLogTFC;
import tfctech.TechConfig;
import tfctech.client.TechSounds;
import tfctech.objects.blocks.TechBlocks;
import tfctech.objects.blocks.devices.BlockLatexExtractor;
import tfctech.registry.TechTrees;

import static net.dries007.tfc.objects.blocks.wood.BlockLogTFC.PLACED;
import static net.minecraft.block.BlockHorizontal.FACING;

@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class ItemGroove extends ItemTechMetal
{
Expand All @@ -33,41 +32,46 @@ public ItemGroove(Metal metal, ItemTechMetal.ItemType type)
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
IBlockState state = worldIn.getBlockState(pos);
if (state.getBlock() instanceof BlockLogTFC)
if (isValidBlock(state))
{
BlockLogTFC log = (BlockLogTFC) state.getBlock();
if (log.getWood() == TechTrees.HEVEA && !state.getValue(PLACED))
//Check if we can place this treetap here
for (EnumFacing face : EnumFacing.HORIZONTALS)
{
//Check if we can place this treetap here
for (EnumFacing face : EnumFacing.HORIZONTALS)
if (!worldIn.isAirBlock(pos.offset(face)))
{
if (!worldIn.isAirBlock(pos.offset(face)))
{
return EnumActionResult.PASS; //Can't place
}
return EnumActionResult.PASS; //Can't place
}
}


//Find if no other treetap is placed in this tree
BlockPos trunkPos = pos;
while (worldIn.getBlockState(trunkPos.down()).getBlock() instanceof BlockLogTFC)
{
trunkPos = trunkPos.down();
}
do
//Find if no other treetap is placed in this tree
BlockPos trunkPos = pos;
while (worldIn.getBlockState(trunkPos.down()).getBlock() == state.getBlock())
{
trunkPos = trunkPos.down();
}
do
{
for (EnumFacing face : EnumFacing.HORIZONTALS)
{
for (EnumFacing face : EnumFacing.HORIZONTALS)
if (worldIn.getBlockState(trunkPos.offset(face)).getBlock() instanceof BlockLatexExtractor)
{
if (worldIn.getBlockState(trunkPos.offset(face)).getBlock() instanceof BlockLatexExtractor)
{
return EnumActionResult.PASS; //Found one, cancel
}
return EnumActionResult.PASS; //Found one, cancel
}
trunkPos = trunkPos.up();
} while (worldIn.getBlockState(trunkPos).getBlock() instanceof BlockLogTFC);
}
trunkPos = trunkPos.up();
} while (worldIn.getBlockState(trunkPos).getBlock() == state.getBlock());

int hammerSlot = -1;
boolean isOffhand = false;
ItemStack offhand = player.getHeldItemOffhand();
if (offhand.getItem().getToolClasses(offhand).contains("hammer"))
{
isOffhand = true;
}
else
{
//Check if player has hammer in toolbar
int hammerSlot = -1;
for (int i = 0; i < 9; i++)
{
ItemStack stack = player.inventory.getStackInSlot(i);
Expand All @@ -77,21 +81,83 @@ public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos p
break;
}
}
}

//Place latex extractor
if (hammerSlot > -1)


//Place latex extractor
if (hammerSlot > -1 || isOffhand)
{
if(isOffhand)
{
offhand.damageItem(1, player);
}
else
{
player.inventory.getStackInSlot(hammerSlot).damageItem(1, player);
player.getHeldItem(hand).shrink(1);
if (!worldIn.isRemote)
}
player.getHeldItem(hand).shrink(1);
if (!worldIn.isRemote)
{
worldIn.playSound(null, pos, TechSounds.RUBBER_GROOVE_FIT, SoundCategory.BLOCKS, 1.0F, 1.0F);
worldIn.setBlockState(pos.offset(facing), TechBlocks.LATEX_EXTRACTOR.getDefaultState().withProperty(FACING, facing));
}
return EnumActionResult.SUCCESS;
}
}
return EnumActionResult.PASS;
}


/**
* Check if said block is a valid rubber tree block (from config)
*
* @param state the block state to check
* @return true if valid (from config)
*/
private boolean isValidBlock(IBlockState state)
{
ResourceLocation resourceLocation = state.getBlock().getRegistryName();
for (String entry : TechConfig.TWEAKS.rubberTrees)
{
String id;
int paramStart = entry.indexOf("{");
int paramEnd = entry.indexOf("}");
if (paramStart > -1)
{
id = entry.substring(0, paramStart).trim();
}
else
{
id = entry;
}
if (resourceLocation != null && id.equals(resourceLocation.toString()))
{
String[] params = entry.substring(paramStart + 1, paramEnd).split(",");
for (String param : params)
{
boolean valid = false;
String paramName = param.substring(0, param.indexOf("=")).trim();
String paramValue = param.substring(param.indexOf("=") + 1).trim();
for (IProperty<?> property : state.getProperties().keySet())
{
worldIn.playSound(null, pos, TechSounds.RUBBER_GROOVE_FIT, SoundCategory.BLOCKS, 1.0F, 1.0F);
worldIn.setBlockState(pos.offset(facing), TechBlocks.LATEX_EXTRACTOR.getDefaultState().withProperty(FACING, facing));
if (property.getName().equals(paramName))
{
if (state.getValue(property).toString().equals(paramValue))
{
valid = true;
}
break;
}
}
if (!valid)
{
return false;
}
return EnumActionResult.SUCCESS;
}
return true;
}
}
return EnumActionResult.PASS;
return false;
}
}
6 changes: 3 additions & 3 deletions src/main/java/tfctech/objects/items/metal/ItemTechMetal.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ItemTechMetal extends ItemTFC implements IMetalItem
@Nullable
public static ItemTechMetal get(Metal metal, ItemTechMetal.ItemType type)
{
return (ItemTechMetal) ((EnumMap) TABLE.get(metal)).get(type);
return TABLE.get(metal).get(type);
}

protected final Metal metal;
Expand Down Expand Up @@ -101,7 +101,7 @@ public String getItemStackDisplayName(@Nonnull ItemStack stack)

@Nullable
@Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt)
public ICapabilityProvider initCapabilities(@Nonnull ItemStack stack, @Nullable NBTTagCompound nbt)
{
return new ForgeableHeatableHandler(nbt, metal.getSpecificHeat(), metal.getMeltTemp());
}
Expand Down Expand Up @@ -131,7 +131,7 @@ public enum ItemType
ROD(50),
BOLT(25),
SCREW(25),
SLEEVE(100),
SLEEVE(100, true),
RACKWHEEL_PIECE(100, true),
RACKWHEEL(400),
GEAR(400, false, ItemGear::new),
Expand Down
Loading

0 comments on commit bac2d4d

Please sign in to comment.