- 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;
@ -229,6 +229,11 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
state = State.valueOf(compound.getString("State")); state = State.valueOf(compound.getString("State"));
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");
@ -306,6 +311,9 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
compound.putString("State", state.name()); compound.putString("State", state.name());
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();
@ -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
@ -439,7 +448,7 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
state = State.RUNNING; state = State.RUNNING;
} }
} }
BlockState blockState = blockReader.getBlockState(target); BlockState blockState = blockReader.getBlockState(target);
if (!shouldPlace(target, blockState)) { if (!shouldPlace(target, blockState)) {
statusMsg = "Searching"; statusMsg = "Searching";
@ -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) {
@ -497,7 +506,7 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
// Load blocks into reader // Load blocks into reader
Template activeTemplate = BlueprintItem.getSchematic(blueprint); Template activeTemplate = BlueprintItem.getSchematic(blueprint);
BlockPos anchor = NBTUtil.readBlockPos(blueprint.getTag().getCompound("Anchor")); BlockPos anchor = NBTUtil.readBlockPos(blueprint.getTag().getCompound("Anchor"));
if (activeTemplate.getSize().equals(BlockPos.ZERO)) { if (activeTemplate.getSize().equals(BlockPos.ZERO)) {
state = State.STOPPED; state = State.STOPPED;
statusMsg = "Schematic File Expired"; statusMsg = "Schematic File Expired";
@ -505,13 +514,13 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
inventory.setStackInSlot(1, new ItemStack(AllItems.EMPTY_BLUEPRINT.get())); inventory.setStackInSlot(1, new ItemStack(AllItems.EMPTY_BLUEPRINT.get()));
return; return;
} }
if (!anchor.withinDistance(getPos(), MAX_ANCHOR_DISTANCE)) { if (!anchor.withinDistance(getPos(), MAX_ANCHOR_DISTANCE)) {
state = State.STOPPED; state = State.STOPPED;
statusMsg = "Target too Far Away"; statusMsg = "Target too Far Away";
return; return;
} }
schematicAnchor = anchor; schematicAnchor = anchor;
blockReader = new SchematicWorld(new HashMap<>(), new Cuboid(), schematicAnchor); blockReader = new SchematicWorld(new HashMap<>(), new Cuboid(), schematicAnchor);
activeTemplate.addBlocksToWorld(blockReader, schematicAnchor, BlueprintItem.getSettings(blueprint)); activeTemplate.addBlocksToWorld(blockReader, schematicAnchor, BlueprintItem.getSettings(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;
@ -592,7 +601,7 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
return false; return false;
if (!replaceTileEntities && toReplace.hasTileEntity()) if (!replaceTileEntities && toReplace.hasTileEntity())
return false; return false;
// Block doesnt have a mapping (Water, lava, etc) // Block doesnt have a mapping (Water, lava, etc)
if (getItemForBlock(state).getItem() == Items.AIR && state.getBlock() != Blocks.AIR) if (getItemForBlock(state).getItem() == Items.AIR && state.getBlock() != Blocks.AIR)
return false; return false;
@ -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) {
@ -700,12 +709,12 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka
public void updateChecklist() { public void updateChecklist() {
checklist.required.clear(); checklist.required.clear();
checklist.blocksNotLoaded = false; checklist.blocksNotLoaded = false;
if (schematicLoaded) { if (schematicLoaded) {
blocksToPlace = blocksPlaced; blocksToPlace = blocksPlaced;
for (BlockPos pos : blockReader.getAllPositions()) { for (BlockPos pos : blockReader.getAllPositions()) {
BlockState required = blockReader.getBlockState(pos.add(schematicAnchor)); BlockState required = blockReader.getBlockState(pos.add(schematicAnchor));
if (!getWorld().isAreaLoaded(pos.add(schematicAnchor), 0)) { if (!getWorld().isAreaLoaded(pos.add(schematicAnchor), 0)) {
checklist.warnBlockNotLoaded(); checklist.warnBlockNotLoaded();
continue; continue;

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");
@ -87,7 +89,7 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
skipMissingButton.setToolTip("Skip missing Blocks"); skipMissingButton.setToolTip("Skip missing Blocks");
skipMissingIndicator = new Indicator(x + 106, y + 96, ""); skipMissingIndicator = new Indicator(x + 106, y + 96, "");
Collections.addAll(widgets, skipMissingButton, skipMissingIndicator); Collections.addAll(widgets, skipMissingButton, skipMissingIndicator);
skipTilesButton = new IconButton(x + 124, y + 101, ScreenResources.ICON_SKIP_TILES); skipTilesButton = new IconButton(x + 124, y + 101, ScreenResources.ICON_SKIP_TILES);
skipTilesButton.setToolTip("Protect Tile Entities"); skipTilesButton.setToolTip("Protect Tile Entities");
skipTilesIndicator = new Indicator(x + 124, y + 96, ""); skipTilesIndicator = new Indicator(x + 124, y + 96, "");
@ -219,18 +221,22 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
if (!te.inventory.getStackInSlot(0).isEmpty()) if (!te.inventory.getStackInSlot(0).isEmpty())
renderBlueprintHighlight(); renderBlueprintHighlight();
renderCannon(); renderCannon();
font.drawString("Schematicannon", guiLeft + 80, guiTop + 10, ScreenResources.FONT_COLOR); font.drawString("Schematicannon", guiLeft + 80, guiTop + 10, ScreenResources.FONT_COLOR);
String msg = te.statusMsg; String msg = te.statusMsg;
int stringWidth = font.getStringWidth(msg); int stringWidth = font.getStringWidth(msg);
if (stringWidth < 120)
font.drawStringWithShadow(msg, guiLeft + 20 + 96 - stringWidth / 2, guiTop + 30, 0xCCDDFF); if (te.missingBlock != null) {
else stringWidth += 15;
font.drawSplitString(msg, guiLeft + 20 + 45, guiTop + 24, 120, 0xCCDDFF); 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.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);
@ -314,19 +328,18 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
sendOptionUpdate(Option.values()[replaceMode], true); sendOptionUpdate(Option.values()[replaceMode], true);
} }
if (skipMissingButton.isHovered()) if (skipMissingButton.isHovered())
sendOptionUpdate(Option.SKIP_MISSING, !container.getTileEntity().skipMissing); sendOptionUpdate(Option.SKIP_MISSING, !container.getTileEntity().skipMissing);
if (skipTilesButton.isHovered()) if (skipTilesButton.isHovered())
sendOptionUpdate(Option.SKIP_TILES, !container.getTileEntity().replaceTileEntities); sendOptionUpdate(Option.SKIP_TILES, !container.getTileEntity().replaceTileEntities);
if (playButton.isHovered() && playButton.active) if (playButton.isHovered() && playButton.active)
sendOptionUpdate(Option.PLAY, true); sendOptionUpdate(Option.PLAY, true);
if (pauseButton.isHovered() && pauseButton.active) if (pauseButton.isHovered() && pauseButton.active)
sendOptionUpdate(Option.PAUSE, true); sendOptionUpdate(Option.PAUSE, true);
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);
} }