-
Notifications
You must be signed in to change notification settings - Fork 79
/
MirrorTransferCrafting.java
169 lines (142 loc) · 3.5 KB
/
MirrorTransferCrafting.java
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
162
163
164
165
166
167
168
169
package mod.chiselsandbits.crafting;
import mod.chiselsandbits.chiseledblock.NBTBlobConverter;
import mod.chiselsandbits.chiseledblock.data.VoxelBlob;
import mod.chiselsandbits.core.ChiselsAndBits;
import mod.chiselsandbits.helpers.ModUtil;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class MirrorTransferCrafting implements IRecipe
{
@Override
public boolean matches(
final InventoryCrafting craftingInv,
final World worldIn )
{
return analzyeCraftingInventory( craftingInv, true ) != null;
}
public ItemStack analzyeCraftingInventory(
final InventoryCrafting craftingInv,
final boolean generatePattern )
{
ItemStack targetA = null;
ItemStack targetB = null;
boolean isNegative = false;
for ( int x = 0; x < craftingInv.getSizeInventory(); x++ )
{
final ItemStack f = craftingInv.getStackInSlot( x );
if ( f == null )
{
continue;
}
if ( f.getItem() == ChiselsAndBits.getItems().itemMirrorprint )
{
if ( ChiselsAndBits.getItems().itemMirrorprint.isWritten( f ) )
{
if ( targetA != null )
{
return null;
}
targetA = f;
}
else
{
return null;
}
}
else if ( f.getItem() == ChiselsAndBits.getItems().itemNegativeprint )
{
if ( !ChiselsAndBits.getItems().itemNegativeprint.isWritten( f ) )
{
if ( targetB != null )
{
return null;
}
isNegative = true;
targetB = f;
}
else
{
return null;
}
}
else if ( f.getItem() == ChiselsAndBits.getItems().itemPositiveprint )
{
if ( !ChiselsAndBits.getItems().itemPositiveprint.isWritten( f ) )
{
if ( targetB != null )
{
return null;
}
isNegative = false;
targetB = f;
}
else
{
return null;
}
}
else
{
return null;
}
}
if ( targetA != null && targetB != null )
{
if ( generatePattern )
{
return targetA;
}
final NBTBlobConverter tmp = new NBTBlobConverter();
tmp.readChisleData( targetA.getTagCompound(), VoxelBlob.VERSION_ANY );
final VoxelBlob bestBlob = tmp.getBlob();
if ( isNegative )
{
bestBlob.binaryReplacement( 0, ModUtil.getStateId( Blocks.STONE.getDefaultState() ) );
}
tmp.setBlob( bestBlob );
final NBTBase copied = targetA.getTagCompound().copy();
final NBTTagCompound comp = (NBTTagCompound) copied;
tmp.writeChisleData( comp, false );
final ItemStack outputPattern = new ItemStack( targetB.getItem() );
outputPattern.setTagCompound( comp );
return outputPattern;
}
return null;
}
@Override
public ItemStack getCraftingResult(
final InventoryCrafting craftingInv )
{
return analzyeCraftingInventory( craftingInv, false );
}
@Override
public int getRecipeSize()
{
return 2;
}
@Override
public ItemStack getRecipeOutput()
{
return null; // nope
}
@Override
public ItemStack[] getRemainingItems(
final InventoryCrafting craftingInv )
{
final ItemStack[] aitemstack = new ItemStack[craftingInv.getSizeInventory()];
for ( int i = 0; i < aitemstack.length; ++i )
{
final ItemStack itemstack = craftingInv.getStackInSlot( i );
if ( itemstack != null && itemstack.getItem() == ChiselsAndBits.getItems().itemMirrorprint && itemstack.hasTagCompound() )
{
itemstack.stackSize++;
}
}
return aitemstack;
}
}