-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Autocrafting notifications
- Loading branch information
Showing
20 changed files
with
272 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
.../refinedmods/refinedstorage/common/autocrafting/PlatformAutocraftingNetworkComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.refinedmods.refinedstorage.common.autocrafting; | ||
|
||
import com.refinedmods.refinedstorage.api.autocrafting.task.Task; | ||
import com.refinedmods.refinedstorage.api.network.impl.autocrafting.AutocraftingNetworkComponentImpl; | ||
import com.refinedmods.refinedstorage.api.storage.root.RootStorage; | ||
import com.refinedmods.refinedstorage.common.Platform; | ||
import com.refinedmods.refinedstorage.common.api.storage.PlayerActor; | ||
import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey; | ||
import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingTaskCompletedPacket; | ||
import com.refinedmods.refinedstorage.common.util.ServerListener; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.function.Supplier; | ||
|
||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.level.ServerPlayer; | ||
|
||
public class PlatformAutocraftingNetworkComponent extends AutocraftingNetworkComponentImpl { | ||
public PlatformAutocraftingNetworkComponent(final Supplier<RootStorage> rootStorageProvider, | ||
final ExecutorService executorService) { | ||
super(rootStorageProvider, executorService); | ||
} | ||
|
||
@Override | ||
public void taskRemoved(final Task task) { | ||
super.taskRemoved(task); | ||
if (task.shouldNotify() | ||
&& task.getActor() instanceof PlayerActor(String name) | ||
&& task.getResource() instanceof PlatformResourceKey resource) { | ||
sendToClient(task, name, resource); | ||
} | ||
} | ||
|
||
private static void sendToClient(final Task task, final String name, final PlatformResourceKey resource) { | ||
ServerListener.queue(server -> sendToClient(task, name, resource, server)); | ||
} | ||
|
||
private static void sendToClient(final Task task, | ||
final String name, | ||
final PlatformResourceKey resource, | ||
final MinecraftServer server) { | ||
final ServerPlayer player = server.getPlayerList().getPlayerByName(name); | ||
if (player == null) { | ||
return; | ||
} | ||
Platform.INSTANCE.sendPacketToClient(player, new AutocraftingTaskCompletedPacket( | ||
resource, | ||
task.getAmount() | ||
)); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
.../src/main/java/com/refinedmods/refinedstorage/common/autocrafting/TaskCompletedToast.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.refinedmods.refinedstorage.common.autocrafting; | ||
|
||
import com.refinedmods.refinedstorage.api.resource.ResourceKey; | ||
import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; | ||
import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.Font; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.components.toasts.Toast; | ||
import net.minecraft.client.gui.components.toasts.ToastComponent; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.chat.MutableComponent; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; | ||
import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; | ||
|
||
public class TaskCompletedToast implements Toast { | ||
private static final ResourceLocation SPRITE = createIdentifier("autocrafting_task_completed_toast"); | ||
private static final MutableComponent TITLE = createTranslation( | ||
"misc", | ||
"autocrafting_task_completed" | ||
); | ||
|
||
private static final long TIME_VISIBLE = 5000; | ||
private static final int MARGIN = 4; | ||
|
||
private final ResourceKey resource; | ||
private final ResourceRendering rendering; | ||
private final MutableComponent resourceTitle; | ||
|
||
public TaskCompletedToast(final ResourceKey resource, final long amount) { | ||
this.resource = resource; | ||
this.rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering(resource.getClass()); | ||
this.resourceTitle = Component.literal(rendering.formatAmount(amount, true)) | ||
.append(" ") | ||
.append(rendering.getDisplayName(resource)); | ||
} | ||
|
||
@Override | ||
public Visibility render(final GuiGraphics graphics, | ||
final ToastComponent toastComponent, | ||
final long timeSinceLastVisible) { | ||
graphics.blitSprite(SPRITE, 0, 0, width(), height()); | ||
rendering.render(resource, graphics, 8, 8); | ||
final Font font = Minecraft.getInstance().font; | ||
graphics.drawString(font, TITLE, 8 + 18 + MARGIN, 7, 0xFFFFA500); | ||
graphics.drawString(font, resourceTitle, 8 + 18 + MARGIN, 7 + 2 + 9, 0xFFFFFFFF); | ||
return timeSinceLastVisible >= TIME_VISIBLE ? Visibility.HIDE : Visibility.SHOW; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.