- Moved Block visualization from ticking to rendering
- Prevents the server from having to translate a block to its Name (Client-Only Code)
This commit is contained in:
simibubi 2019-07-20 09:36:04 +02:00
parent dbfb60b809
commit 558a36fb47
2 changed files with 58 additions and 36 deletions

View file

@ -71,7 +71,7 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
public BlockPos currentPos;
public BlockPos schematicAnchor;
public boolean schematicLoaded;
public boolean missingBlock;
public BlockState missingBlock;
public boolean blockNotLoaded;
public boolean hasCreativeCrate;
private int printerCooldown;
@ -230,6 +230,11 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
blocksPlaced = compound.getInt("AmountPlaced");
blocksToPlace = compound.getInt("AmountToPlace");
if (compound.contains("MissingBlock"))
missingBlock = NBTUtil.readBlockState(compound.getCompound("MissingBlock"));
else
missingBlock = null;
// Settings
CompoundNBT options = compound.getCompound("Options");
replaceMode = options.getInt("ReplaceMode");
@ -307,6 +312,9 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
compound.putInt("AmountPlaced", blocksPlaced);
compound.putInt("AmountToPlace", blocksToPlace);
if (missingBlock != null)
compound.put("MissingBlock", NBTUtil.writeBlockState(missingBlock));
// Settings
CompoundNBT options = new CompoundNBT();
options.putInt("ReplaceMode", replaceMode);
@ -385,7 +393,7 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
return;
}
if (state == State.PAUSED && !blockNotLoaded && !missingBlock && fuelLevel > FUEL_USAGE_RATE)
if (state == State.PAUSED && !blockNotLoaded && missingBlock == null && fuelLevel > FUEL_USAGE_RATE)
return;
// Initialize Printer
@ -411,12 +419,13 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
// Update Target
if (hasCreativeCrate) {
if (missingBlock) {
missingBlock = false;
if (missingBlock != null) {
missingBlock = null;
state = State.RUNNING;
}
}
if (!missingBlock && !blockNotLoaded) {
if (missingBlock == null && !blockNotLoaded) {
advanceCurrentPos();
// End reached
@ -453,16 +462,16 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
if (skipMissing) {
statusMsg = "Skipping";
blockSkipped = true;
if (missingBlock) {
missingBlock = false;
if (missingBlock != null) {
missingBlock = null;
state = State.RUNNING;
}
return;
}
missingBlock = true;
missingBlock = blockState;
state = State.PAUSED;
statusMsg = "Missing " + blockState.getBlock().getNameTextComponent().getFormattedText();
statusMsg = "Missing Block: ";
return;
}
@ -476,7 +485,7 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
printerCooldown = PLACEMENT_DELAY;
fuelLevel -= FUEL_USAGE_RATE;
sendUpdate = true;
missingBlock = false;
missingBlock = null;
}
protected void initializePrinter(ItemStack blueprint) {
@ -575,7 +584,7 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
schematicAnchor = null;
currentPos = null;
blockReader = null;
missingBlock = false;
missingBlock = null;
sendUpdate = true;
schematicProgress = 0;
blocksPlaced = 0;
@ -678,8 +687,8 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
if (state.getBlock() != Blocks.AIR)
blocksPlaced++;
flyingBlocks.add(new LaunchedBlock(target, state));
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS,
.1f, 1.1f);
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_GENERIC_EXPLODE,
SoundCategory.BLOCKS, .1f, 1.1f);
}
public void sendToContainer(PacketBuffer buffer) {

View file

@ -19,6 +19,7 @@ import com.simibubi.create.networking.AllPackets;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
@ -69,8 +70,9 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
// Replace settings
replaceLevelButtons = new Vector<>(4);
replaceLevelIndicators = new Vector<>(4);
List<ScreenResources> icons = ImmutableList.of(ScreenResources.ICON_DONT_REPLACE, ScreenResources.ICON_REPLACE_SOLID,
ScreenResources.ICON_REPLACE_ANY, ScreenResources.ICON_REPLACE_EMPTY);
List<ScreenResources> icons = ImmutableList.of(ScreenResources.ICON_DONT_REPLACE,
ScreenResources.ICON_REPLACE_SOLID, ScreenResources.ICON_REPLACE_ANY,
ScreenResources.ICON_REPLACE_EMPTY);
List<String> toolTips = ImmutableList.of("Don't Replace Solid Blocks", "Replace Solid with Solid",
"Replace Solid with Any", "Replace Solid with Empty");
@ -226,10 +228,14 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
String msg = te.statusMsg;
int stringWidth = font.getStringWidth(msg);
if (stringWidth < 120)
if (te.missingBlock != null) {
stringWidth += 15;
itemRenderer.renderItemIntoGUI(new ItemStack(BlockItem.BLOCK_TO_ITEM.get(te.missingBlock.getBlock())),
guiLeft + 145, guiTop + 25);
}
font.drawStringWithShadow(msg, guiLeft + 20 + 96 - stringWidth / 2, guiTop + 30, 0xCCDDFF);
else
font.drawSplitString(msg, guiLeft + 20 + 45, guiTop + 24, 120, 0xCCDDFF);
font.drawString("Placement Settings", guiLeft + 20 + 13, guiTop + 84, ScreenResources.FONT_COLOR);
font.drawString("Inventory", guiLeft - 10 + 7, guiTop + 145 + 6, 0x666666);
@ -281,10 +287,10 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
@Override
protected void renderWindowForeground(int mouseX, int mouseY, float partialTicks) {
int fuelX = guiLeft + 20 + 73, fuelY = guiTop + 135;
SchematicannonTileEntity te = container.getTileEntity();
if (mouseX >= fuelX && mouseY >= fuelY && mouseX <= fuelX + ScreenResources.SCHEMATICANNON_FUEL.width
&& mouseY <= fuelY + ScreenResources.SCHEMATICANNON_FUEL.height) {
container.getTileEntity();
SchematicannonTileEntity te = container.getTileEntity();
int shotsLeft = (int) (te.fuelLevel / SchematicannonTileEntity.FUEL_USAGE_RATE);
int shotsLeftWithItems = (int) (shotsLeft + te.inventory.getStackInSlot(4).getCount()
* (SchematicannonTileEntity.FUEL_PER_GUNPOWDER / SchematicannonTileEntity.FUEL_USAGE_RATE));
@ -295,6 +301,14 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
mouseX, mouseY);
}
if (te.missingBlock != null) {
int missingBlockX = guiLeft + 145, missingBlockY = guiTop + 25;
if (mouseX >= missingBlockX && mouseY >= missingBlockY && mouseX <= missingBlockX + 16
&& mouseY <= missingBlockY + 16) {
renderTooltip(new ItemStack(BlockItem.BLOCK_TO_ITEM.get(te.missingBlock.getBlock())), mouseX, mouseY);
}
}
int paperX = guiLeft + 20 + 202, paperY = guiTop + 20;
if (mouseX >= paperX && mouseY >= paperY && mouseX <= paperX + 16 && mouseY <= paperY + 16) {
renderTooltip("Material List Printer", mouseX, mouseY);
@ -326,7 +340,6 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
if (resetButton.isHovered() && resetButton.active)
sendOptionUpdate(Option.STOP, true);
return super.mouseClicked(x, y, button);
}