Pedestals and rituals state saving

This commit is contained in:
Aleksey 2020-11-10 13:51:25 +03:00
parent c7d8365765
commit 28427f54a3
3 changed files with 21 additions and 10 deletions

View file

@ -238,7 +238,6 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
@Override @Override
public void tick() { public void tick() {
boolean initialBurning = this.isBurning(); boolean initialBurning = this.isBurning();
boolean smelting = false;
if (initialBurning) { if (initialBurning) {
this.burnTime--; this.burnTime--;
} }
@ -261,7 +260,6 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
this.fuelTime = this.burnTime; this.fuelTime = this.burnTime;
burning = this.isBurning(); burning = this.isBurning();
if (burning) { if (burning) {
smelting = true;
if (!fuel.isEmpty()) { if (!fuel.isEmpty()) {
Item item = fuel.getItem(); Item item = fuel.getItem();
fuel.decrement(1); fuel.decrement(1);
@ -270,6 +268,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
this.inventory.set(2, remainFuel == null ? ItemStack.EMPTY : new ItemStack(remainFuel)); this.inventory.set(2, remainFuel == null ? ItemStack.EMPTY : new ItemStack(remainFuel));
} }
} }
this.markDirty();
} }
} }
@ -279,7 +278,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
this.smeltTime = 0; this.smeltTime = 0;
this.smeltTimeTotal = this.getSmeltTime(); this.smeltTimeTotal = this.getSmeltTime();
this.craftRecipe(recipe); this.craftRecipe(recipe);
smelting = true; this.markDirty();
} }
} else { } else {
this.smeltTime = 0; this.smeltTime = 0;
@ -287,15 +286,11 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
} }
if (initialBurning != burning) { if (initialBurning != burning) {
smelting = true;
this.world.setBlockState(pos, world.getBlockState(pos).with(EndStoneSmelter.LIT, burning), 3); this.world.setBlockState(pos, world.getBlockState(pos).with(EndStoneSmelter.LIT, burning), 3);
}
}
if (smelting) {
this.markDirty(); this.markDirty();
} }
} }
}
protected boolean canAcceptRecipeOutput(Recipe<?> recipe) { protected boolean canAcceptRecipeOutput(Recipe<?> recipe) {
if (recipe == null) return false; if (recipe == null) return false;

View file

@ -38,6 +38,7 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
@Override @Override
public void clear() { public void clear() {
this.activeItem = ItemStack.EMPTY; this.activeItem = ItemStack.EMPTY;
this.markDirty();
} }
@Override @Override
@ -62,7 +63,10 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
@Override @Override
public ItemStack removeStack(int slot) { public ItemStack removeStack(int slot) {
return this.activeItem = ItemStack.EMPTY; ItemStack stored = this.activeItem;
this.activeItem = ItemStack.EMPTY;
this.markDirty();
return stored;
} }
public void removeStack(World world, BlockState state) { public void removeStack(World world, BlockState state) {
@ -73,6 +77,7 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
@Override @Override
public void setStack(int slot, ItemStack stack) { public void setStack(int slot, ItemStack stack) {
this.activeItem = stack; this.activeItem = stack;
this.markDirty();
} }
public void setStack(World world, BlockState state, ItemStack stack) { public void setStack(World world, BlockState state, ItemStack stack) {

View file

@ -66,11 +66,13 @@ public class InfusionRitual implements Inventory {
this.activeRecipe = null; this.activeRecipe = null;
this.progress = 0; this.progress = 0;
this.time = 0; this.time = 0;
this.markDirty();
return false; return false;
} else if (recipe != activeRecipe) { } else if (recipe != activeRecipe) {
this.activeRecipe = recipe; this.activeRecipe = recipe;
this.time = this.activeRecipe.getInfusionTime(); this.time = this.activeRecipe.getInfusionTime();
this.progress = 0; this.progress = 0;
this.markDirty();
} }
return true; return true;
} }
@ -78,6 +80,7 @@ public class InfusionRitual implements Inventory {
if (activeRecipe != null) { if (activeRecipe != null) {
this.time = this.activeRecipe.getInfusionTime(); this.time = this.activeRecipe.getInfusionTime();
this.progress = 0; this.progress = 0;
this.markDirty();
return true; return true;
} }
return false; return false;
@ -97,6 +100,7 @@ public class InfusionRitual implements Inventory {
this.activeRecipe = null; this.activeRecipe = null;
this.progress = 0; this.progress = 0;
this.time = 0; this.time = 0;
this.markDirty();
} else { } else {
ServerWorld world = (ServerWorld) this.world; ServerWorld world = (ServerWorld) this.world;
BlockPos target = this.worldPos.up(); BlockPos target = this.worldPos.up();
@ -193,7 +197,14 @@ public class InfusionRitual implements Inventory {
} }
@Override @Override
public void markDirty() {} public void markDirty() {
if (isValid()) {
this.input.markDirty();
for (PedestalBlockEntity catalyst : catalysts) {
catalyst.markDirty();
}
}
}
@Override @Override
public boolean canPlayerUse(PlayerEntity player) { public boolean canPlayerUse(PlayerEntity player) {