Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VAT #631

Merged
merged 19 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,34 @@
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.client.gui.components.WidgetSprites;
import net.minecraft.network.chat.Component;

import javax.annotation.Nullable;

// Wrapper for ImageButton to draw background.
// Can be removed after GUI redesign if no longer required.
public class EIOImageButton extends ImageButton {

private final EIOScreen<?> addedOn;
private final EIOScreen<?> screen;
@Nullable private final Component message;

public EIOImageButton(EIOScreen<?> addedOn, int x, int y, int width, int height, WidgetSprites sprites, OnPress onPress) {
public EIOImageButton(EIOScreen<?> screen, int x, int y, int width, int height, WidgetSprites sprites, OnPress onPress, @Nullable Component message) {
super(x, y, width, height, sprites, onPress);
this.addedOn = addedOn;
this.screen = screen;
this.message = message;
}

public EIOImageButton(EIOScreen<?> screen, int x, int y, int width, int height, WidgetSprites sprites, OnPress onPress) {
this(screen, x, y, width, height, sprites, onPress, null);
}

@Override
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
addedOn.renderSimpleArea(guiGraphics, new Vector2i(getX(), getY()), new Vector2i(getX() + getWidth(), getY() + getHeight()));
screen.renderSimpleArea(guiGraphics, new Vector2i(getX(), getY()), new Vector2i(getX() + getWidth(), getY() + getHeight()));
super.renderWidget(guiGraphics, mouseX, mouseY, partialTick);

if (this.isHovered() && message != null) {
guiGraphics.renderTooltip(screen.getMinecraft().font, message, mouseX, mouseY);
}
}
}
19 changes: 19 additions & 0 deletions src/generated/resources/assets/enderio/blockstates/vat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"variants": {
"facing=east": {
"model": "enderio:block/vat_combined",
"y": 90
},
"facing=north": {
"model": "enderio:block/vat_combined"
},
"facing=south": {
"model": "enderio:block/vat_combined",
"y": 180
},
"facing=west": {
"model": "enderio:block/vat_combined",
"y": 270
}
}
}
3 changes: 3 additions & 0 deletions src/generated/resources/assets/enderio/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
"block.enderio.travel_anchor": "Travel Anchor",
"block.enderio.vacuum_chest": "Vacuum Chest",
"block.enderio.vapor_of_levity": "Vapor Of Levity",
"block.enderio.vat": "VAT",
"block.enderio.vibrant_alloy_block": "Vibrant Alloy Block",
"block.enderio.vibrant_capacitor_bank": "Vibrant Capacitor Bank",
"block.enderio.vibrant_photovoltaic_module": "Vibrant Photovoltaic Module",
Expand Down Expand Up @@ -237,12 +238,14 @@
"gui.enderio.alloy_smelter.mode_alloy": "Alloys Only",
"gui.enderio.alloy_smelter.mode_furnace": "Furnace Only",
"gui.enderio.blocked_redstone": "The machine is blocked by redstone",
"gui.enderio.button.dump_tank": "Void tank contents",
"gui.enderio.button.retrieve_10_level": "Retrieve 10 levels of XP",
"gui.enderio.button.retrieve_1_level": "Retrieve 1 level of XP",
"gui.enderio.button.retrieve_all_level": "Retrieve all levels of XP",
"gui.enderio.button.store_10_level": "Store 10 levels of XP",
"gui.enderio.button.store_1_level": "Store 1 level of XP",
"gui.enderio.button.store_all_level": "Store all levels of XP",
"gui.enderio.button.transfer_tank": "Transfer tank contents",
"gui.enderio.cancel": "Cancel",
"gui.enderio.category.alloy_smelting": "Alloy Smelting",
"gui.enderio.category.enchanter": "Enchanting",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"parent": "minecraft:block/block",
"children": {
"machine": {
"parent": "enderio:block/vat"
},
"overlay": {
"parent": "enderio:block/io_overlay"
}
},
"item_render_order": [
"machine",
"overlay"
],
"loader": "neoforge:composite",
"textures": {
"particle": "enderio:block/vat_front"
}
}
3 changes: 3 additions & 0 deletions src/generated/resources/assets/enderio/models/item/vat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "enderio:block/vat"
}
5 changes: 5 additions & 0 deletions src/generated/resources/data/c/tags/item/crops.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"minecraft:wheat"
]
}
5 changes: 5 additions & 0 deletions src/generated/resources/data/c/tags/item/seeds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"minecraft:wheat"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"values": {
"minecraft:wheat": {
"#c:crops": 3.0,
"#c:seeds": 2.0
}
}
}
22 changes: 22 additions & 0 deletions src/generated/resources/data/enderio/loot_table/blocks/vat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:item",
"functions": [
{
"function": "minecraft:copy_components",
"source": "block_entity"
}
],
"name": "enderio:vat"
}
],
"rolls": 1.0
}
],
"random_sequence": "enderio:blocks/vat"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"type": "enderio:vat_fermenting",
"input": {
"amount": 1000,
"tag": "minecraft:water"
},
"left_reagent": "c:seeds",
"output": {
"amount": 250,
"id": "enderio:fluid_hootch_still"
},
"right_reagent": "c:crops",
"ticks": 100
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"enderio:crafter",
"enderio:soul_engine",
"enderio:drain",
"enderio:vat",
"enderio:xp_obelisk",
"enderio:conduit"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"enderio:crafter",
"enderio:soul_engine",
"enderio:drain",
"enderio:vat",
"enderio:xp_obelisk"
]
}
4 changes: 4 additions & 0 deletions src/machines/java/com/enderio/machines/EIOMachines.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import com.enderio.machines.common.menu.PreviewMachineSlot;
import com.enderio.machines.common.tag.MachineTags;
import com.enderio.machines.data.advancements.MachinesAdvancementGenerator;
import com.enderio.machines.data.reagentdata.ReagentDataProvider;
import com.enderio.machines.data.recipes.AlloyRecipeProvider;
import com.enderio.machines.data.recipes.EnchanterRecipeProvider;
import com.enderio.machines.data.recipes.FermentingRecipeProvider;
import com.enderio.machines.data.recipes.MachineRecipeProvider;
import com.enderio.machines.data.recipes.PaintingRecipeProvider;
import com.enderio.machines.data.recipes.SagMillRecipeProvider;
Expand Down Expand Up @@ -88,13 +90,15 @@ public static void gatherData(GatherDataEvent event) {
provider.addSubProvider(event.includeServer(), new MachineRecipeProvider(packOutput, lookupProvider));
provider.addSubProvider(event.includeServer(), new AlloyRecipeProvider(packOutput, lookupProvider));
provider.addSubProvider(event.includeServer(), new EnchanterRecipeProvider(packOutput, lookupProvider));
provider.addSubProvider(event.includeServer(), new FermentingRecipeProvider(packOutput, lookupProvider));
provider.addSubProvider(event.includeServer(), new SagMillRecipeProvider(packOutput, lookupProvider));
provider.addSubProvider(event.includeServer(), new SlicingRecipeProvider(packOutput, lookupProvider));
provider.addSubProvider(event.includeServer(), new SoulBindingRecipeProvider(packOutput, lookupProvider));
provider.addSubProvider(event.includeServer(), new TankRecipeProvider(packOutput, lookupProvider));
provider.addSubProvider(event.includeServer(), new PaintingRecipeProvider(packOutput, lookupProvider));
provider.addSubProvider(event.includeServer(), new SoulDataProvider(packOutput));
provider.addSubProvider(event.includeServer(), new MachineEntityTypeTagsProvider(packOutput, lookupProvider, event.getExistingFileHelper()));
provider.addSubProvider(event.includeServer(), new ReagentDataProvider(packOutput, lookupProvider, event.getExistingFileHelper()));

generator.addProvider(true, provider);
provider.addSubProvider(event.includeServer(), new AdvancementProvider(packOutput, event.getLookupProvider(), event.getExistingFileHelper(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package com.enderio.machines.client.gui.screen;

import com.enderio.EnderIO;
import com.enderio.api.misc.Vector2i;
import com.enderio.base.common.lang.EIOLang;
import com.enderio.core.client.gui.screen.EIOScreen;
import com.enderio.core.client.gui.widgets.EIOImageButton;
import com.enderio.core.client.gui.widgets.EnumIconWidget;
import com.enderio.machines.client.gui.widget.ActivityWidget;
import com.enderio.machines.client.gui.widget.FermentationWidget;
import com.enderio.machines.client.gui.widget.FluidStackWidget;
import com.enderio.machines.client.gui.widget.ProgressWidget;
import com.enderio.machines.client.gui.widget.ioconfig.IOConfigButton;
import com.enderio.machines.common.io.fluid.MachineFluidTank;
import com.enderio.machines.common.lang.MachineLang;
import com.enderio.machines.common.menu.VatMenu;
import com.enderio.machines.common.recipe.FermentingRecipe;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.WidgetSprites;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.neoforged.neoforge.fluids.FluidStack;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;

public class VatScreen extends EIOScreen<VatMenu> {

private static final ResourceLocation VAT_BG = EnderIO.loc("textures/gui/vat.png");
private static final ResourceLocation VAT_COVER = EnderIO.loc("vat_cover");
public static final ResourceLocation MOVE_FLUID = EnderIO.loc("buttons/move_fluid");
public static final ResourceLocation VOID_FLUID = EnderIO.loc("buttons/void_fluid");

private FermentingRecipe recipeCache;
private ResourceLocation recipeId;

public VatScreen(VatMenu pMenu, Inventory pPlayerInventory, Component pTitle) {
super(pMenu, pPlayerInventory, pTitle, false);
}

@Override
protected void init() {
super.init();
updateRecipeCache();
addRenderableOnly(new FluidStackWidget(this, this::wrappedInputTank, 30 + leftPos, 12 + topPos, 15, 47));
addRenderableOnly(new FluidStackWidget(this, getMenu().getBlockEntity()::getOutputTank, 132 + leftPos, 12 + topPos, 15, 47));

addRenderableOnly(
new FermentationWidget(this::isCrafting, this::inputFluidStack, this::outputFluidStack, this::getProgress, 76 + leftPos, 34 + topPos, 26, 28));

addRenderableOnly(new ProgressWidget.BottomUp(this, this::getProgress, 82 + leftPos, 64 + topPos, 14, 14, 176, 0));

addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 6 - 16, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE));

addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 24, 16, 16, menu, this::addRenderableWidget, font));
addRenderableWidget(new ActivityWidget(this, menu.getBlockEntity()::getMachineStates, leftPos + imageWidth - 6 - 16, topPos + 16 * 4));

addRenderableWidget(new EIOImageButton(this, leftPos + 29, topPos + 62, 16, 16, new WidgetSprites(MOVE_FLUID, MOVE_FLUID),
dphaldes marked this conversation as resolved.
Show resolved Hide resolved
press -> menu.getBlockEntity().moveFluidToOutputTank(), MachineLang.TRANSFER_TANK));

addRenderableWidget(new EIOImageButton(this, leftPos + 131, topPos + 62, 16, 16, new WidgetSprites(VOID_FLUID, VOID_FLUID),
press -> menu.getBlockEntity().dumpOutputTank(), MachineLang.DUMP_TANK));
}

@Override
public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) {
updateRecipeCache();
super.render(guiGraphics, pMouseX, pMouseY, pPartialTicks);

guiGraphics.blitSprite(VAT_COVER, 76 + leftPos, 34 + topPos, 26, 28);
drawModifierStrings(guiGraphics);
}

@Override
public ResourceLocation getBackgroundImage() {
return VAT_BG;
}

@Override
protected Vector2i getBackgroundImageSize() {
return new Vector2i(176, 166);
}

private void updateRecipeCache() {
if (recipeId != getMenu().getBlockEntity().getRecipeId()) {
recipeId = getMenu().getBlockEntity().getRecipeId();
Optional<RecipeHolder<?>> optional = Minecraft.getInstance().level.getRecipeManager().byKey(recipeId);
if (optional.isPresent() && optional.get().value() instanceof FermentingRecipe recipe) {
recipeCache = recipe;
}
}
}

private boolean isCrafting() {
return recipeCache != null && getMenu().getBlockEntity().getCraftingHost().getProgress() > 0;
}

private FluidStack inputFluidStack() {
return getMenu().getBlockEntity().getInputTank().getFluid();
}

private FluidStack outputFluidStack() {
return recipeCache.output();
}

private float getProgress() {
return menu.getBlockEntity().getProgress();
}

/**
* Wraps the essential parts of the input tank. Remove the amount of fluid in client screen to fake the effect of consumption of fluid.
*/
private MachineFluidTank wrappedInputTank() {
MachineFluidTank tank = getMenu().getBlockEntity().getInputTank();
return new MachineFluidTank(0, null) {
@Override
public @NotNull FluidStack getFluid() {
return tank.getFluid();
}

@Override
public int getFluidAmount() {
int reduced = 0;
if (isCrafting()) {
reduced = recipeCache.input().amount();
}
return Math.max(tank.getFluidAmount() - reduced, 0);
}

@Override
public int getCapacity() {
return tank.getCapacity();
}
};
}

private void drawModifierStrings(GuiGraphics guiGraphics) {
if (!isCrafting()) {
return;
}
// left modifier
ItemStack item = getMenu().getSlot(0).getItem();
double modifier = FermentingRecipe.getModifier(item, recipeCache.leftReagent());
String text = "x" + modifier;
int x = getGuiLeft() + 63 - minecraft.font.width(text) / 2;
guiGraphics.drawString(minecraft.font, text, x, getGuiTop() + 32, 4210752, false);

// right modifier
item = getMenu().getSlot(1).getItem();
modifier = FermentingRecipe.getModifier(item, recipeCache.rightReagent());
text = "x" + modifier;
x = getGuiLeft() + 113 - minecraft.font.width(text) / 2;
guiGraphics.drawString(minecraft.font, text, x, getGuiTop() + 32, 4210752, false);

}
}
Loading