From 558a36fb47d278d015092a7eae3f15157106b393 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sat, 20 Jul 2019 09:36:04 +0200 Subject: [PATCH] Fix Issue #2 - Moved Block visualization from ticking to rendering - Prevents the server from having to translate a block to its Name (Client-Only Code) --- .../block/SchematicannonTileEntity.java | 49 +++++++++++-------- .../create/gui/SchematicannonScreen.java | 45 +++++++++++------ 2 files changed, 58 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/simibubi/create/block/SchematicannonTileEntity.java b/src/main/java/com/simibubi/create/block/SchematicannonTileEntity.java index 8f259d1a6..e68f6a2b1 100644 --- a/src/main/java/com/simibubi/create/block/SchematicannonTileEntity.java +++ b/src/main/java/com/simibubi/create/block/SchematicannonTileEntity.java @@ -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; @@ -229,6 +229,11 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka state = State.valueOf(compound.getString("State")); 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"); @@ -306,6 +311,9 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka compound.putString("State", state.name()); compound.putInt("AmountPlaced", blocksPlaced); compound.putInt("AmountToPlace", blocksToPlace); + + if (missingBlock != null) + compound.put("MissingBlock", NBTUtil.writeBlockState(missingBlock)); // Settings CompoundNBT options = new CompoundNBT(); @@ -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 @@ -439,7 +448,7 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka state = State.RUNNING; } } - + BlockState blockState = blockReader.getBlockState(target); if (!shouldPlace(target, blockState)) { statusMsg = "Searching"; @@ -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) { @@ -497,7 +506,7 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka // Load blocks into reader Template activeTemplate = BlueprintItem.getSchematic(blueprint); BlockPos anchor = NBTUtil.readBlockPos(blueprint.getTag().getCompound("Anchor")); - + if (activeTemplate.getSize().equals(BlockPos.ZERO)) { state = State.STOPPED; statusMsg = "Schematic File Expired"; @@ -505,13 +514,13 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka inventory.setStackInSlot(1, new ItemStack(AllItems.EMPTY_BLUEPRINT.get())); return; } - + if (!anchor.withinDistance(getPos(), MAX_ANCHOR_DISTANCE)) { state = State.STOPPED; statusMsg = "Target too Far Away"; return; } - + schematicAnchor = anchor; blockReader = new SchematicWorld(new HashMap<>(), new Cuboid(), schematicAnchor); activeTemplate.addBlocksToWorld(blockReader, schematicAnchor, BlueprintItem.getSettings(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; @@ -592,7 +601,7 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka return false; if (!replaceTileEntities && toReplace.hasTileEntity()) return false; - + // Block doesnt have a mapping (Water, lava, etc) if (getItemForBlock(state).getItem() == Items.AIR && state.getBlock() != Blocks.AIR) return false; @@ -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) { @@ -700,12 +709,12 @@ public class SchematicannonTileEntity extends TileEntitySynced implements ITicka public void updateChecklist() { checklist.required.clear(); checklist.blocksNotLoaded = false; - + if (schematicLoaded) { blocksToPlace = blocksPlaced; for (BlockPos pos : blockReader.getAllPositions()) { BlockState required = blockReader.getBlockState(pos.add(schematicAnchor)); - + if (!getWorld().isAreaLoaded(pos.add(schematicAnchor), 0)) { checklist.warnBlockNotLoaded(); continue; diff --git a/src/main/java/com/simibubi/create/gui/SchematicannonScreen.java b/src/main/java/com/simibubi/create/gui/SchematicannonScreen.java index 4a0227660..570ad2529 100644 --- a/src/main/java/com/simibubi/create/gui/SchematicannonScreen.java +++ b/src/main/java/com/simibubi/create/gui/SchematicannonScreen.java @@ -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(4); replaceLevelIndicators = new Vector<>(4); - List icons = ImmutableList.of(ScreenResources.ICON_DONT_REPLACE, ScreenResources.ICON_REPLACE_SOLID, - ScreenResources.ICON_REPLACE_ANY, ScreenResources.ICON_REPLACE_EMPTY); + List icons = ImmutableList.of(ScreenResources.ICON_DONT_REPLACE, + ScreenResources.ICON_REPLACE_SOLID, ScreenResources.ICON_REPLACE_ANY, + ScreenResources.ICON_REPLACE_EMPTY); List toolTips = ImmutableList.of("Don't Replace Solid Blocks", "Replace Solid with Solid", "Replace Solid with Any", "Replace Solid with Empty"); @@ -87,7 +89,7 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen= 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= 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); @@ -314,19 +328,18 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen