Skip to content

Commit

Permalink
Always hide facades when a network tool is held in either hand (#7755)
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte authored Mar 12, 2024
1 parent 94bbdce commit 6b6c37f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 83 deletions.
6 changes: 6 additions & 0 deletions guidebook/items-blocks-machines/facades.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ Be clever with them to improve your base aesthetic or make blocks with different
<IsometricCamera yaw="195" pitch="30" />
</GameScene>

## Hiding Facades

Facades will be hidden while holding a <a href="network_tool.md">network tool</a> in either hand.

You can interact with blocks behind hidden facades without having to remove the facades first.

## Recipe

Place the block you want the texture of in the middle of 4 <ItemLink id="cable_anchor" />s.
Expand Down
6 changes: 6 additions & 0 deletions guidebook/items-blocks-machines/network_tool.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ This window shows
This window is also helpful for figuring out if two different cables or devices are part of the same network when messing around with
[Subnetworks](../ae2-mechanics/subnetworks.md).

## Hiding Facades

<a href="facades.md">Facades</a> will be hidden while holding a network tool in either hand.

You can interact with blocks behind hidden facades without having to remove the facades first.

## Recipe

<RecipeFor id="network_tool" />
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,12 @@
import net.minecraft.world.entity.player.Inventory;

import appeng.client.gui.AEBaseScreen;
import appeng.client.gui.Icon;
import appeng.client.gui.style.ScreenStyle;
import appeng.client.gui.widgets.ToggleButton;
import appeng.core.localization.GuiText;
import appeng.menu.me.networktool.NetworkToolMenu;

public class NetworkToolScreen extends AEBaseScreen<NetworkToolMenu> {

private final ToggleButton transparentFacadesButton;

public NetworkToolScreen(NetworkToolMenu menu, Inventory playerInventory, Component title,
ScreenStyle style) {
super(menu, playerInventory, title, style);

this.transparentFacadesButton = new ToggleButton(Icon.TRANSPARENT_FACADES_OFF, Icon.TRANSPARENT_FACADES_ON,
GuiText.TransparentFacades.text(), GuiText.TransparentFacadesHint.text(),
btn -> menu.toggleFacadeMode());

addToLeftToolbar(this.transparentFacadesButton);
}

@Override
protected void updateBeforeRender() {
super.updateBeforeRender();

this.transparentFacadesButton.setState(menu.isFacadeMode());
}

}
17 changes: 4 additions & 13 deletions src/main/java/appeng/core/AppEngBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.neoforged.bus.api.Event;
import net.neoforged.bus.api.EventPriority;
Expand Down Expand Up @@ -91,7 +89,6 @@
import appeng.init.worldgen.InitStructures;
import appeng.integration.Integrations;
import appeng.items.tools.MemoryCardItem;
import appeng.items.tools.NetworkToolItem;
import appeng.server.AECommand;
import appeng.server.services.ChunkLoadingService;
import appeng.server.testworld.GameTestPlotAdapter;
Expand Down Expand Up @@ -300,15 +297,9 @@ public MinecraftServer getCurrentServer() {

protected final CableRenderMode getCableRenderModeForPlayer(@Nullable Player player) {
if (player != null) {
for (int x = 0; x < Inventory.getSelectionSize(); x++) {
final ItemStack is = player.getInventory().getItem(x);

if (!is.isEmpty() && is.getItem() instanceof NetworkToolItem) {
final CompoundTag c = is.getTag();
if (c != null && c.getBoolean("hideFacades")) {
return CableRenderMode.CABLE_VIEW;
}
}
if (AEItems.NETWORK_TOOL.isSameAs(player.getItemInHand(InteractionHand.MAIN_HAND))
|| AEItems.NETWORK_TOOL.isSameAs(player.getItemInHand(InteractionHand.OFF_HAND))) {
return CableRenderMode.CABLE_VIEW;
}
}

Expand Down
39 changes: 23 additions & 16 deletions src/main/java/appeng/core/AppEngClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.HitResult;
import net.neoforged.api.distmarker.Dist;
Expand All @@ -56,7 +57,6 @@
import net.neoforged.neoforge.event.server.ServerStartingEvent;

import appeng.api.parts.CableRenderMode;
import appeng.api.parts.PartHelper;
import appeng.client.EffectType;
import appeng.client.Hotkeys;
import appeng.client.commands.ClientCommands;
Expand All @@ -77,6 +77,7 @@
import appeng.client.render.effects.EnergyParticleData;
import appeng.client.render.effects.ParticleTypes;
import appeng.client.render.overlay.OverlayManager;
import appeng.core.definitions.AEBlocks;
import appeng.core.network.NetworkHandler;
import appeng.core.network.serverbound.MouseWheelPacket;
import appeng.helpers.IMouseWheelItem;
Expand Down Expand Up @@ -375,7 +376,7 @@ private void spawnLightning(Level level, double posX, double posY, double posZ)
}

private void updateCableRenderMode() {
var currentMode = PartHelper.getCableRenderMode();
var currentMode = getCableRenderMode();

// Handle changes to the cable-rendering mode
if (currentMode == this.prevCableRenderMode) {
Expand All @@ -384,21 +385,25 @@ private void updateCableRenderMode() {

this.prevCableRenderMode = currentMode;

final Minecraft mc = Minecraft.getInstance();
var mc = Minecraft.getInstance();
if (mc.player == null || mc.level == null) {
return;
}

final Player player = mc.player;

final int x = (int) player.getX();
final int y = (int) player.getY();
final int z = (int) player.getZ();

final int range = 16 * 16;

mc.levelRenderer.setBlocksDirty(x - range, y - range, z - range, x + range, y + range,
z + range);
// Invalidate all sections that contain a cable bus within view distance
// This should asynchronously update the chunk meshes and as part of that use the new facade render mode
var viewDistance = (int) Math.ceil(mc.levelRenderer.getLastViewDistance());
ChunkPos.rangeClosed(mc.player.chunkPosition(), viewDistance).forEach(chunkPos -> {
var chunk = mc.level.getChunkSource().getChunkNow(chunkPos.x, chunkPos.z);
if (chunk != null) {
for (var i = 0; i < chunk.getSectionsCount(); i++) {
var section = chunk.getSection(i);
if (section.maybeHas(state -> state.is(AEBlocks.CABLE_BUS.block()))) {
mc.levelRenderer.setSectionDirty(chunkPos.x, chunk.getSectionYFromSectionIndex(i), chunkPos.z);
}
}
}
});
}

@Override
Expand All @@ -407,10 +412,12 @@ public CableRenderMode getCableRenderMode() {
return super.getCableRenderMode();
}

final Minecraft mc = Minecraft.getInstance();
final Player player = mc.player;
var mc = Minecraft.getInstance();
if (mc.player == null) {
return CableRenderMode.STANDARD;
}

return this.getCableRenderModeForPlayer(player);
return this.getCableRenderModeForPlayer(mc.player);
}

@Override
Expand Down
34 changes: 0 additions & 34 deletions src/main/java/appeng/menu/me/networktool/NetworkToolMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
* @see appeng.client.gui.me.networktool.NetworkToolScreen
*/
public class NetworkToolMenu extends AEBaseMenu {

private static final String ACTION_TOGGLE_FACADE_MODE = "toggleFacadeMode";

public static final MenuType<NetworkToolMenu> TYPE = MenuTypeBuilder
.create(NetworkToolMenu::new, NetworkToolMenuHost.class)
.build("networktool");
Expand All @@ -51,36 +48,5 @@ public NetworkToolMenu(int id, Inventory ip, NetworkToolMenuHost host) {
}

this.createPlayerInventorySlots(ip);

registerClientAction(ACTION_TOGGLE_FACADE_MODE, this::toggleFacadeMode);
}

public void toggleFacadeMode() {
if (isClientSide()) {
sendClientAction(ACTION_TOGGLE_FACADE_MODE);
return;
}

var data = this.itemMenuHost.getItemStack().getOrCreateTag();
data.putBoolean("hideFacades", !data.getBoolean("hideFacades"));
this.broadcastChanges();
}

@Override
public void broadcastChanges() {
super.broadcastChanges();

if (this.isValidMenu()) {
var tag = itemMenuHost.getItemStack().getOrCreateTag();
this.setFacadeMode(tag.getBoolean("hideFacades"));
}
}

public boolean isFacadeMode() {
return this.facadeMode;
}

private void setFacadeMode(boolean facadeMode) {
this.facadeMode = facadeMode;
}
}

0 comments on commit 6b6c37f

Please sign in to comment.