trying to match inputs

This commit is contained in:
Mohammad-Ali Minaie
2018-10-16 10:58:47 -04:00
parent eecd4536ce
commit 3d8552ed1a
7 changed files with 414 additions and 22 deletions

View File

@@ -1,12 +1,10 @@
# To-Dos
## Bugs
- [ ] Texture mismatch for 4diamond 1 redstone
- [ ] ForgeHammer extend Gallagher
- [ ] Placement bug for crucible from tongs
## Current Feature
- [ ] weapon upgrades
- [ ] Untick Bloomery and Forge
- [ ] Craft Tweaker Support
- [ ] Recipe Handler for Block Breaker

View File

@@ -1,13 +1,20 @@
package nmd.primal.forgecraft;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
import net.minecraftforge.oredict.OreDictionary;
import nmd.primal.core.api.PrimalAPI;
import nmd.primal.core.api.events.CauldronEvent;
import nmd.primal.core.common.helper.PlayerHelper;
import nmd.primal.forgecraft.init.ModItems;
import nmd.primal.forgecraft.items.parts.ToolPart;
import nmd.primal.forgecraft.items.parts.WeaponPart;
import nmd.primal.forgecraft.items.tools.CustomAxe;
import nmd.primal.forgecraft.items.tools.CustomHoe;
import nmd.primal.forgecraft.items.tools.CustomPickaxe;
@@ -19,8 +26,56 @@ import nmd.primal.forgecraft.util.ToolNBT;
*/
public class CommonEvents implements ToolNBT {
@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
public void onItemCrafted(CauldronEvent event){
@SubscribeEvent(priority= EventPriority.HIGHEST, receiveCanceled=true)
NonNullList<ItemStack> inputs = NonNullList.<ItemStack>withSize(6,ItemStack.EMPTY);
inputs.set(0, event.getTile().getInputHandler().getStackInSlot(0));
inputs.set(1, event.getTile().getInputHandler().getStackInSlot(1));
inputs.set(2, event.getTile().getInputHandler().getStackInSlot(2));
inputs.set(3, event.getTile().getInputHandler().getStackInSlot(3));
inputs.set(4, event.getTile().getInputHandler().getStackInSlot(4));
inputs.set(5, event.getTile().getInputHandler().getStackInSlot(5));
NonNullList<ItemStack> outputs = NonNullList.<ItemStack>withSize(6,ItemStack.EMPTY);
outputs.set(0, event.getTile().getOutputHandler().getStackInSlot(0));
outputs.set(1, event.getTile().getOutputHandler().getStackInSlot(1));
outputs.set(2, event.getTile().getOutputHandler().getStackInSlot(2));
outputs.set(3, event.getTile().getOutputHandler().getStackInSlot(3));
outputs.set(4, event.getTile().getOutputHandler().getStackInSlot(4));
outputs.set(5, event.getTile().getOutputHandler().getStackInSlot(5));
//System.out.println(inputs. + ":" + outputs.stream());
if(getMatchingStacks(inputs, outputs).get(0) != ItemStack.EMPTY){
System.out.println(getMatchingStacks(inputs, outputs).get(0) + " : " + getMatchingStacks(inputs, outputs).get(1));
}
}
private NonNullList<ItemStack> getMatchingStacks(NonNullList<ItemStack> input, NonNullList<ItemStack> output){
ItemStack inputStack = ItemStack.EMPTY;
ItemStack outputStack = ItemStack.EMPTY;
NonNullList<ItemStack> returnList = NonNullList.<ItemStack>withSize(2, ItemStack.EMPTY);
for (int i = 0; i < input.size(); i++) {
if(input.get(i).getItem() instanceof WeaponPart){
inputStack = input.get(i);
}
}
for (int i = 0; i < output.size(); i++) {
if(output.get(i).getItem() instanceof WeaponPart){
outputStack = output.get(i);
}
}
if(inputStack != null && outputStack != null && inputStack.equals(outputStack)){
returnList.set(0, inputStack);
returnList.set(1, outputStack);
}
return returnList;
}
/*@SubscribeEvent(priority= EventPriority.HIGHEST, receiveCanceled=true)
public void onItemCrafted(PlayerEvent.ItemCraftedEvent event) {
if(!event.player.getEntityWorld().isRemote) {
@@ -88,5 +143,5 @@ public class CommonEvents implements ToolNBT {
}
}
}
}
}*/
}

View File

@@ -13,6 +13,7 @@ import nmd.primal.forgecraft.items.*;
import nmd.primal.forgecraft.items.armor.CustomHelmet;
import nmd.primal.forgecraft.items.blocks.ItemNBTCrucible;
import nmd.primal.forgecraft.items.parts.ToolPart;
import nmd.primal.forgecraft.items.parts.WeaponPart;
import nmd.primal.forgecraft.items.tools.CustomAxe;
import nmd.primal.forgecraft.items.tools.CustomHoe;
import nmd.primal.forgecraft.items.tools.CustomPickaxe;
@@ -34,7 +35,8 @@ public class ModItems {
public static Item softcrucible;
//public static Item stonetongs;
public static Item castingmud;
//public static Item rawbronzegladius;
public static Item rawbronzegladius;
public static Item bronzeingotball;
public static Item bronzechunk;
@@ -249,7 +251,7 @@ public class ModItems {
/**********
WEAPONS
**********/
//rawbronzegladius = new Item().setRegistryName("rawbronzegladius").setUnlocalizedName("rawbronzegladius");
rawbronzegladius = new WeaponPart("rawbronzegladius", PrimalAPI.ToolMaterials.TOOL_BRONZE);
bronzegladius = new CustomSword("bronzegladius", PrimalAPI.ToolMaterials.TOOL_BRONZE, 5.5D, 2D);
wroughtirongladius = new CustomSword("wroughtirongladius", PrimalAPI.ToolMaterials.TOOL_WROUGHT_IRON, 4.5D, -1.85D);
@@ -401,7 +403,7 @@ public class ModItems {
/**********
WEAPONS
**********/
//ForgeRegistries.ITEMS.register(rawbronzegladius);
ForgeRegistries.ITEMS.register(rawbronzegladius);
ForgeRegistries.ITEMS.register(wroughtirongladius);
ForgeRegistries.ITEMS.register(bronzegladius);
@@ -539,9 +541,9 @@ public class ModItems {
/**********
WEAPONS
**********/
registerRender(wroughtironshield);
//registerRender(wroughtironshield);
//registerRender(rawbronzegladius);
registerRender(rawbronzegladius);
registerRender(bronzegladius);
registerRender(wroughtirongladius);

View File

@@ -2,14 +2,20 @@ package nmd.primal.forgecraft.init.recipes;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.registries.IForgeRegistry;
import nmd.primal.core.api.PrimalAPI;
import nmd.primal.core.common.helper.RecipeHelper;
import nmd.primal.core.common.recipes.tile.CauldronRecipe;
import nmd.primal.forgecraft.ModInfo;
import nmd.primal.forgecraft.init.ModItems;
import nmd.primal.forgecraft.util.WeaponNBT;
@GameRegistry.ObjectHolder(ModInfo.MOD_ID)
@Mod.EventBusSubscriber
@@ -20,18 +26,27 @@ public class CauldronRecipes
{
final IForgeRegistry<CauldronRecipe> recipes = event.getRegistry();
ItemStack defaultBronze = new ItemStack(ModItems.bronzegladius);
ItemStack defaultBronzeGladius = new ItemStack(ModItems.rawbronzegladius, 1);
NBTTagCompound tags = new NBTTagCompound();
defaultBronze.setTagCompound(tags);
ItemStack lapisBronze = defaultBronze.copy();
lapisBronze.getTagCompound().setTag("tags", tags);
lapisBronze.getSubCompound("tags").setInteger("smite", 0);
lapisBronze.getSubCompound("tags").setInteger("bane", 0);
lapisBronze.getSubCompound("tags").setInteger("fire", 0);
lapisBronze.getSubCompound("tags").setInteger("lapis", 1);
lapisBronze.getSubCompound("tags").setBoolean("modified", true);
//WeaponNBT.setDefaultNBT(defaultBronzeGladius);
NonNullList<ItemStack> tempList1 = NonNullList.<ItemStack>create();
tempList1.add(0, new ItemStack(ModItems.rawbronzegladius, 1));
recipes.register(new CauldronRecipe(
5,
new FluidStack(FluidRegistry.WATER, 1000),
new FluidStack(PrimalAPI.Fluids.WASTE, 1000),
RecipeHelper.getOreStack("gemLapis", 1),
tempList1,
defaultBronzeGladius,
ItemStack.EMPTY).setRecipeName("rawbronzegladiuslapis"));
}
}
//int cook_time,
// FluidStack fluid_input,
// FluidStack fluid_output,
// List<ItemStack> item_input_1,
// List<ItemStack> item_input_2,
// ItemStack item_output_1,
// ItemStack item_output_2

View File

@@ -0,0 +1,137 @@
package nmd.primal.forgecraft.items.parts;
import com.mojang.realmsclient.gui.ChatFormatting;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import nmd.primal.core.api.PrimalAPI;
import nmd.primal.forgecraft.ModInfo;
import nmd.primal.forgecraft.util.ToolMaterialMap;
import nmd.primal.forgecraft.util.ToolNBT;
import nmd.primal.forgecraft.util.WeaponNBT;
import javax.annotation.Nullable;
import java.util.List;
/**
* Created by mminaie on 3/9/17.
*/
public class WeaponPart extends Item implements WeaponNBT {
private ToolMaterial toolMaterial;
public WeaponPart(String name, ToolMaterial material) {
this.setMaxDamage(material.getMaxUses());
this.setUnlocalizedName(name);
this.setRegistryName(name);
this.setCreativeTab(ModInfo.TAB_FORGECRAFT);
this.setMaxStackSize(1);
this.setNoRepair();
this.toolMaterial = material;
this.addPropertyOverride(new ResourceLocation("type"), new IItemPropertyGetter() {
/***
smite| bane | fire | fortune | leech
X.0 | 0.X | 0.0X | 0.00X | 0.000X
***/
@SideOnly(Side.CLIENT)
public float apply(ItemStack item, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) {
if (item.hasTagCompound()) {
Float returnFloat = 0.0F;
if(getSmiteLevel(item)>0){
returnFloat += 0.1F;
}
if(getBaneLevel(item)>0){
returnFloat += (0.01F * getBaneLevel(item));
}
if(getFireLevel(item)>0){
returnFloat += (0.001F * getFireLevel(item));
}
if(getFortuneLevel(item)>0){
returnFloat += (0.0001F * getFortuneLevel(item));
}
if(getLeechLevel(item)>0){
returnFloat += (0.0001F * getLeechLevel(item));
}
return returnFloat;
}
return 0.0F;
}
});
}
public static boolean isHidden()
{
return false;
}
public ToolMaterial getMaterial() {return toolMaterial;}
public void createDefaultNBT(ItemStack item){
if (!item.hasTagCompound()) {
item.setTagCompound(new NBTTagCompound());
NBTTagCompound tags = new NBTTagCompound();
item.getTagCompound().setTag("tags", tags);
setSmiteLevel(item, 0);
setBaneLevel(item, 0);
setFireLevel(item, 0);
setFortuneLevel(item, 0);
setLeechLevel(item, 0);
setSweepingLevel(item, 0);
setSharpnessLevel(item, 0);
setModifiers(item, 0);
}
}
@Override
public void onCreated(ItemStack item, World worldIn, EntityPlayer playerIn) {
createDefaultNBT(item);
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack item, @Nullable World world, List<String> tooltip, ITooltipFlag flagIn)
{
if(item.hasTagCompound())
{
tooltip.add(ChatFormatting.GRAY + "Upgrades left: " + (WeaponNBT.materialModifiers.get(this.toolMaterial) - getModifiers(item)));
/*if (getEmerald(item)) {
tooltip.add(ChatFormatting.DARK_GREEN + "Emerald");
}
if (getDiamondLevel(item) > 0) {
tooltip.add(ChatFormatting.AQUA + "Diamond Level: " + getDiamondLevel(item));
}
if (getRedstoneLevel(item) > 0) {
tooltip.add(ChatFormatting.RED + "Redstone Level: " + getRedstoneLevel(item));
}
if (getLapisLevel(item) > 0) {
tooltip.add(ChatFormatting.BLUE + "Lapis Level: " + getLapisLevel(item));
}*/
}
}
}

View File

@@ -107,7 +107,6 @@ public class Longbow extends ItemBow {
{
ItemArrow itemarrow = (ItemArrow)((ItemArrow)(itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW));
EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
System.out.println(f);
entityarrow.setDamage(entityarrow.getDamage()+(entityarrow.getDamage()*f));
entityarrow.shoot(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 6.0F, 0.5F);

View File

@@ -0,0 +1,186 @@
package nmd.primal.forgecraft.util;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import nmd.primal.core.api.PrimalAPI;
import java.util.Hashtable;
/**
* Created by mminaie on 3/17/17.
*/
public interface WeaponNBT {
/***
* smite
* bane
* fire
* fortune
* leech
* sweeping
* sharpness
***/
/***
*
* @param stack The ItemStack to get Modifiers from
* @return int The number of modifiers applied
*/
default int getModifiers(ItemStack stack) {
if(!stack.isEmpty()) {
if (stack.hasTagCompound()) {
if (stack.getSubCompound("tags") != null) {
return stack.getSubCompound("tags").getInteger("modifiers");
}
}
}
return 0;
}
/***
*
* @param stack The stack to set modifiers to
* @param mods The number of modifiers added
*/
default void setModifiers(ItemStack stack, Integer mods){
stack.getSubCompound("tags").setInteger("modifiers", mods);
}
default int getSmiteLevel(ItemStack stack){
if(!stack.isEmpty()) {
if (stack.hasTagCompound()) {
if (stack.getSubCompound("tags") != null) {
return stack.getSubCompound("tags").getInteger("smite");
}
}
}
return 0;
}
default void setSmiteLevel(ItemStack stack, int smite){
stack.getSubCompound("tags").setInteger("smite", smite);
}
default int getBaneLevel(ItemStack stack) {
if(!stack.isEmpty()) {
if (stack.hasTagCompound()) {
if (stack.getSubCompound("tags") != null) {
return stack.getSubCompound("tags").getInteger("bane");
}
}
}
return 0;
}
default void setBaneLevel(ItemStack stack, Integer level){
stack.getSubCompound("tags").setInteger("bane", level);
}
default int getFireLevel(ItemStack stack) {
if(!stack.isEmpty()) {
if (stack.hasTagCompound()) {
if (stack.getSubCompound("tags") != null) {
return stack.getSubCompound("tags").getInteger("fire");
}
}
}
return 0;
}
default void setFireLevel(ItemStack stack, Integer level){
stack.getSubCompound("tags").setInteger("fire", level);
}
default int getFortuneLevel(ItemStack stack) {
if(!stack.isEmpty()) {
if (stack.hasTagCompound()) {
if (stack.getSubCompound("tags") != null) {
return stack.getSubCompound("tags").getInteger("fortune");
}
}
}
return 0;
}
default void setFortuneLevel(ItemStack stack, Integer level){
stack.getSubCompound("tags").setInteger("fortune", level);
}
default int getSweepingLevel(ItemStack stack) {
if(!stack.isEmpty()) {
if (stack.hasTagCompound()) {
if (stack.getSubCompound("tags") != null) {
return stack.getSubCompound("tags").getInteger("sweeping");
}
}
}
return 0;
}
default void setSweepingLevel(ItemStack stack, Integer level){
stack.getSubCompound("tags").setInteger("sweeping", level);
}
default int getSharpnessLevel(ItemStack stack) {
if(!stack.isEmpty()) {
if (stack.hasTagCompound()) {
if (stack.getSubCompound("tags") != null) {
return stack.getSubCompound("tags").getInteger("sharp");
}
}
}
return 0;
}
default void setSharpnessLevel(ItemStack stack, Integer level){
stack.getSubCompound("tags").setInteger("sharp", level);
}
default int getLeechLevel(ItemStack stack) {
if(!stack.isEmpty()) {
if (stack.hasTagCompound()) {
if (stack.getSubCompound("tags") != null) {
return stack.getSubCompound("tags").getInteger("leech");
}
}
}
return 0;
}
default void setLeechLevel(ItemStack stack, Integer level){
stack.getSubCompound("tags").setInteger("leech", level);
}
default NBTTagCompound getTags(ItemStack stack){
if(!stack.isEmpty()) {
if (stack.hasTagCompound()) {
if (stack.getSubCompound("tags") != null) {
return stack.getSubCompound("tags");
}
}
}
return null;
}
static void setDefaultNBT(ItemStack stack){
NBTTagCompound tags = new NBTTagCompound();
stack.setTagCompound(tags);
stack.getTagCompound().setTag("tags", tags);
stack.getSubCompound("tags").setInteger("smite", 0);
stack.getSubCompound("tags").setInteger("bane", 0);
stack.getSubCompound("tags").setInteger("fire", 0);
stack.getSubCompound("tags").setInteger("fortune", 0);
stack.getSubCompound("tags").setInteger("leech", 0);
stack.getSubCompound("tags").setInteger("sweeping", 0);
stack.getSubCompound("tags").setInteger("sharpness", 0);
}
Hashtable<Item.ToolMaterial, Integer> materialModifiers = new Hashtable<Item.ToolMaterial, Integer>(){{
put(PrimalAPI.ToolMaterials.TOOL_COPPER, 3);
put(PrimalAPI.ToolMaterials.TOOL_BRONZE, 3);
put(PrimalAPI.ToolMaterials.TOOL_CRUDE_IRON, 4);
put(PrimalAPI.ToolMaterials.TOOL_WROUGHT_IRON, 5);
put(PrimalAPI.ToolMaterials.TOOL_CLEAN_IRON, 7);
put(PrimalAPI.ToolMaterials.TOOL_BASIC_STEEL, 8);
put(PrimalAPI.ToolMaterials.TOOL_WOOTZ_STEEL, 9);
}};
}