blob: a66e844c1369a1fd00aed73f87178667b58c46a3 (
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
|
package jp.plusplus.fbs.container.inventory;
import jp.plusplus.fbs.block.BlockCore;
import jp.plusplus.fbs.item.ItemCore;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MathHelper;
import net.minecraft.util.StatCollector;
import shift.mceconomy2.api.MCEconomyAPI;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Random;
/**
* Created by plusplus_F on 2015/10/21.
*/
public class InventoryEnchantment implements IInventory {
public EntityPlayer player;
public ItemStack[] itemStacks=new ItemStack[3];
protected Random rand=new Random();
public InventoryEnchantment(EntityPlayer ep){
player=ep;
}
@Override
public int getSizeInventory() {
return itemStacks.length;
}
@Override
public ItemStack getStackInSlot(int p_70301_1_) {
return itemStacks[p_70301_1_];
}
@Override
public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) {
if (this.itemStacks[p_70298_1_] != null) {
ItemStack itemstack;
if (this.itemStacks[p_70298_1_].stackSize <= p_70298_2_) {
itemstack = this.itemStacks[p_70298_1_];
this.itemStacks[p_70298_1_] = null;
this.markDirty();
return itemstack;
} else {
itemstack = this.itemStacks[p_70298_1_].splitStack(p_70298_2_);
if (this.itemStacks[p_70298_1_].stackSize == 0) {
this.itemStacks[p_70298_1_] = null;
}
this.markDirty();
return itemstack;
}
}
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
if (this.itemStacks[p_70304_1_] != null) {
ItemStack itemstack = this.itemStacks[p_70304_1_];
this.itemStacks[p_70304_1_] = null;
return itemstack;
}
return null;
}
@Override
public void setInventorySlotContents(int p_70299_1_, ItemStack p_70299_2_) {
this.itemStacks[p_70299_1_] = p_70299_2_;
if (p_70299_2_ != null && p_70299_2_.stackSize > this.getInventoryStackLimit()) {
p_70299_2_.stackSize = this.getInventoryStackLimit();
}
this.markDirty();
}
@Override
public String getInventoryName() {
return StatCollector.translateToLocal(ItemCore.enchantScroll.getUnlocalizedName()+".name");
}
@Override
public boolean hasCustomInventoryName() {
return false;
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public void markDirty() {
}
@Override
public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
return true;
}
@Override
public void openInventory() {
}
@Override
public void closeInventory() {
if(player.worldObj.isRemote) return;
for(int i=0;i<itemStacks.length;i++){
ItemStack itemstack = this.getStackInSlot(i);
if (itemstack != null){
float f = this.rand.nextFloat() * 0.8F + 0.1F;
float f1 = this.rand.nextFloat() * 0.8F + 0.1F;
float f2 = this.rand.nextFloat() * 0.8F + 0.1F;
while (itemstack.stackSize > 0){
int k1 = this.rand.nextInt(21) + 10;
if (k1 > itemstack.stackSize){
k1 = itemstack.stackSize;
}
itemstack.stackSize -= k1;
double x=player.posX+f;
double y=player.posY+f1+player.getEyeHeight();
double z=player.posZ+f2;
EntityItem entityitem = new EntityItem(player.worldObj, x, y, z, new ItemStack(itemstack.getItem(), k1, itemstack.getItemDamage()));
if (itemstack.hasTagCompound()){
entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
}
float f3 = 0.05F;
entityitem.motionX = (double)((float)this.rand.nextGaussian() * f3);
entityitem.motionY = (double)((float)this.rand.nextGaussian() * f3 + 0.2F);
entityitem.motionZ = (double)((float)this.rand.nextGaussian() * f3);
player.worldObj.spawnEntityInWorld(entityitem);
}
}
}
}
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
return true;
}
}
|