Skip to content

Commit

Permalink
remove fog diffuser boosting
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Oct 27, 2023
1 parent 9310f9a commit 4e2e74e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 182 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package de.teamlapen.vampirism.blockentity;

import de.teamlapen.vampirism.core.ModTags;
import de.teamlapen.vampirism.core.ModTiles;
import de.teamlapen.vampirism.items.PureBloodItem;
import de.teamlapen.vampirism.world.VampirismWorld;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
Expand All @@ -18,10 +17,7 @@ public class FogDiffuserBlockEntity extends BlockEntity {

@NotNull
private State state = State.IDLE;
@NotNull
private Strength strength = Strength.NONE;

private float fuel = 0;
private boolean activated = false;
private float bootProgress = 0;

public FogDiffuserBlockEntity(BlockPos pPos, BlockState pBlockState) {
Expand All @@ -32,86 +28,26 @@ public FogDiffuserBlockEntity(BlockPos pPos, BlockState pBlockState) {
protected void saveAdditional(@NotNull CompoundTag pTag) {
super.saveAdditional(pTag);
pTag.putString("state", this.state.name());
pTag.putString("strength", this.strength.name());
pTag.putFloat("fuel", this.fuel);
pTag.putFloat("bootProgress", this.bootProgress);
pTag.putBoolean("activated", this.activated);
}

@Override
public void load(@NotNull CompoundTag pTag) {
super.load(pTag);
this.state = State.valueOf(pTag.getString("state"));
this.strength = Strength.valueOf(pTag.getString("strength"));
this.fuel = pTag.getFloat("fuel");
this.bootProgress = pTag.getFloat("bootProgress");
}

public boolean addFuel(@NotNull Player pPlayer, ItemStack stack) {
if (canAcceptFuelItem(stack) && isFuelingAllowedFor(stack)) {
Strength strength = getStrengthFor(stack);
if (strength.getLevel() > this.strength.getLevel()) {
this.strength = strength;
}
float fuel = getFuelFor(stack);
this.fuel = Math.min(1, this.fuel + fuel);
if (!pPlayer.getAbilities().instabuild) {
stack.shrink(1);
}
return true;
}
return false;
}

public boolean isFuelingAllowedFor(ItemStack stack) {
float fuel = getFuelFor(stack);
return this.fuel + fuel <= 1 + fuel * 0.6;
}

public boolean canAcceptFuelItem(ItemStack stack) {
Strength strength = getStrengthFor(stack);
return strength != Strength.NONE && strength.getLevel() >= this.strength.getLevel();
}

public Strength getStrengthFor(ItemStack stack) {
if (stack.getItem() instanceof PureBloodItem pureBlood) {
return switch (pureBlood.getLevel()) {
default -> Strength.LOW;
case 2, 3 -> Strength.MEDIUM;
case 4 -> Strength.HIGH;
};
}
return Strength.NONE;
}

public float getFuelFor(ItemStack stack) {
if (stack.getItem() instanceof PureBloodItem pureBlood) {
return switch (pureBlood.getLevel()) {
default -> 0.1f;
case 1 -> 0.2f;
case 2 -> 0.3f;
case 3 -> 0.4f;
case 4 -> 0.5f;
};
}
return 0;
this.activated = pTag.getBoolean("activated");
}

protected int getRange() {
return this.strength.getRadius();
}

public @NotNull Strength getStrength() {
return strength;
return (int) (2.5 * 16);
}

public @NotNull State getState() {
return state;
}

public float getFuel() {
return fuel;
}

public float getBootProgress() {
return bootProgress;
}
Expand All @@ -127,7 +63,7 @@ protected AABB getArea(int range) {
public static void tick(Level level, BlockPos pos, BlockState state, FogDiffuserBlockEntity blockEntity) {
switch (blockEntity.state) {
case IDLE -> {
if (blockEntity.fuel > 0) {
if (blockEntity.activated) {
blockEntity.state = State.BOOTING;
blockEntity.bootProgress = 0;
}
Expand All @@ -142,78 +78,28 @@ public static void tick(Level level, BlockPos pos, BlockState state, FogDiffuser
}
}
case ACTIVE -> {
if (level.getGameTime() % 256 == 0) {
blockEntity.fuel -= blockEntity.strength.getFuelConsumption() * 256;
if (blockEntity.fuel <= 0) {
blockEntity.state = State.SHUTTING_DOWN;
blockEntity.strength = Strength.NONE;
blockEntity.bootProgress = 1;
}
}
}
case SHUTTING_DOWN -> {
if (level.getGameTime() % 128 == 0) {
blockEntity.bootProgress -= 0.1;
if (blockEntity.bootProgress <= 0) {
blockEntity.state = State.IDLE;
}
blockEntity.updateFogArea(level);
}
}
}
}

public void updateFogArea(Level level) {
VampirismWorld.getOpt(level).ifPresent(w -> w.updateTemporaryArtificialFog(this.worldPosition, switch (this.state) {
case BOOTING, SHUTTING_DOWN -> getArea((int) (this.getRange() * this.bootProgress));
case BOOTING -> getArea((int) (this.getRange() * this.bootProgress));
case ACTIVE -> getArea();
default -> null;
}));
}

public void interact(ItemStack itemInHand) {
if (!this.activated && itemInHand.is(ModTags.Items.PURE_BLOOD)) {
this.activated = true;
itemInHand.shrink(1);
}
}

public enum State {
IDLE,
BOOTING,
ACTIVE,
SHUTTING_DOWN
}

public enum Strength {
NONE(0, 0, 0),
/**
* lasts ~ 20 minutes
*/
LOW(1, 5, 0.000040f),
/**
* lasts ~ 40 minutes
*/
MEDIUM(2, 10, 0.000020f),
/**
* lasts ~ 1.5 hours
*/
HIGH(3, 15, 0.000010f);

private final int level;
private final int radius;
private final float fuelConsumption;

Strength(int level, int radius, float fuelConsumption) {
this.level = level;
this.radius = radius;
this.fuelConsumption = fuelConsumption;
}

public int getLevel() {
return level;
}

public int getRadius() {
return radius;
}

public float getFuelConsumption() {
return fuelConsumption;
}

ACTIVE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ public FogDiffuserBlock(@NotNull Properties properties) {
public @NotNull InteractionResult use(@NotNull BlockState pState, @NotNull Level pLevel, @NotNull BlockPos pPos, @NotNull Player pPlayer, @NotNull InteractionHand pHand, @NotNull BlockHitResult pHit) {
ItemStack itemInHand = pPlayer.getItemInHand(pHand);
getBlockEntity(pLevel, pPos).ifPresent(blockEntity -> {
if (!blockEntity.addFuel(pPlayer, itemInHand)) {
VampirismMod.proxy.displayFogDiffuserScreen(blockEntity, getName());
}
blockEntity.interact(itemInHand);
VampirismMod.proxy.displayFogDiffuserScreen(blockEntity, getName());
});
return InteractionResult.sidedSuccess(pLevel.isClientSide);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import de.teamlapen.lib.lib.client.gui.ProgressBar;
import de.teamlapen.vampirism.REFERENCE;
import de.teamlapen.vampirism.blockentity.FogDiffuserBlockEntity;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.network.chat.Component;
Expand All @@ -20,7 +21,6 @@ public class FogDiffuserScreen extends Screen {
protected int guiTop;

private final FogDiffuserBlockEntity blockEntity;
private ProgressBar fuelProgress;
private ProgressBar startupProgress;

public FogDiffuserScreen(FogDiffuserBlockEntity blockEntity, Component pTitle) {
Expand All @@ -38,73 +38,39 @@ protected void init() {
this.guiLeft = (this.width - this.xSize) / 2;
this.guiTop = (this.height - this.ySize) / 2;

this.fuelProgress = this.addRenderableWidget(new ProgressBar(this.guiLeft + 25, this.guiTop + 22, 170, Component.translatable("fuel")));
this.fuelProgress.setColor(0xaaaaaa);
this.startupProgress = this.addRenderableWidget(new ProgressBar(this.guiLeft + 25, this.guiTop + 45, 170, Component.translatable("startup")));
this.startupProgress = this.addRenderableWidget(new ProgressBar(this.guiLeft + 25, this.guiTop + 30, 170, Component.translatable("startup")));
this.startupProgress.setColor(0xaaaaaa);
this.updateFuel();
}

@Override
public void tick() {
updateFuel();
updateStartup();
}

@Override
public void render(@NotNull PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTick) {
this.renderBackground(pPoseStack);
this.renderGuiBackground(pPoseStack, pMouseX, pMouseY, pPartialTick);
this.renderTitle(pPoseStack);
super.render(pPoseStack, pMouseX, pMouseY, pPartialTick);
public void render(@NotNull GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
this.renderBackground(pGuiGraphics);
this.renderGuiBackground(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
this.renderTitle(pGuiGraphics);
super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
}

private void renderTitle(@NotNull PoseStack pPoseStack) {
this.font.drawShadow(pPoseStack, title, this.guiLeft + 15, this.guiTop + 5, -1);
private void renderTitle(@NotNull GuiGraphics pGuiGraphics) {
pGuiGraphics.drawString(this.font, title, this.guiLeft + 15, this.guiTop + 5, -1);
}

private void renderGuiBackground(@NotNull PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTick) {
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
RenderSystem.setShaderTexture(0, BACKGROUND);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
blit(pPoseStack, this.guiLeft, this.guiTop, this.getBlitOffset(), 0, 0, this.xSize, this.ySize, 256, 256);
}

protected void updateFuel() {
this.fuelProgress.setProgress(this.blockEntity.getFuel());
this.fuelProgress.setColor(switch (this.blockEntity.getStrength()) {
default -> 0x964c4c;
case LOW -> 0x9f3b3b;
case MEDIUM -> 0xae2828;
case HIGH -> 0xaa0101;
});
if (this.blockEntity.getState() == FogDiffuserBlockEntity.State.IDLE) {
this.fuelProgress.setColor(0x808080);
}
this.fuelProgress.setMessage(this.getFuelText());
private void renderGuiBackground(@NotNull GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
pGuiGraphics.setColor(1.0F, 1.0F, 1.0F, 1.0F);
pGuiGraphics.blit(BACKGROUND, this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize, 256, 256);
}

protected void updateStartup() {
this.startupProgress.visible = switch (this.blockEntity.getState()) {
case IDLE, BOOTING, SHUTTING_DOWN -> true;
default -> false;
};
this.startupProgress.setProgress(this.blockEntity.getBootProgress());
this.startupProgress.setMessage(this.getStartupText());
}

protected Component getFuelText() {
FogDiffuserBlockEntity.Strength strength = this.blockEntity.getStrength();
if (strength == FogDiffuserBlockEntity.Strength.NONE) {
return Component.translatable("text.vampirism.empty");
} else {
return Component.translatable("item.vampirism.pure_blood").append(" ").append(Component.translatable("text.vampirism.purity_" + this.blockEntity.getStrength().name().toLowerCase()));
}
}

protected Component getStartupText() {
return switch (this.blockEntity.getState()) {
case SHUTTING_DOWN -> Component.translatable("text.vampirism.fog_diffuser.shutting_down");
case BOOTING -> Component.translatable("text.vampirism.fog_diffuser.booting");
case IDLE -> Component.translatable("text.vampirism.fog_diffuser.idle");
case ACTIVE -> Component.translatable("text.vampirism.fog_diffuser.active");
Expand Down
4 changes: 0 additions & 4 deletions src/main/resources/assets/vampirism/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@
"text.vampirism.key_shortcuts": "Key Shortcuts",
"text.vampirism.open_settings": "Open Keybinding",
"text.vampirism.empty": "Empty",
"text.vampirism.purity_low": "Purity: low",
"text.vampirism.purity_medium": "Purity: medium",
"text.vampirism.purity_high": "Purity: high",
"text.vampirism.fog_diffuser.shutting_down": "Shutting down",
"text.vampirism.fog_diffuser.booting": "Starting up",
"text.vampirism.fog_diffuser.idle": "Inactive",
"text.vampirism.fog_diffuser.active": "Running",
Expand Down

0 comments on commit 4e2e74e

Please sign in to comment.