aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/plugin/villagers/trade/TradeHandlerAboriginal.java
blob: 3baca107926301c91aebe2382aa414368d10491d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package gtPlusPlus.plugin.villagers.trade;

import static java.util.Collections.shuffle;

import java.util.Collections;
import java.util.Random;

import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.AutoMap;
import gtPlusPlus.core.material.ELEMENT;
import gtPlusPlus.core.util.math.MathUtils;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.village.MerchantRecipe;
import net.minecraft.village.MerchantRecipeList;

public class TradeHandlerAboriginal extends TradeHandlerBase {

	private final static AutoMap<ItemStack> mInputs = new AutoMap<ItemStack>();
	private final static AutoMap<ItemStack> mOutputs = new AutoMap<ItemStack>();
	private static boolean initialised = false;

	public static void init() {
		mOutputs.put(ItemUtils.getSimpleStack(Blocks.anvil, 1));
		mOutputs.put(ItemUtils.getSimpleStack(Blocks.bookshelf, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Blocks.cactus, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Blocks.dirt, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Blocks.cobblestone, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Blocks.mossy_cobblestone, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Blocks.pumpkin, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Blocks.hardened_clay, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Blocks.log, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Blocks.obsidian, 8));
		mOutputs.put(ItemUtils.getSimpleStack(Items.wheat, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Blocks.gravel, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Blocks.sand, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.apple, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.emerald, 1));
		mOutputs.put(ItemUtils.getSimpleStack(Items.diamond, 1));
		mOutputs.put(ItemUtils.getSimpleStack(Items.baked_potato, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.beef, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.bone, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.bread, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.carrot, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.potato, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.poisonous_potato, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.chicken, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.porkchop, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.cooked_beef, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.cooked_chicken, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.cooked_porkchop, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.fish, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.cooked_fished, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.feather, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.egg, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.gold_nugget, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.leather, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.melon_seeds, 0));
		mOutputs.put(ItemUtils.getSimpleStack(Items.reeds, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.wooden_door));
		mInputs.put(ItemUtils.getSimpleStack(Blocks.log));
		mInputs.put(ItemUtils.getSimpleStack(Blocks.log2));
		mInputs.put(ItemUtils.getSimpleStack(Blocks.planks));
		mInputs.put(ItemUtils.getSimpleStack(Blocks.sapling));
		mInputs.put(ItemUtils.getSimpleStack(Blocks.sandstone));
		mInputs.put(ItemUtils.getSimpleStack(Blocks.nether_brick));
		mInputs.put(ItemUtils.getSimpleStack(Blocks.bookshelf));
		mInputs.put(ItemUtils.getSimpleStack(Blocks.crafting_table));
		mInputs.put(ItemUtils.getSimpleStack(Blocks.gravel));
		mInputs.put(ItemUtils.getSimpleStack(Blocks.hardened_clay));
		mInputs.put(ItemUtils.getSimpleStack(Blocks.cactus));
		mInputs.put(ItemUtils.getSimpleStack(Blocks.quartz_block));
		mInputs.put(ItemUtils.getSimpleStack(Blocks.stone));
		mInputs.put(ItemUtils.getSimpleStack(Blocks.mossy_cobblestone));
		mInputs.put(ItemUtils.getSimpleStack(Items.apple, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.emerald, 1));
		mInputs.put(ItemUtils.getSimpleStack(Items.diamond, 1));
		mInputs.put(ItemUtils.getSimpleStack(Items.baked_potato, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.beef, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.bone, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.bread, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.carrot, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.potato, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.poisonous_potato, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.chicken, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.porkchop, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.cooked_beef, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.cooked_chicken, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.cooked_porkchop, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.fish, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.cooked_fished, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.feather, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.egg, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.gold_nugget, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.leather, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.melon_seeds, 0));
		mInputs.put(ItemUtils.getSimpleStack(Items.reeds, 0));		
		initialised = true;
	}


	public TradeHandlerAboriginal() {
		Logger.INFO("Created Trade Manager for 'Trader' villager profession type.");
	}

	@SuppressWarnings("unchecked")
	@Override
	public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipeList, Random random) {		
		if (!initialised) {
			init();
		}	
		if (initialised) {
			recipeList.add(new MerchantRecipe(getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput()));
			recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput()));
			shuffle(recipeList);
		}
	}

	private ItemStack getInput() {
		ItemStack input = mInputs.get(MathUtils.randInt(0, mInputs.size()-1));
		int outputSize = (input.stackSize == 0 ? (Math.max(MathUtils.randInt(1, 64), MathUtils.randInt(1, 32))) : input.stackSize);
		return ItemUtils.getSimpleStack(input, outputSize);
	}
	
	final static int MID_BOUND = 24;	
	private ItemStack getOutput() {
		ItemStack output = mOutputs.get(MathUtils.randInt(0, mOutputs.size()-1));
		int outputSize = (output.stackSize == 0 ? (Math.min(MathUtils.randInt(MathUtils.randInt(1, MID_BOUND), MathUtils.randInt(MID_BOUND, 32)), MathUtils.randInt(MathUtils.randInt(12, MID_BOUND), MathUtils.randInt(MID_BOUND, 48)))) : output.stackSize);
		return ItemUtils.getSimpleStack(output, outputSize);
	}

}