This commit is contained in:
Aleksey 2021-02-27 00:39:17 +03:00
parent db2a555ae9
commit 616c824257
6 changed files with 123 additions and 125 deletions

View file

@ -48,7 +48,7 @@ public class InfusionRitual implements Inventory {
if (world == null || world.isClient || worldPos == null) return;
BlockEntity inputEntity = world.getBlockEntity(worldPos);
if (inputEntity instanceof InfusionPedestalEntity) {
this.input = (InfusionPedestalEntity) inputEntity;
input = (InfusionPedestalEntity) inputEntity;
}
int i = 0;
for(Point point : PEDESTALS_MAP) {
@ -65,59 +65,59 @@ public class InfusionRitual implements Inventory {
public boolean checkRecipe() {
if (!isValid()) return false;
InfusionRecipe recipe = this.world.getRecipeManager().getFirstMatch(InfusionRecipe.TYPE, this, world).orElse(null);
InfusionRecipe recipe = world.getRecipeManager().getFirstMatch(InfusionRecipe.TYPE, this, world).orElse(null);
if (hasRecipe()) {
if (recipe == null) {
this.stop();
stop();
return false;
} else if (recipe.getInfusionTime() != time) {
this.activeRecipe = recipe;
this.time = this.activeRecipe.getInfusionTime();
this.progress = 0;
this.markDirty();
activeRecipe = recipe;
time = activeRecipe.getInfusionTime();
progress = 0;
markDirty();
} else if (activeRecipe == null) {
this.activeRecipe = recipe;
activeRecipe = recipe;
}
return true;
}
if (recipe != null) {
this.activeRecipe = recipe;
this.time = this.activeRecipe.getInfusionTime();
this.hasRecipe = true;
this.progress = 0;
this.markDirty();
activeRecipe = recipe;
time = activeRecipe.getInfusionTime();
hasRecipe = true;
progress = 0;
markDirty();
return true;
}
return false;
}
public void stop() {
this.activeRecipe = null;
this.hasRecipe = false;
this.progress = 0;
this.time = 0;
this.markDirty();
activeRecipe = null;
hasRecipe = false;
progress = 0;
time = 0;
markDirty();
}
public void tick() {
if (isDirty) {
this.configure();
this.isDirty = false;
configure();
isDirty = false;
}
if (!isValid() || !hasRecipe()) return;
if (!checkRecipe()) return;
this.progress++;
progress++;
if (progress == time) {
BlockState inputState = world.getBlockState(input.getPos());
this.input.removeStack(world, inputState);
this.input.setStack(0, activeRecipe.craft(this));
input.removeStack(0);
input.setStack(0, activeRecipe.craft(this));
for (PedestalBlockEntity catalyst : catalysts) {
catalyst.removeStack(world, world.getBlockState(catalyst.getPos()));
catalyst.removeStack(0);
}
this.stop();
stop();
} else {
ServerWorld world = (ServerWorld) this.world;
BlockPos target = this.worldPos.up();
BlockPos target = worldPos.up();
double tx = target.getX() + 0.5;
double ty = target.getY() + 0.5;
double tz = target.getZ() + 0.5;
@ -137,7 +137,7 @@ public class InfusionRitual implements Inventory {
@Override
public boolean isValid(int slot, ItemStack stack) {
return this.isValid();
return isValid();
}
public boolean isValid() {
@ -149,7 +149,7 @@ public class InfusionRitual implements Inventory {
}
public boolean hasRecipe() {
return this.hasRecipe;
return hasRecipe;
}
public void setLocation(World world, BlockPos pos) {
@ -161,7 +161,7 @@ public class InfusionRitual implements Inventory {
@Override
public void clear() {
if (!isValid()) return;
this.input.clear();
input.clear();
for (PedestalBlockEntity catalyst : catalysts) {
catalyst.clear();
}
@ -181,24 +181,24 @@ public class InfusionRitual implements Inventory {
public ItemStack getStack(int slot) {
if (slot > 8) return ItemStack.EMPTY;
if (slot == 0) {
return this.input.getStack(0);
return input.getStack(0);
} else {
return this.catalysts[slot - 1].getStack(0);
return catalysts[slot - 1].getStack(0);
}
}
@Override
public ItemStack removeStack(int slot, int amount) {
return this.removeStack(slot);
return removeStack(slot);
}
@Override
public ItemStack removeStack(int slot) {
if (slot > 8) return ItemStack.EMPTY;
if (slot == 0) {
return this.input.removeStack(0);
return input.removeStack(0);
} else {
return this.catalysts[slot - 1].getStack(0);
return catalysts[slot - 1].getStack(0);
}
}
@ -206,16 +206,16 @@ public class InfusionRitual implements Inventory {
public void setStack(int slot, ItemStack stack) {
if (slot > 8) return;
if (slot == 0) {
this.input.setStack(0, stack);
input.setStack(0, stack);
} else {
this.catalysts[slot - 1].setStack(0, stack);
catalysts[slot - 1].setStack(0, stack);
}
}
@Override
public void markDirty() {
if (isValid()) {
this.input.markDirty();
input.markDirty();
for (PedestalBlockEntity catalyst : catalysts) {
catalyst.markDirty();
}
@ -229,15 +229,15 @@ public class InfusionRitual implements Inventory {
public void fromTag(CompoundTag tag) {
if (tag.contains("recipe")) {
this.hasRecipe = tag.getBoolean("recipe");
this.progress = tag.getInt("progress");
this.time = tag.getInt("time");
hasRecipe = tag.getBoolean("recipe");
progress = tag.getInt("progress");
time = tag.getInt("time");
}
}
public CompoundTag toTag(CompoundTag tag) {
if (hasRecipe()) {
tag.putBoolean("recipe", this.hasRecipe);
tag.putBoolean("recipe", hasRecipe);
tag.putInt("progress", progress);
tag.putInt("time", time);
}