mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-29 00:09:17 +00:00
Fix Auto Chisel visuals not updating when base was replaced
This commit is contained in:
1 parent
1afc214356
commit
ac3b049df8
1 file changed
+54
-38
@@ -80,8 +80,10 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
|
||||
public boolean chiseling = false, breakChisel = false;;
|
||||
public int toChisel = 1;
|
||||
|
||||
// Client-side visual cache
|
||||
private ItemStack lastBase;
|
||||
|
||||
// Server-side crafting caches
|
||||
private ItemStack baseCache = null;
|
||||
private ItemStack targetCache = null;
|
||||
private ItemStack reversionTargetCache = null;
|
||||
@@ -131,13 +133,26 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
ItemStack base = inventory[BASE];
|
||||
if (base == null) {
|
||||
baseCache = targetCache = reversionTargetCache = null;
|
||||
if (!worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (baseCache != base) {
|
||||
baseCache = base;
|
||||
reversionTargetCache = null;
|
||||
progress = 0;
|
||||
}
|
||||
|
||||
// Client-side visuals
|
||||
if (worldObj.isRemote) {
|
||||
if (chiseling) {
|
||||
chiselRot += rotAmnt;
|
||||
if (chiselRot >= maxRot) {
|
||||
// Play Chisel SFX
|
||||
chiselItem(0, getTarget());
|
||||
playChiselingEffects();
|
||||
}
|
||||
} else {
|
||||
chiselRot = Math.max(chiselRot - rotAmnt, 0);
|
||||
@@ -146,15 +161,13 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
|
||||
}
|
||||
|
||||
// Server-side crafting
|
||||
ItemStack base = inventory[BASE];
|
||||
ItemStack target = getTarget();
|
||||
if (base == null || target == null || !hasChisel()) {
|
||||
baseCache = targetCache = null;
|
||||
if (target == null || !hasChisel()) {
|
||||
baseCache = targetCache = reversionTargetCache = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (baseCache != base && targetCache != target) {
|
||||
baseCache = base;
|
||||
if (targetCache != target) {
|
||||
targetCache = target;
|
||||
progress = 0;
|
||||
}
|
||||
@@ -190,7 +203,6 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
|
||||
result.stackSize = hasUpgrade(Upgrade.STACK) ? maxCraftSize : 1;
|
||||
|
||||
if (canChisel(result)) {
|
||||
// Use (and possibly break) the chisel
|
||||
chiselItem(result.stackSize, target);
|
||||
|
||||
base.stackSize -= result.stackSize;
|
||||
@@ -249,37 +261,41 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
|
||||
|
||||
/** Calls IChiselItem#onChisel() and sends the chisel packet for sound/animation */
|
||||
private void chiselItem(int chiseled, ItemStack target) {
|
||||
if (!worldObj.isRemote) {
|
||||
boolean breakChisel = false;
|
||||
if (((IChiselItem) inventory[CHISEL].getItem())
|
||||
.onChisel(worldObj, inventory[CHISEL], General.getVariation(target))) {
|
||||
inventory[CHISEL].setItemDamage(inventory[CHISEL].getItemDamage() + 1);
|
||||
if (inventory[CHISEL].getItemDamage() >= inventory[CHISEL].getMaxDamage()) {
|
||||
setInventorySlotContents(CHISEL, null);
|
||||
breakChisel = true;
|
||||
}
|
||||
if (worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean breakChisel = false;
|
||||
if (((IChiselItem) inventory[CHISEL].getItem())
|
||||
.onChisel(worldObj, inventory[CHISEL], General.getVariation(target))) {
|
||||
inventory[CHISEL].setItemDamage(inventory[CHISEL].getItemDamage() + 1);
|
||||
if (inventory[CHISEL].getItemDamage() >= inventory[CHISEL].getMaxDamage()) {
|
||||
setInventorySlotContents(CHISEL, null);
|
||||
breakChisel = true;
|
||||
}
|
||||
PacketHandler.INSTANCE.sendToDimension(
|
||||
new MessageAutoChisel(this, chiseled, true, breakChisel),
|
||||
worldObj.provider.dimensionId);
|
||||
} else {
|
||||
if (breakChisel) {
|
||||
worldObj.playSound(
|
||||
xCoord + 0.5,
|
||||
yCoord + 0.5,
|
||||
zCoord + 0.5,
|
||||
"random.break",
|
||||
0.8F,
|
||||
0.8F + worldObj.rand.nextFloat() * 0.4F,
|
||||
false);
|
||||
}
|
||||
GeneralChiselClient.spawnAutoChiselFX(this, lastBase != null ? lastBase : inventory[BASE]);
|
||||
chiseling = false;
|
||||
if (lastBase != null) {
|
||||
lastBase.stackSize -= toChisel;
|
||||
if (lastBase.stackSize <= 0) {
|
||||
lastBase = null;
|
||||
}
|
||||
}
|
||||
PacketHandler.INSTANCE
|
||||
.sendToDimension(new MessageAutoChisel(this, chiseled, true, breakChisel), worldObj.provider.dimensionId);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private void playChiselingEffects() {
|
||||
if (breakChisel) {
|
||||
worldObj.playSound(
|
||||
xCoord + 0.5,
|
||||
yCoord + 0.5,
|
||||
zCoord + 0.5,
|
||||
"random.break",
|
||||
0.8F,
|
||||
0.8F + worldObj.rand.nextFloat() * 0.4F,
|
||||
false);
|
||||
}
|
||||
GeneralChiselClient.spawnAutoChiselFX(this, lastBase != null ? lastBase : inventory[BASE]);
|
||||
chiseling = false;
|
||||
if (lastBase != null) {
|
||||
lastBase.stackSize -= toChisel;
|
||||
if (lastBase.stackSize <= 0) {
|
||||
lastBase = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user