Skip to content

Commit

Permalink
visual effects work
Browse files Browse the repository at this point in the history
  • Loading branch information
eerussianguy committed Nov 3, 2024
1 parent 7cb5cb1 commit 5293a2f
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.eerussianguy.beneath.client.screen;

import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;

public class BeneathScreen extends Screen
{
public BeneathScreen(Component title)
{
super(title);
}

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers)
{
if (super.keyPressed(keyCode, scanCode, modifiers))
return true;
assert minecraft != null;
if (minecraft.options.keyInventory.isActiveAndMatches(InputConstants.getKey(keyCode, scanCode)))
{
minecraft.setScreen(null);
return true;
}
return false;
}

protected void drawCenteredLine(GuiGraphics graphics, MutableComponent text, int x, int y)
{
final int dx = (256 - this.font.width(text)) / 2;
graphics.drawString(this.font, text, x + dx, y, 4210752, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@

import com.eerussianguy.beneath.Beneath;
import com.eerussianguy.beneath.common.items.LostPageItem;
import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;

public class LostPageScreen extends Screen
public class LostPageScreen extends BeneathScreen
{
private static final ResourceLocation TEXTURE = Beneath.identifier("textures/gui/lost_page.png");
private static final Component NAME = Component.translatable("beneath.screen.lost_page");
Expand Down Expand Up @@ -51,34 +48,15 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTi
drawCenteredLine(graphics, Component.literal(item.getCostAmount(stack) + "x ").append(item.getSpecificIngredientTranslation(stack)), x, y + 26);
graphics.renderItem(cost, x + 120, y + 34);


drawCenteredLine(graphics, Component.translatable("beneath.screen.lost_page.reward"), x, y + 64);
drawCenteredLine(graphics, Component.literal(item.getRewardAmount(stack) + "x ").append(reward.getHoverName()), x, y + 74);
graphics.renderItem(reward, x + 120, y + 82);

drawCenteredLine(graphics, Component.translatable("beneath.screen.lost_page.punishment"), x, y + 112);
drawCenteredLine(graphics, Beneath.translateEnum(item.getPunishment(stack)), x, y + 122);
final MutableComponent pun = Beneath.translateEnum(item.getPunishment(stack));
graphics.drawWordWrap(font, pun, x + 70, y + 122, 110, 0);
}
}

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers)
{
if (super.keyPressed(keyCode, scanCode, modifiers))
return true;
assert minecraft != null;
if (minecraft.options.keyInventory.isActiveAndMatches(InputConstants.getKey(keyCode, scanCode)))
{
minecraft.setScreen(null);
return true;
}
return false;
}

protected void drawCenteredLine(GuiGraphics graphics, MutableComponent text, int x, int y)
{
final int dx = (256 - this.font.width(text)) / 2;
graphics.drawString(this.font, text, x + dx, y, 4210752, false);
}

}
Original file line number Diff line number Diff line change
@@ -1,23 +1,207 @@
package com.eerussianguy.beneath.common.blockentities;

import java.util.ArrayList;
import java.util.List;
import com.eerussianguy.beneath.Beneath;
import com.eerussianguy.beneath.common.items.LostPageItem;
import com.eerussianguy.beneath.misc.LostPage;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.Tags;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.ItemStackHandler;

import net.dries007.tfc.common.blockentities.InventoryBlockEntity;
import net.dries007.tfc.util.Helpers;

public class AncientAltarBlockEntity extends InventoryBlockEntity<ItemStackHandler>
{
public static void tickBothSides(Level level, BlockPos pos, BlockState state, AncientAltarBlockEntity altar)
{
if (altar.tick < 0)
return;

if (level.isClientSide)
{
final double x = pos.getX() + 0.5;
final double y = pos.getY() + 1;
final double z = pos.getZ() + 0.5;

final float partial = altar.tick / 20f * Mth.TWO_PI;
final float r = 0.5f + (0.01f * altar.tick);

final ParticleOptions particle = switch (altar.success)
{
case 0 -> ParticleTypes.WHITE_ASH;
case 1 -> ParticleTypes.CHERRY_LEAVES;
default -> ParticleTypes.MYCELIUM;
};
level.addParticle(particle, x + Mth.sin(partial) * r, y + ((altar.success == 2 ? 1 : 2) * altar.tick / 20f), z + Mth.cos(partial) * r, Helpers.triangle(level.random, 0.2f), -0.2f, Helpers.triangle(level.random, 0.2f));
if (altar.tick == 0)
{
for (int i = 0; i < 10; i++)
{
level.addParticle(ParticleTypes.SMOKE, x, y + 0.125, z, level.random.nextGaussian() * 0.05, 0.005, level.random.nextGaussian() * 0.05);
}
}
}
if (altar.tick == 0)
{
Helpers.playSound(level, pos, SoundEvents.FIREWORK_ROCKET_TWINKLE);
}

altar.tick--;
}

private int tick = -1;
private int success = 0;

public AncientAltarBlockEntity(BlockPos pos, BlockState state)
{
super(BeneathBlockEntities.ANCIENT_ALTAR.get(), pos, state, defaultInventory(1), Beneath.blockEntityName("ancient_altar"));
}

@Override
public void loadAdditional(CompoundTag nbt)
{
super.loadAdditional(nbt);
tick = nbt.getInt("tick");
success = nbt.getInt("success");
}

@Override
public void saveAdditional(CompoundTag nbt)
{
super.saveAdditional(nbt);
nbt.putInt("tick", tick);
nbt.putInt("success", success);
}

public IItemHandler getInventory()
{
return inventory;
}

public void playSuccess()
{
assert level != null;
tick = 40;
success = 1;
Helpers.playSound(level, worldPosition, SoundEvents.ENCHANTMENT_TABLE_USE);
markForSync();
}

public void playFail()
{
assert level != null;
tick = 40;
success = 0;
Helpers.playSound(level, worldPosition, SoundEvents.GLASS_BREAK);
markForSync();
}

public void playSecondarySuccess()
{
assert level != null;
tick = 40;
success = 2;
markForSync();
}

@Override
public void setAndUpdateSlots(int slot)
{
super.setAndUpdateSlots(slot);
}

public InteractionResult use(Player player, InteractionHand hand)
{
assert level != null;
final BlockPos pos = worldPosition;
final IItemHandler inv = getInventory();
final ItemStack held = player.getItemInHand(hand);
if (Helpers.isItem(held, Tags.Items.GEMS))
{
final ItemStack stack = inv.getStackInSlot(0);
if (LostPage.choose(stack, level.getRandom()))
{
held.shrink(1);
playSuccess();
return InteractionResult.sidedSuccess(level.isClientSide);
}
else if (stack.getItem() instanceof LostPageItem page && page.hasInitialized(stack))
{
int found = 0;
final Ingredient cost = page.getCost(stack);
final int costAmount = page.getCostAmount(stack);
final List<AncientAltarBlockEntity> altars = new ArrayList<>();
for (BlockPos checkPos : BlockPos.betweenClosed(pos.offset(-5, 0, -5), pos.offset(5, 0, 5)))
{
if (level.getBlockEntity(checkPos) instanceof AncientAltarBlockEntity otherAltar && this != otherAltar)
{
final ItemStack foundStack = otherAltar.getInventory().getStackInSlot(0);
if (cost.test(foundStack))
{
found += foundStack.getCount();
altars.add(otherAltar);
if (found >= costAmount)
break;
}
}
}
if (found >= page.getCostAmount(stack))
{
for (AncientAltarBlockEntity otherAltar : altars)
{
otherAltar.playSecondarySuccess();
otherAltar.getInventory().extractItem(0, 64, false);
level.sendBlockUpdated(otherAltar.getBlockPos(), otherAltar.getBlockState(), otherAltar.getBlockState(), Block.UPDATE_CLIENTS);
}
int rewardAmount = page.getRewardAmount(stack);
if (!level.dimensionType().ultraWarm())
rewardAmount /= 2;
final ItemStack reward = page.getReward(stack);
while (rewardAmount > 0)
{
int count = Math.min(reward.getMaxStackSize(), rewardAmount);
Helpers.spawnItem(level, pos, reward.copyWithCount(count));
rewardAmount -= count;
}
held.shrink(1);
playSuccess();
page.getPunishment(stack).administer(player, level, pos);
}
else
{
player.hurt(level.damageSources().magic(), 1f);
playFail();
player.displayClientMessage(Component.translatable("beneath.sacrifice.error"), true);
}
return InteractionResult.sidedSuccess(level.isClientSide);
}
}

// regular interaction
if (!inv.getStackInSlot(0).isEmpty())
{
ItemHandlerHelper.giveItemToPlayer(player, inv.extractItem(0, 64, false));
}
ItemHandlerHelper.giveItemToPlayer(player, inv.insertItem(0, held.split(64), false));
return InteractionResult.sidedSuccess(level.isClientSide);
}

}
Loading

0 comments on commit 5293a2f

Please sign in to comment.