jopi
Попрошайка
- 1,421
- 30
- 260
Проблема века.
В общем суть, написал блок, он должен исходя из заданных рецептов начать процесс переработки и из слотов 1, 2 должен по рецепту выдать предметы в слоты 3, 4, слот 0 для подзарядки(необязательный крч)
Слоты при процессе 3 и 4 должны быть пусты, когда я ложу предмет совпадающий с рецептом начинается процесс, визуально ничего потому-что почему?
а потому-что при сравнивании рецептов происходит ошибка. Когда я вывожу в debug id итемов и их damage, я получаю в консоли:
1260 0 -1 -1 (1-й предмет 1260 с damage = 0 а 2 предмета нет)
рецепт такой существует, но я вижу не просто 1 такую строку каждую секунду, а вижу:
Почему обновляется более 1 раза? Из-за этого рецепт проверяется неправильно.
TileEntity:
Класс рецепта:
В общем суть, написал блок, он должен исходя из заданных рецептов начать процесс переработки и из слотов 1, 2 должен по рецепту выдать предметы в слоты 3, 4, слот 0 для подзарядки(необязательный крч)
Слоты при процессе 3 и 4 должны быть пусты, когда я ложу предмет совпадающий с рецептом начинается процесс, визуально ничего потому-что почему?
а потому-что при сравнивании рецептов происходит ошибка. Когда я вывожу в debug id итемов и их damage, я получаю в консоли:
1260 0 -1 -1 (1-й предмет 1260 с damage = 0 а 2 предмета нет)
рецепт такой существует, но я вижу не просто 1 такую строку каждую секунду, а вижу:
Java:
1260 0 -1 -1
-1 -1 -1 -1
-1 -1 -1 -1
-1 -1 -1 -1
TileEntity:
Java:
public void updateEntity() {
super.updateEntity();
if (++this.tick >= 20 && !super.worldObj.isRemote) {
this.tick = 0;
try {
PacketDispatcher.sendPacketToAllAround((double) super.xCoord, (double) super.yCoord, (double) super.zCoord, 50.0D, super.worldObj.provider.dimensionId, this.getDescriptionPacket());
if (this.charge < this.maxCharge) this.charge++;
ItemStack item0 = super.ItemStacks[0];
ItemStack item1 = super.ItemStacks[1];
ItemStack item2 = super.ItemStacks[2];
if (item0 != null) {
Integer chargein = 0;
Integer killers = 0;
switch(item0.itemID) {
case 173:
chargein = 80;
killers = 3;
break;
case 263:
chargein = 8;
killers = 2;
break;
case 1257:
chargein = 2;
killers = 1;
break;
}
if ((this.charge + chargein) <= this.maxCharge && this.life >= killers) {
this.charge += chargein;
this.life -= killers;
if (item0.stackSize == 1)
super.ItemStacks[0] = null;
else
super.ItemStacks[0].stackSize--;
}
}
Integer[] build = new Integer[4];
if (super.ItemStacks[1] != null) {
build[0] = super.ItemStacks[1].itemID;
build[1] = super.ItemStacks[1].getItemDamage();
} else
build[0] = build[1] = -1;
if (super.ItemStacks[2] != null) {
build[2] = super.ItemStacks[2].itemID;
build[3] = super.ItemStacks[2].getItemDamage();
} else
build[2] = build[3] = -1;
if (!this.isWorking) {
System.out.println("yie"); //срабатывает
if (this.hasRecipe(build[0], build[1], build[2], build[3])) { //не проходит проверку
if (this.life > 0) {
this.isWorking = true;
this.time++;
this.recipeID = this.getRecipe(build[0], build[1], build[2], build[3]).getID();
System.out.println("yey"); //не срабатывает
return;
}
}
} else {
build = new Integer[]{item1 == null ? -1 : item1.itemID, item1 == null ? -1 : item1.getItemDamage(), item2 == null ? -1 : item2.itemID, item2 == null ? -1 : item2.getItemDamage()};
if (this.hasRecipe(build[0], build[1], build[2], build[3])) {
if (this.life > 0 && this.charge >= this.getRecipe(build[0], build[1], build[2], build[3]).getEnergy()) {
if (this.recipeID == this.getRecipe(build[0], build[1], build[2], build[3]).getID()) {
if (super.ItemStacks[3] == null && super.ItemStacks[4] == null) {
if (this.time >= 19) {
if (super.ItemStacks[1] != null) {
if (super.ItemStacks[1].stackSize < 2) {
super.ItemStacks[1] = null;
}
else {
super.ItemStacks[1].stackSize--;
}
}
if (super.ItemStacks[2] != null) {
if (super.ItemStacks[2].stackSize < 2) {
super.ItemStacks[2] = null;
}
else {
super.ItemStacks[2].stackSize--;
}
}
if (this.recipes.get(this.recipeID).getStack(3) != null) super.ItemStacks[3] = this.recipes.get(this.recipeID).getStack(3);
if (this.recipes.get(this.recipeID).getStack(4) != null) super.ItemStacks[4] = this.recipes.get(this.recipeID).getStack(4);
this.time = 0;
this.isWorking = false;
this.life--;
this.charge -= this.recipes.get(this.recipeID).getEnergy();
this.recipeID = -1;
return;
} else {
this.time++;
return;
}
}
}
}
}
}
this.time = 0;
this.isWorking = false;
this.recipeID = -1;
} catch (Exception var6) {
}
}
}
public boolean hasRecipe(int i1, int i2, int b1, int b2) {
for (int i = 0; i != this.recipes.size(); i++) {
if (this.recipes.get(i) != null) {
RecoveryPlantRecipe rpr = this.recipes.get(i);
if (rpr.getItemID(1) == i1 && rpr.getItemID(2) == b1) {
if (rpr.getItemDamage(1) == i2 && rpr.getItemDamage(2) == b2) {
return true;
}
}
}
}
return false;
}
Класс рецепта:
Код:
package hardpla.systems;
import net.minecraft.item.ItemStack;
public class RecoveryPlantRecipe {
private ItemStack si1;
private ItemStack si2;
private ItemStack ou1;
private ItemStack ou2;
private int energy;
private int id;
public RecoveryPlantRecipe(ItemStack si1, ItemStack si2, ItemStack ou1, ItemStack ou2, int energy, int id) {
this.si1 = si1;
this.si2 = si2;
this.ou1 = ou1;
this.ou2 = ou2;
this.energy = energy;
this.id = id;
}
public Integer getItemID(int par1) {
return par1 == 1 ? (this.si1 == null ? -1 : this.si1.itemID) : (par1 == 2 ? (this.si2 == null ? -1 : this.si2.itemID) : (par1 == 3 ? (this.ou1 == null ? -1 : this.ou1.itemID) : par1 == 4 ? (this.ou2 == null ? -1 : this.ou2.itemID) : -1));
}
public Integer getItemStackSize(int par1) {
return par1 == 1 ? (this.si1 == null ? -1 : this.si1.stackSize) : (par1 == 2 ? (this.si2 == null ? -1 : this.si2.stackSize) : (par1 == 3 ? (this.ou1 == null ? -1 : this.ou1.stackSize) : par1 == 4 ? (this.ou2 == null ? -1 : this.ou2.stackSize) : -1));
}
public Integer getItemDamage(int par1) {
return par1 == 1 ? (this.si1 == null ? -1 : this.si1.getItemDamage()) : (par1 == 2 ? (this.si2 == null ? -1 : this.si2.getItemDamage()) : (par1 == 3 ? (this.ou1 == null ? -1 : this.ou1.getItemDamage()) : par1 == 4 ? (this.ou2 == null ? -1 : this.ou2.getItemDamage()) : -1));
}
public ItemStack getStack(int par1) {
return par1 == 1 ? this.si1 : (par1 == 2 ? this.si2 : (par1 == 3 ? this.ou1 : (par1 == 4 ? this.ou2 : null)));
}
public Integer getEnergy() {
return this.energy;
}
public Integer getID() {
return this.id;
}
}
Java:
Последнее редактирование модератором: