mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-10 12:34:11 +01:00
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)
This commit is contained in:
parent
dbfb60b809
commit
558a36fb47
@ -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;
|
||||
|
@ -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");
|
||||
|
||||
@ -87,7 +89,7 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
|
||||
skipMissingButton.setToolTip("Skip missing Blocks");
|
||||
skipMissingIndicator = new Indicator(x + 106, y + 96, "");
|
||||
Collections.addAll(widgets, skipMissingButton, skipMissingIndicator);
|
||||
|
||||
|
||||
skipTilesButton = new IconButton(x + 124, y + 101, ScreenResources.ICON_SKIP_TILES);
|
||||
skipTilesButton.setToolTip("Protect Tile Entities");
|
||||
skipTilesIndicator = new Indicator(x + 124, y + 96, "");
|
||||
@ -219,18 +221,22 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
|
||||
|
||||
if (!te.inventory.getStackInSlot(0).isEmpty())
|
||||
renderBlueprintHighlight();
|
||||
|
||||
|
||||
renderCannon();
|
||||
|
||||
font.drawString("Schematicannon", guiLeft + 80, guiTop + 10, ScreenResources.FONT_COLOR);
|
||||
|
||||
String msg = te.statusMsg;
|
||||
int stringWidth = font.getStringWidth(msg);
|
||||
if (stringWidth < 120)
|
||||
font.drawStringWithShadow(msg, guiLeft + 20 + 96 - stringWidth / 2, guiTop + 30, 0xCCDDFF);
|
||||
else
|
||||
font.drawSplitString(msg, guiLeft + 20 + 45, guiTop + 24, 120, 0xCCDDFF);
|
||||
|
||||
|
||||
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.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);
|
||||
@ -314,19 +328,18 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
|
||||
sendOptionUpdate(Option.values()[replaceMode], true);
|
||||
}
|
||||
|
||||
if (skipMissingButton.isHovered())
|
||||
if (skipMissingButton.isHovered())
|
||||
sendOptionUpdate(Option.SKIP_MISSING, !container.getTileEntity().skipMissing);
|
||||
if (skipTilesButton.isHovered())
|
||||
if (skipTilesButton.isHovered())
|
||||
sendOptionUpdate(Option.SKIP_TILES, !container.getTileEntity().replaceTileEntities);
|
||||
|
||||
if (playButton.isHovered() && playButton.active)
|
||||
if (playButton.isHovered() && playButton.active)
|
||||
sendOptionUpdate(Option.PLAY, true);
|
||||
if (pauseButton.isHovered() && pauseButton.active)
|
||||
if (pauseButton.isHovered() && pauseButton.active)
|
||||
sendOptionUpdate(Option.PAUSE, true);
|
||||
if (resetButton.isHovered() && resetButton.active)
|
||||
if (resetButton.isHovered() && resetButton.active)
|
||||
sendOptionUpdate(Option.STOP, true);
|
||||
|
||||
|
||||
return super.mouseClicked(x, y, button);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user