generated from NeoForgeMDKs/MDK-1.21-NeoGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
622c741
commit f483db8
Showing
22 changed files
with
505 additions
and
112 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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/portingdeadmods/nautec/api/bacteria/CollapsedBacteriaStats.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,16 @@ | ||
package com.portingdeadmods.nautec.api.bacteria; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.portingdeadmods.nautec.NTRegistries; | ||
import net.minecraft.network.RegistryFriendlyByteBuf; | ||
import net.minecraft.network.codec.ByteBufCodecs; | ||
import net.minecraft.network.codec.StreamCodec; | ||
|
||
public interface CollapsedBacteriaStats { | ||
Codec<CollapsedBacteriaStats> CODEC = | ||
NTRegistries.BACTERIA_STATS_SERIALIZER.byNameCodec().dispatch(CollapsedBacteriaStats::getSerializer, BacteriaStatsSerializer::collapsedMapCodec); | ||
StreamCodec<RegistryFriendlyByteBuf, CollapsedBacteriaStats> STREAM_CODEC = | ||
ByteBufCodecs.registry(NTRegistries.BACTERIA_STATS_SERIALIZER_KEY).dispatch(CollapsedBacteriaStats::getSerializer, BacteriaStatsSerializer::collapsedStreamCodec); | ||
|
||
BacteriaStatsSerializer<?, ?> getSerializer(); | ||
} |
95 changes: 95 additions & 0 deletions
95
src/main/java/com/portingdeadmods/nautec/api/client/screen/NTMachineScreen.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,95 @@ | ||
package com.portingdeadmods.nautec.api.client.screen; | ||
|
||
import com.portingdeadmods.nautec.api.blockentities.ContainerBlockEntity; | ||
import com.portingdeadmods.nautec.api.menu.NTMachineMenu; | ||
import com.portingdeadmods.nautec.api.menu.slots.SlotBacteriaStorage; | ||
import com.portingdeadmods.nautec.api.menu.slots.SlotFluidHandler; | ||
import net.minecraft.ChatFormatting; | ||
import net.minecraft.client.gui.Font; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.player.Inventory; | ||
import net.neoforged.neoforge.fluids.FluidStack; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.text.NumberFormat; | ||
import java.util.List; | ||
|
||
public abstract class NTMachineScreen<T extends ContainerBlockEntity> extends AbstractContainerScreen<NTMachineMenu<T>> { | ||
private SlotFluidHandler hoveredFluidHandlerSlot; | ||
private SlotBacteriaStorage hoveredBacteriaStorageSlot; | ||
|
||
private final NumberFormat nf = NumberFormat.getIntegerInstance(); | ||
|
||
public NTMachineScreen(NTMachineMenu<T> menu, Inventory playerInventory, Component title) { | ||
super(menu, playerInventory, title); | ||
|
||
this.titleLabelY = 4; | ||
this.imageHeight = 174; | ||
} | ||
|
||
@Override | ||
public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) { | ||
renderBackground(pGuiGraphics, pMouseX, pMouseX, pPartialTick); | ||
super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick); | ||
renderTooltip(pGuiGraphics, pMouseX, pMouseY); | ||
|
||
hoverFluidSlot(pMouseX, pMouseY); | ||
|
||
hoverBacteriaSlot(pMouseX, pMouseY); | ||
|
||
Font font = minecraft.font; | ||
if (this.hoveredBacteriaStorageSlot != null) { | ||
SimpleCollapsedStats | ||
pGuiGraphics.renderComponentTooltip(font, List.of(Component.literal("Bacteria Storage")), pMouseX, pMouseY); | ||
} | ||
|
||
if (this.hoveredFluidHandlerSlot != null) { | ||
FluidStack fluid = this.hoveredFluidHandlerSlot.getFluidStack(); | ||
pGuiGraphics.renderComponentTooltip(font, List.of( | ||
fluid.getHoverName(), | ||
Component.literal("%s / %s mb".formatted( | ||
nf.format(fluid.getAmount()), | ||
nf.format(this.hoveredFluidHandlerSlot.getFluidCapacity())) | ||
).withStyle(ChatFormatting.GRAY) | ||
), pMouseX, pMouseY); | ||
} | ||
} | ||
|
||
private void hoverFluidSlot(int pMouseX, int pMouseY) { | ||
for (SlotFluidHandler fSlot : menu.getFluidTankSlots()) { | ||
if (isHovering(fSlot.getX(), fSlot.getY(), fSlot.getWidth(), fSlot.getHeight(), pMouseX, pMouseY)) { | ||
this.hoveredFluidHandlerSlot = fSlot; | ||
return; | ||
} | ||
} | ||
this.hoveredFluidHandlerSlot = null; | ||
} | ||
|
||
private void hoverBacteriaSlot(int pMouseX, int pMouseY) { | ||
for (SlotBacteriaStorage bSlot : menu.getBacteriaStorageSlots()) { | ||
if (isHovering(bSlot.getX(), bSlot.getY(), bSlot.getWidth(), bSlot.getHeight(), pMouseX, pMouseY)) { | ||
this.hoveredBacteriaStorageSlot = bSlot; | ||
return; | ||
} | ||
} | ||
this.hoveredBacteriaStorageSlot = null; | ||
} | ||
|
||
@Override | ||
protected void renderBg(GuiGraphics guiGraphics, float delta, int mouseX, int mouseY) { | ||
guiGraphics.blit(getBackgroundTexture(), leftPos, topPos, 0, 0, imageWidth, imageHeight); | ||
} | ||
|
||
public abstract @NotNull ResourceLocation getBackgroundTexture(); | ||
|
||
public SlotFluidHandler getHoveredFluidHandlerSlot() { | ||
return hoveredFluidHandlerSlot; | ||
} | ||
|
||
public SlotBacteriaStorage getHoveredBacteriaStorageSlot() { | ||
return hoveredBacteriaStorageSlot; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/portingdeadmods/nautec/api/menu/NTMachineMenu.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,40 @@ | ||
package com.portingdeadmods.nautec.api.menu; | ||
|
||
import com.portingdeadmods.nautec.api.blockentities.ContainerBlockEntity; | ||
import com.portingdeadmods.nautec.api.menu.slots.SlotBacteriaStorage; | ||
import com.portingdeadmods.nautec.api.menu.slots.SlotFluidHandler; | ||
import net.minecraft.core.NonNullList; | ||
import net.minecraft.world.entity.player.Inventory; | ||
import net.minecraft.world.inventory.MenuType; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public abstract class NTMachineMenu<T extends ContainerBlockEntity> extends NTAbstractContainerMenu<T> { | ||
private final NonNullList<SlotFluidHandler> fluidTankSlots; | ||
private final NonNullList<SlotBacteriaStorage> bacteriaStorageSlots; | ||
|
||
public NTMachineMenu(MenuType<?> menuType, int containerId, @NotNull Inventory inv, @NotNull T blockEntity) { | ||
super(menuType, containerId, inv, blockEntity); | ||
|
||
addPlayerInventory(inv, 92); | ||
addPlayerHotbar(inv, 150); | ||
|
||
this.fluidTankSlots = NonNullList.create(); | ||
this.bacteriaStorageSlots = NonNullList.create(); | ||
} | ||
|
||
public void addFluidHandlerSlot(SlotFluidHandler slot) { | ||
this.fluidTankSlots.add(slot); | ||
} | ||
|
||
public void addBacteriaStorageSlot(SlotBacteriaStorage slot) { | ||
this.bacteriaStorageSlots.add(slot); | ||
} | ||
|
||
public NonNullList<SlotFluidHandler> getFluidTankSlots() { | ||
return fluidTankSlots; | ||
} | ||
|
||
public NonNullList<SlotBacteriaStorage> getBacteriaStorageSlots() { | ||
return bacteriaStorageSlots; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/portingdeadmods/nautec/api/menu/slots/AbstractSlot.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,24 @@ | ||
package com.portingdeadmods.nautec.api.menu.slots; | ||
|
||
import net.neoforged.neoforge.fluids.capability.IFluidHandler; | ||
|
||
public abstract class AbstractSlot { | ||
protected final int slot; | ||
public int index; | ||
protected final int x; | ||
protected final int y; | ||
|
||
public AbstractSlot(int index, int x, int y) { | ||
this.slot = index; | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
public int getX() { | ||
return x; | ||
} | ||
|
||
public int getY() { | ||
return y; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/portingdeadmods/nautec/api/menu/slots/SlotBacteriaStorage.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,26 @@ | ||
package com.portingdeadmods.nautec.api.menu.slots; | ||
|
||
import com.portingdeadmods.nautec.capabilities.bacteria.IBacteriaStorage; | ||
|
||
public class SlotBacteriaStorage extends AbstractSlot { | ||
private static final int WIDTH = 18; | ||
private static final int HEIGHT = 18; | ||
private final IBacteriaStorage bacteriaStorage; | ||
|
||
public SlotBacteriaStorage(IBacteriaStorage bacteriaStorage, int index, int x, int y) { | ||
super(index, x, y); | ||
this.bacteriaStorage = bacteriaStorage; | ||
} | ||
|
||
public IBacteriaStorage getBacteriaStorage() { | ||
return bacteriaStorage; | ||
} | ||
|
||
public int getWidth() { | ||
return WIDTH; | ||
} | ||
|
||
public int getHeight() { | ||
return HEIGHT; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/portingdeadmods/nautec/api/menu/slots/SlotFluidHandler.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,37 @@ | ||
package com.portingdeadmods.nautec.api.menu.slots; | ||
|
||
import net.neoforged.neoforge.fluids.FluidStack; | ||
import net.neoforged.neoforge.fluids.capability.IFluidHandler; | ||
|
||
public class SlotFluidHandler extends AbstractSlot { | ||
private final IFluidHandler fluidHandler; | ||
private final int width; | ||
private final int height; | ||
|
||
public SlotFluidHandler(IFluidHandler fluidHandler, int index, int x, int y, int width, int height) { | ||
super(index, x, y); | ||
this.fluidHandler = fluidHandler; | ||
this.width = width; | ||
this.height = height; | ||
} | ||
|
||
public FluidStack getFluidStack() { | ||
return fluidHandler.getFluidInTank(slot); | ||
} | ||
|
||
public int getFluidCapacity() { | ||
return fluidHandler.getTankCapacity(slot); | ||
} | ||
|
||
public int getWidth() { | ||
return width; | ||
} | ||
|
||
public int getHeight() { | ||
return height; | ||
} | ||
|
||
public IFluidHandler getFluidHandler() { | ||
return fluidHandler; | ||
} | ||
} |
Oops, something went wrong.