Skip to content

Commit

Permalink
remake block from mb to droplets and convert it when needed
Browse files Browse the repository at this point in the history
MEGATREX4 committed Jul 31, 2024
1 parent 4f7be74 commit 50f1e3f
Showing 5 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ protected FluidVariant getBlankVariant() {

@Override
public long getCapacity(FluidVariant variant) {
return com.megatrex4.ukrainian_dlight.config.ModConfig.getBrewingKegCapacity();
return FluidStack.convertMbToDroplets(ModConfig.getBrewingKegCapacity());
}


@@ -504,9 +504,10 @@ private void handleWaterBucket() {

public boolean addWater(long WaterAmountAdd) {
try (Transaction transaction = Transaction.openOuter()) {
long insertedAmount = this.fluidStorage.insert(FluidVariant.of(Fluids.WATER), WaterAmountAdd, transaction);
long dropletsToAdd = FluidStack.convertMbToDroplets(WaterAmountAdd);
long insertedAmount = this.fluidStorage.insert(FluidVariant.of(Fluids.WATER), dropletsToAdd, transaction);

if (insertedAmount == WaterAmountAdd) {
if (insertedAmount == dropletsToAdd) {
transaction.commit();
return true; // Successfully added water
}
@@ -531,17 +532,18 @@ private boolean hasEnoughFluid() {
Optional<BrewingRecipe> match = getCurrentRecipe();
if (match.isPresent()) {
BrewingRecipe recipe = match.get();
return fluidStorage.amount >= recipe.getWaterAmount();
long requiredFluid = FluidStack.convertMbToDroplets(recipe.getWaterAmount());
return fluidStorage.amount >= requiredFluid;
}
return false;
}

public long getWaterAmount() {
return fluidStorage.amount;
return FluidStack.convertDropletsToMb(fluidStorage.amount);
}

public long getWaterCapacity() {
return fluidStorage.getCapacity();
return FluidStack.convertDropletsToMb(fluidStorage.getCapacity());
}


Original file line number Diff line number Diff line change
@@ -35,7 +35,6 @@ public class BrewingKegScreen extends HandledScreen<BrewingKegScreenHandler> {

public static final int[] INGREDIENT_SLOTS = {0, 1, 2, 3, 4, 5};
public static final int CONTAINER_SLOT = 6;
public static final int REQUIRE_CONTAINER = 7;
public static final int WATER_SLOT = 8;
public static final int DRINKS_DISPLAY_SLOT = 9;
public static final int OUTPUT_SLOT = 10;
@@ -117,8 +116,8 @@ protected void drawMouseoverTooltip(DrawContext context, int mouseX, int mouseY)
}
drink.getItem().appendTooltip(drink, handler.blockEntity.getWorld(), tooltip, TooltipContext.Default.BASIC);

// Get the item in REQUIRE_CONTAINER (slot ID 7)
ItemStack containerItem = handler.blockEntity.getStack(REQUIRE_CONTAINER);
// Get the item from nbt requireContainer
ItemStack containerItem = handler.blockEntity.getRequiredContainer();
String containerName = "";
if (!containerItem.isEmpty()) {
Item container = containerItem.getItem();
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.fluid.Fluid;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
@@ -134,7 +135,7 @@ public int getScaledProgress() {
}

public int getScaledWaterLevel() {
long waterLevel = this.fluidStack.amount;
long waterLevel = FluidStack.convertDropletsToMb(this.fluidStack.amount);
long maxWaterLevel = this.blockEntity.getMaxWaterLevel();
int waterBarHeight = 40;

Original file line number Diff line number Diff line change
@@ -77,12 +77,12 @@ public void drawFluid(DrawContext context, FluidStack fluid, int x, int y, int w
// Set texture to the block atlas texture
RenderSystem.setShaderTexture(0, PlayerScreenHandler.BLOCK_ATLAS_TEXTURE);

// Calculate the height of the fluid based on the current amount
// Calculate the height of the fluid based on the current amount in millibuckets
y += height;
final Sprite sprite = FluidVariantRendering.getSprite(fluid.getFluidVariant());
int color = FluidVariantRendering.getColor(fluid.getFluidVariant());

final int drawHeight = (int) (fluid.getAmount() / (maxCapacity * 1F) * height);
final int drawHeight = (int) (FluidStack.convertDropletsToMb(fluid.getAmount()) / (maxCapacity * 1F) * height);
final int iconHeight = sprite.getContents().getHeight();
int offsetHeight = drawHeight;

@@ -114,6 +114,7 @@ public void drawFluid(DrawContext context, FluidStack fluid, int x, int y, int w




@Override
public List<Text> getTooltip(FluidStack fluidStack, TooltipContext tooltipFlag) {
List<Text> tooltip = new ArrayList<>();
@@ -122,7 +123,7 @@ public List<Text> getTooltip(FluidStack fluidStack, TooltipContext tooltipFlag)
return tooltip;
}

long amount = fluidStack.getAmount();
long amount = FluidStack.convertDropletsToMb(fluidStack.getAmount()); // Convert amount to Mb
if (amount > 0) {
MutableText displayName = Text.translatable("block." + Registries.FLUID.getId(fluidStack.getFluidVariant().getFluid()).toTranslationKey());
tooltip.add(displayName);
@@ -143,6 +144,7 @@ public List<Text> getTooltip(FluidStack fluidStack, TooltipContext tooltipFlag)




// get tooltip for items like [ %s ] - %d / %d mb
public List<Text> getItemTooltip(FluidStack fluidStack, TooltipContext tooltipFlag) {
List<Text> tooltip = new ArrayList<>();
@@ -151,15 +153,15 @@ public List<Text> getItemTooltip(FluidStack fluidStack, TooltipContext tooltipFl
return tooltip;
}

long amount = fluidStack.getAmount();
long amount = FluidStack.convertDropletsToMb(fluidStack.getAmount()); // Convert amount to Mb
if (amount > 0) {
MutableText displayName = Text.translatable("block." + Registries.FLUID.getId(fluidStack.getFluidVariant().getFluid()).toTranslationKey());

if (tooltipMode == TooltipMode.SHOW_AMOUNT_AND_CAPACITY) {
MutableText amountString = UkrainianDelight.i18n("tooltip.item_amout_with_capacity", displayName, nf.format(amount), nf.format(ItemCapacityMb));
tooltip.add(amountString.fillStyle(Style.EMPTY.withColor(Formatting.DARK_GRAY)));
} else if (tooltipMode == TooltipMode.SHOW_AMOUNT) {
MutableText amountString = UkrainianDelight.i18n("tooltip.item_tank_amount",displayName, nf.format(amount));
MutableText amountString = UkrainianDelight.i18n("tooltip.item_tank_amount", displayName, nf.format(amount));
tooltip.add(amountString.fillStyle(Style.EMPTY.withColor(Formatting.DARK_GRAY)));
}
} else {
Original file line number Diff line number Diff line change
@@ -30,10 +30,10 @@ public void setAmount(long amount) {
}

public static long convertDropletsToMb(long droplets) {
return droplets / DROPLETS_PER_MILLIBUCKET;
return droplets / 81;
}

public static long convertMbToDroplets(long millibuckets) {
return millibuckets * DROPLETS_PER_MILLIBUCKET;
return millibuckets * 81;
}
}

0 comments on commit 50f1e3f

Please sign in to comment.