- 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 currentPos;
public BlockPos schematicAnchor; public BlockPos schematicAnchor;
public boolean schematicLoaded; public boolean schematicLoaded;
public boolean missingBlock; public BlockState missingBlock;
public boolean blockNotLoaded; public boolean blockNotLoaded;
public boolean hasCreativeCrate; public boolean hasCreativeCrate;
private int printerCooldown; private int printerCooldown;
@ -230,6 +230,11 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
blocksPlaced = compound.getInt("AmountPlaced"); blocksPlaced = compound.getInt("AmountPlaced");
blocksToPlace = compound.getInt("AmountToPlace"); blocksToPlace = compound.getInt("AmountToPlace");
if (compound.contains("MissingBlock"))
missingBlock = NBTUtil.readBlockState(compound.getCompound("MissingBlock"));
else
missingBlock = null;
// Settings // Settings
CompoundNBT options = compound.getCompound("Options"); CompoundNBT options = compound.getCompound("Options");
replaceMode = options.getInt("ReplaceMode"); replaceMode = options.getInt("ReplaceMode");
@ -307,6 +312,9 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
compound.putInt("AmountPlaced", blocksPlaced); compound.putInt("AmountPlaced", blocksPlaced);
compound.putInt("AmountToPlace", blocksToPlace); compound.putInt("AmountToPlace", blocksToPlace);
if (missingBlock != null)
compound.put("MissingBlock", NBTUtil.writeBlockState(missingBlock));
// Settings // Settings
CompoundNBT options = new CompoundNBT(); CompoundNBT options = new CompoundNBT();
options.putInt("ReplaceMode", replaceMode); options.putInt("ReplaceMode", replaceMode);
@ -385,7 +393,7 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
return; return;
} }
if (state == State.PAUSED && !blockNotLoaded && !missingBlock && fuelLevel > FUEL_USAGE_RATE) if (state == State.PAUSED && !blockNotLoaded && missingBlock == null && fuelLevel > FUEL_USAGE_RATE)
return; return;
// Initialize Printer // Initialize Printer
@ -411,12 +419,13 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
// Update Target // Update Target
if (hasCreativeCrate) { if (hasCreativeCrate) {
if (missingBlock) { if (missingBlock != null) {
missingBlock = false; missingBlock = null;
state = State.RUNNING; state = State.RUNNING;
} }
} }
if (!missingBlock && !blockNotLoaded) {
if (missingBlock == null && !blockNotLoaded) {
advanceCurrentPos(); advanceCurrentPos();
// End reached // End reached
@ -453,16 +462,16 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
if (skipMissing) { if (skipMissing) {
statusMsg = "Skipping"; statusMsg = "Skipping";
blockSkipped = true; blockSkipped = true;
if (missingBlock) { if (missingBlock != null) {
missingBlock = false; missingBlock = null;
state = State.RUNNING; state = State.RUNNING;
} }
return; return;
} }
missingBlock = true; missingBlock = blockState;
state = State.PAUSED; state = State.PAUSED;
statusMsg = "Missing " + blockState.getBlock().getNameTextComponent().getFormattedText(); statusMsg = "Missing Block: ";
return; return;
} }
@ -476,7 +485,7 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
printerCooldown = PLACEMENT_DELAY; printerCooldown = PLACEMENT_DELAY;
fuelLevel -= FUEL_USAGE_RATE; fuelLevel -= FUEL_USAGE_RATE;
sendUpdate = true; sendUpdate = true;
missingBlock = false; missingBlock = null;
} }
protected void initializePrinter(ItemStack blueprint) { protected void initializePrinter(ItemStack blueprint) {
@ -575,7 +584,7 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
schematicAnchor = null; schematicAnchor = null;
currentPos = null; currentPos = null;
blockReader = null; blockReader = null;
missingBlock = false; missingBlock = null;
sendUpdate = true; sendUpdate = true;
schematicProgress = 0; schematicProgress = 0;
blocksPlaced = 0; blocksPlaced = 0;
@ -678,8 +687,8 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
if (state.getBlock() != Blocks.AIR) if (state.getBlock() != Blocks.AIR)
blocksPlaced++; blocksPlaced++;
flyingBlocks.add(new LaunchedBlock(target, state)); flyingBlocks.add(new LaunchedBlock(target, state));
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_GENERIC_EXPLODE,
.1f, 1.1f); SoundCategory.BLOCKS, .1f, 1.1f);
} }
public void sendToContainer(PacketBuffer buffer) { 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.gui.widget.Widget;
import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
@ -69,8 +70,9 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
// Replace settings // Replace settings
replaceLevelButtons = new Vector<>(4); replaceLevelButtons = new Vector<>(4);
replaceLevelIndicators = new Vector<>(4); replaceLevelIndicators = new Vector<>(4);
List<ScreenResources> icons = ImmutableList.of(ScreenResources.ICON_DONT_REPLACE, ScreenResources.ICON_REPLACE_SOLID, List<ScreenResources> icons = ImmutableList.of(ScreenResources.ICON_DONT_REPLACE,
ScreenResources.ICON_REPLACE_ANY, ScreenResources.ICON_REPLACE_EMPTY); 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", List<String> toolTips = ImmutableList.of("Don't Replace Solid Blocks", "Replace Solid with Solid",
"Replace Solid with Any", "Replace Solid with Empty"); "Replace Solid with Any", "Replace Solid with Empty");
@ -226,10 +228,14 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
String msg = te.statusMsg; String msg = te.statusMsg;
int stringWidth = font.getStringWidth(msg); 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); 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("Placement Settings", guiLeft + 20 + 13, guiTop + 84, ScreenResources.FONT_COLOR);
font.drawString("Inventory", guiLeft - 10 + 7, guiTop + 145 + 6, 0x666666); font.drawString("Inventory", guiLeft - 10 + 7, guiTop + 145 + 6, 0x666666);
@ -281,10 +287,10 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
@Override @Override
protected void renderWindowForeground(int mouseX, int mouseY, float partialTicks) { protected void renderWindowForeground(int mouseX, int mouseY, float partialTicks) {
int fuelX = guiLeft + 20 + 73, fuelY = guiTop + 135; int fuelX = guiLeft + 20 + 73, fuelY = guiTop + 135;
SchematicannonTileEntity te = container.getTileEntity();
if (mouseX >= fuelX && mouseY >= fuelY && mouseX <= fuelX + ScreenResources.SCHEMATICANNON_FUEL.width if (mouseX >= fuelX && mouseY >= fuelY && mouseX <= fuelX + ScreenResources.SCHEMATICANNON_FUEL.width
&& mouseY <= fuelY + ScreenResources.SCHEMATICANNON_FUEL.height) { && mouseY <= fuelY + ScreenResources.SCHEMATICANNON_FUEL.height) {
container.getTileEntity(); container.getTileEntity();
SchematicannonTileEntity te = container.getTileEntity();
int shotsLeft = (int) (te.fuelLevel / SchematicannonTileEntity.FUEL_USAGE_RATE); int shotsLeft = (int) (te.fuelLevel / SchematicannonTileEntity.FUEL_USAGE_RATE);
int shotsLeftWithItems = (int) (shotsLeft + te.inventory.getStackInSlot(4).getCount() int shotsLeftWithItems = (int) (shotsLeft + te.inventory.getStackInSlot(4).getCount()
* (SchematicannonTileEntity.FUEL_PER_GUNPOWDER / SchematicannonTileEntity.FUEL_USAGE_RATE)); * (SchematicannonTileEntity.FUEL_PER_GUNPOWDER / SchematicannonTileEntity.FUEL_USAGE_RATE));
@ -295,6 +301,14 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
mouseX, mouseY); 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; int paperX = guiLeft + 20 + 202, paperY = guiTop + 20;
if (mouseX >= paperX && mouseY >= paperY && mouseX <= paperX + 16 && mouseY <= paperY + 16) { if (mouseX >= paperX && mouseY >= paperY && mouseX <= paperX + 16 && mouseY <= paperY + 16) {
renderTooltip("Material List Printer", mouseX, mouseY); renderTooltip("Material List Printer", mouseX, mouseY);
@ -326,7 +340,6 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
if (resetButton.isHovered() && resetButton.active) if (resetButton.isHovered() && resetButton.active)
sendOptionUpdate(Option.STOP, true); sendOptionUpdate(Option.STOP, true);
return super.mouseClicked(x, y, button); return super.mouseClicked(x, y, button);
} }