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

Turn rituals into data-driven recipes #87

Closed
wants to merge 2 commits into from
Closed
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
152 changes: 89 additions & 63 deletions src/main/java/elucent/rootsclassic/block/altar/AltarBlockEntity.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package elucent.rootsclassic.block.altar;

import com.google.common.collect.Lists;
import elucent.rootsclassic.block.brazier.BrazierBlockEntity;
import elucent.rootsclassic.blockentity.BEBase;
import elucent.rootsclassic.client.particles.MagicAltarParticleData;
import elucent.rootsclassic.client.particles.MagicLineParticleData;
import elucent.rootsclassic.recipe.RitualRecipe;
import elucent.rootsclassic.registry.RootsRegistry;
import elucent.rootsclassic.ritual.RitualBase;
import elucent.rootsclassic.ritual.RitualBaseRegistry;
import elucent.rootsclassic.ritual.RitualEffect;
import elucent.rootsclassic.ritual.RitualPillars;
import elucent.rootsclassic.ritual.RitualRegistry;
import elucent.rootsclassic.util.InventoryUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.item.ItemEntity;
Expand All @@ -23,22 +25,31 @@
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.ItemStackHandler;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class AltarBlockEntity extends BEBase {
private static final int RECIPE_PROGRESS_TIME = 200;
private ArrayList<ItemStack> incenses = new ArrayList<>();
private List<ItemStack> incenses = Collections.emptyList();
private int ticker = 0;
private int progress = 0;
private ResourceLocation ritualName = null;
private RitualBase ritualCurrent = null;
// private ItemStack resultItem = ItemStack.EMPTY; TODO: Unused

@Nullable
private RitualRecipe<?> ritualCurrent = null;
private int clientRitualLevel;
private Color clientRitualColor;
private Color clientRitualSecondaryColor;

public final ItemStackHandler inventory = new ItemStackHandler(3) {

@Override
Expand All @@ -64,13 +75,24 @@ public void load(CompoundTag tag) {
if (tag.contains("incenses")) {
ListTag list = tag.getList("incenses", CompoundTag.TAG_COMPOUND);
for (int i = 0; i < list.size(); i++) {
getIncenses().add(ItemStack.of(list.getCompound(i)));
incenses.add(ItemStack.of(list.getCompound(i)));
}
}

/*
if (tag.contains("ritualName")) {
setRitualNameFromString(tag.getString("ritualName"));
setRitualCurrent(RitualBaseRegistry.RITUALS.get().getValue(getRitualName()));
setRitualCurrent(RitualRegistry.byName(getRitualName(), level.getRecipeManager()));
}
*/

if (level != null && level.isClientSide() && tag.contains("ritual", 10)) {
var ritualTag = tag.getCompound("ritual");
clientRitualLevel = ritualTag.getInt("level");
clientRitualColor = new Color(ritualTag.getInt("color"));
clientRitualSecondaryColor = new Color(ritualTag.getInt("secondaryColor"));
}

if (tag.contains("progress")) {
setProgress(tag.getInt("progress"));
}
Expand All @@ -80,19 +102,31 @@ public void load(CompoundTag tag) {
public void saveAdditional(CompoundTag tag) {
super.saveAdditional(tag);
tag.put("InventoryHandler", inventory.serializeNBT());
if (getIncenses().size() > 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I get that a lot of the changes you have made are likely nice ones but just a tip for the future, try to keep your PR's as close to only the changes needed rather than nice to have changes, especially if they are of this scale. It makes the pr a lot harder to review and more likely to have clashes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry, I realize now that I have probably made a lot of these unnecessary changes automatically, without thinking about it

if (incenses.size() > 0) {
ListTag list = new ListTag();
for (int i = 0; i < getIncenses().size(); i++) {
for (int i = 0; i < incenses.size(); i++) {
// ;
// if (getIncenses().get(i) != null) {
list.add(getIncenses().get(i).save(new CompoundTag()));
// if (incenses.get(i) != null) {
list.add(incenses.get(i).save(new CompoundTag()));
// }
}
tag.put("incenses", list);
}

/*
if (getRitualName() != null) {
tag.putString("ritualName", getRitualName().toString());
}
*/

if (level != null && !level.isClientSide() && ritualCurrent != null) {
var ritualTag = new CompoundTag();
ritualTag.putInt("level", ritualCurrent.level);
ritualTag.putInt("color", ritualCurrent.color.getRGB());
ritualTag.putInt("secondaryColor", ritualCurrent.secondaryColor.getRGB());
tag.put("ritual", ritualTag);
}

tag.putInt("progress", getProgress());
}

Expand Down Expand Up @@ -128,24 +162,28 @@ public InteractionResult activate(Level levelAccessor, BlockPos pos, BlockState
}
} else if (player.isShiftKeyDown() && heldItem.isEmpty() && this.getProgress() == 0) {
// Try to start a new ritual
setRitualName(null);
setRitualCurrent(null);
RitualBase ritual = RitualRegistry.findMatchingByIngredients(this);
if (ritual == null) {

setRitual(null);

var optionalRitual = RitualRegistry.findMatchingByIngredients(this);
if (optionalRitual.isEmpty()) {
player.displayClientMessage(Component.translatable("rootsclassic.error.noritual.ingredients"), true);
return InteractionResult.FAIL;
}
if (!ritual.verifyPositionBlocks(levelAccessor, pos)) {

var ritual = optionalRitual.get();

if (!RitualPillars.verifyPositionBlocks(ritual, levelAccessor, pos)) {
player.displayClientMessage(Component.translatable("rootsclassic.error.noritual.stones"), true);
return InteractionResult.FAIL;
}
//does it match everything else?
if (ritual.incenseMatches(level, pos)) {
setRitualCurrent(ritual);
setRitualName(RitualBaseRegistry.RITUALS.get().getKey(ritual));
setRitual(ritual);

setIncenses(RitualRegistry.getIncenses(levelAccessor, pos));
setProgress(RECIPE_PROGRESS_TIME);
for (BrazierBlockEntity brazier : ritual.getRecipeBraziers(levelAccessor, pos)) {
for (BrazierBlockEntity brazier : RitualPillars.getRecipeBraziers(levelAccessor, pos)) {
brazier.setBurning(true);
brazier.setHeldItem(ItemStack.EMPTY);
}
Expand Down Expand Up @@ -189,7 +227,7 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, Altar
if (tile.getTicker() > 360) {
tile.setTicker(0);
}
if (tile.getProgress() > 0 && tile.getRitualCurrent() != null) {
if (tile.getProgress() > 0 && tile.ritualCurrent != null) {
tile.setProgress(tile.getProgress() - 1);
// if (tile.getProgress() % 40 == 0) {
// setIncenses(RitualManager.getIncenses(getWorld(), getPos()));
Expand All @@ -204,10 +242,10 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, Altar
// setRitualName(null);
// }
// }
if (tile.getProgress() == 0 && tile.getRitualCurrent() != null) {
tile.getRitualCurrent().doEffect(level, pos, InventoryUtil.createIInventory(tile.inventory), tile.getIncenses());
tile.setRitualName(null);
tile.setRitualCurrent(null);
if (tile.getProgress() == 0 && tile.ritualCurrent != null) {
tile.ritualCurrent.doEffect(level, pos, InventoryUtil.createIInventory(tile.inventory), tile.incenses);

tile.setRitual(null);
tile.emptyAltar();
tile.setChanged();
level.sendBlockUpdated(pos, state, state, 3);
Expand All @@ -216,72 +254,75 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, Altar
}

public static void clientTick(Level level, BlockPos pos, BlockState state, AltarBlockEntity tile) {
if (tile.getProgress() > 0 && tile.getRitualCurrent() != null) {
if (tile.getProgress() > 0 && tile.ritualCurrent != null) {
tile.setProgress(tile.getProgress() - 1);
if (tile.getRitualCurrent().getPositionsRelative().size() > 0) {
BlockPos particlePos = tile.getRitualCurrent().getPositionsRelative().get(level.random.nextInt(tile.getRitualCurrent().getPositionsRelative().size())).above()
.offset(pos.getX(), pos.getY(), pos.getZ());
var pillars = RitualPillars.getRitualPillars(tile.clientRitualLevel);
var pillarPositions = pillars.keySet().stream().toList();
var color = tile.clientRitualColor;
var secondaryColor = tile.clientRitualSecondaryColor;

if(color == null || secondaryColor == null) return;

if (!pillars.isEmpty()) {
BlockPos particlePos = pillarPositions.get(level.random.nextInt(pillars.size())).above().offset(pos);
if (level.random.nextInt(6) == 0) {
level.addParticle(MagicLineParticleData.createData(tile.getRitualCurrent().getColor().x, tile.getRitualCurrent().getColor().y, tile.getRitualCurrent().getColor().z),
level.addParticle(MagicLineParticleData.createData(color.getRed(), color.getGreen(), color.getBlue()),
particlePos.getX() + 0.5, particlePos.getY() + 0.125, particlePos.getZ() + 0.5,
particlePos.getX() + 0.5, particlePos.getY() + 0.875, particlePos.getZ() + 0.5);
} else {
level.addParticle(MagicLineParticleData.createData(tile.getRitualCurrent().getSecondaryColor().x, tile.getRitualCurrent().getSecondaryColor().y, tile.getRitualCurrent().getSecondaryColor().z),
level.addParticle(MagicLineParticleData.createData(secondaryColor.getRed(), secondaryColor.getGreen(), secondaryColor.getBlue()),
particlePos.getX() + 0.5, particlePos.getY() + 0.125, particlePos.getZ() + 0.5,
particlePos.getX() + 0.5, particlePos.getY() + 0.875, particlePos.getZ() + 0.5);
}
}

if (level.random.nextInt(4) == 0) {
level.addParticle(MagicAltarParticleData.createData(tile.getRitualCurrent().getColor().x, tile.getRitualCurrent().getColor().y, tile.getRitualCurrent().getColor().z),
level.addParticle(MagicAltarParticleData.createData(color.getRed(), color.getGreen(), color.getBlue()),
pos.getX() + 0.5, pos.getY() + 0.875, pos.getZ() + 0.5,
0.125 * Math.sin(Math.toRadians(360.0 * (tile.getProgress() % 100) / 100.0)), 0, 0.125 * Math.cos(Math.toRadians(360.0 * (tile.getProgress() % 100) / 100.0)));
} else {
level.addParticle(MagicAltarParticleData.createData(tile.getRitualCurrent().getSecondaryColor().x, tile.getRitualCurrent().getSecondaryColor().y, tile.getRitualCurrent().getSecondaryColor().z),
level.addParticle(MagicAltarParticleData.createData(secondaryColor.getRed(), secondaryColor.getGreen(), secondaryColor.getBlue()),
pos.getX() + 0.5, pos.getY() + 0.875, pos.getZ() + 0.5,
0.125 * Math.sin(Math.toRadians(360.0 * (tile.getProgress() % 100) / 100.0)), 0, 0.125 * Math.cos(Math.toRadians(360.0 * (tile.getProgress() % 100) / 100.0)));
}
if (level.random.nextInt(4) == 0) {
level.addParticle(MagicAltarParticleData.createData(tile.getRitualCurrent().getColor().x, tile.getRitualCurrent().getColor().y, tile.getRitualCurrent().getColor().z),
level.addParticle(MagicAltarParticleData.createData(color.getRed(), color.getGreen(), color.getBlue()),
pos.getX() + 0.5, pos.getY() + 0.875, pos.getZ() + 0.5,
.125 * Math.sin(Math.toRadians(90.0 + 360.0 * (tile.getProgress() % 100) / 100.0)), 0, 0.125 * Math.cos(Math.toRadians(90.0 + 360.0 * (tile.getProgress() % 100) / 100.0)));
} else {
level.addParticle(MagicAltarParticleData.createData(tile.getRitualCurrent().getSecondaryColor().x, tile.getRitualCurrent().getSecondaryColor().y, tile.getRitualCurrent().getSecondaryColor().z),
level.addParticle(MagicAltarParticleData.createData(secondaryColor.getRed(), secondaryColor.getGreen(), secondaryColor.getBlue()),
pos.getX() + 0.5, pos.getY() + 0.875, pos.getZ() + 0.5,
.125 * Math.sin(Math.toRadians(90.0 + 360.0 * (tile.getProgress() % 100) / 100.0)), 0, 0.125 * Math.cos(Math.toRadians(90.0 + 360.0 * (tile.getProgress() % 100) / 100.0)));
}
if (level.random.nextInt(4) == 0) {
level.addParticle(MagicAltarParticleData.createData(tile.getRitualCurrent().getColor().x, tile.getRitualCurrent().getColor().y, tile.getRitualCurrent().getColor().z),
level.addParticle(MagicAltarParticleData.createData(color.getRed(), color.getGreen(), color.getBlue()),
pos.getX() + 0.5, pos.getY() + 0.875, pos.getZ() + 0.5,
.125 * Math.sin(Math.toRadians(180.0 + 360.0 * (tile.getProgress() % 100) / 100.0)), 0, 0.125 * Math.cos(Math.toRadians(180.0 + 360.0 * (tile.getProgress() % 100) / 100.0)));
} else {
level.addParticle(MagicAltarParticleData.createData(tile.getRitualCurrent().getSecondaryColor().x, tile.getRitualCurrent().getSecondaryColor().y, tile.getRitualCurrent().getSecondaryColor().z),
level.addParticle(MagicAltarParticleData.createData(secondaryColor.getRed(), secondaryColor.getGreen(), secondaryColor.getBlue()),
pos.getX() + 0.5, pos.getY() + 0.875, pos.getZ() + 0.5,
.125 * Math.sin(Math.toRadians(180.0 + 360.0 * (tile.getProgress() % 100) / 100.0)), 0, 0.125 * Math.cos(Math.toRadians(180.0 + 360.0 * (tile.getProgress() % 100) / 100.0)));
}
if (level.random.nextInt(4) == 0) {
level.addParticle(MagicAltarParticleData.createData(tile.getRitualCurrent().getColor().x, tile.getRitualCurrent().getColor().y, tile.getRitualCurrent().getColor().z),
level.addParticle(MagicAltarParticleData.createData(color.getRed(), color.getGreen(), color.getBlue()),
pos.getX() + 0.5, pos.getY() + 0.875, pos.getZ() + 0.5,
.125 * Math.sin(Math.toRadians(270.0 + 360.0 * (tile.getProgress() % 100) / 100.0)), 0, 0.125 * Math.cos(Math.toRadians(270.0 + 360.0 * (tile.getProgress() % 100) / 100.0)));
} else {
level.addParticle(MagicAltarParticleData.createData(tile.getRitualCurrent().getSecondaryColor().x, tile.getRitualCurrent().getSecondaryColor().y, tile.getRitualCurrent().getSecondaryColor().z),
level.addParticle(MagicAltarParticleData.createData(secondaryColor.getRed(), secondaryColor.getGreen(), secondaryColor.getBlue()),
pos.getX() + 0.5, pos.getY() + 0.875, pos.getZ() + 0.5,
.125 * Math.sin(Math.toRadians(270.0 + 360.0 * (tile.getProgress() % 100) / 100.0)), 0, 0.125 * Math.cos(Math.toRadians(270.0 + 360.0 * (tile.getProgress() % 100) / 100.0)));
}
}
}

// private void emptyNearbyBraziers() {
// for (TileEntityBrazier brazier : getRitualCurrent().getRecipeBraziers(world, pos)) {
// for (TileEntityBrazier brazier : ritualCurrent.getRecipeBraziers(world, pos)) {
// brazier.setHeldItem(ItemStack.EMPTY);
// brazier.setBurning(false);
// }
// }

public ArrayList<ItemStack> getIncenses() {
return incenses;
}

public void setIncenses(ArrayList<ItemStack> incenses) {
public void setIncenses(List<ItemStack> incenses) {
this.incenses = incenses;
}

Expand All @@ -301,24 +342,9 @@ public void setProgress(int progress) {
this.progress = progress;
}

public ResourceLocation getRitualName() {
return ritualName;
}

public void setRitualNameFromString(String ritualName) {
this.ritualName = ResourceLocation.tryParse(ritualName);
}

public void setRitualName(ResourceLocation ritualName) {
this.ritualName = ritualName;
}

public RitualBase getRitualCurrent() {
return ritualCurrent;
}

public void setRitualCurrent(RitualBase ritualCurrent) {
public void setRitual(RitualRecipe<?> ritualCurrent) {
this.ritualCurrent = ritualCurrent;
setChanged();
}

public void emptyAltar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import elucent.rootsclassic.research.ResearchBase;
import elucent.rootsclassic.research.ResearchGroup;
import elucent.rootsclassic.research.ResearchPage;
import elucent.rootsclassic.ritual.RitualPillars;
import elucent.rootsclassic.util.RootsUtil;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.resources.language.I18n;
Expand Down Expand Up @@ -93,7 +95,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
&& mouseY >= (height / 2.0f) - 138 && mouseY < (height / 2.0f) - 40) {
if (researchInfo.get(currentPage).recipe == EnumPageType.TYPE_MORTAR) {
//Roots.lang("rootsclassic.recipe.chat") +
player.sendSystemMessage(Component.translatable(researchInfo.get(currentPage).mortarRecipe.toString()));
player.sendSystemMessage(Component.literal(researchInfo.get(currentPage).mortarRecipe.toString()));
} else if (researchInfo.get(currentPage).recipe == EnumPageType.TYPE_ALTAR) {
player.sendSystemMessage(Component.translatable(researchInfo.get(currentPage).altarRecipe.toString()));
}
Expand Down Expand Up @@ -169,31 +171,37 @@ public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTic
case TYPE_ALTAR -> {
RenderSystem.setShaderTexture(0, Const.tabletAltar);
this.blit(poseStack, basePosX, basePosY, 0, 0, 192, 256);
for (int i = 0; i < page.altarRecipe.getBlocks().size(); i++) {

RitualPillars.getRitualPillars(page.altarRecipe.level).forEach((pos, block) -> {

RenderSystem.setShaderTexture(0, Const.tabletAltar);
int u = 192;
int v = 240;
int xShift = 0;
int yShift = 0;
this.blit(poseStack, basePosX + 93, basePosY + 153, 192, 32, 16, 16);
if (page.altarRecipe.getBlocks().get(i).equals(RootsRegistry.MUNDANE_STANDING_STONE.get())) {
if (block.equals(RootsRegistry.MUNDANE_STANDING_STONE.get())) {
v = 48;
xShift = 8 * (int) page.altarRecipe.getPositionsRelative().get(i).getX();
yShift = 8 * (int) page.altarRecipe.getPositionsRelative().get(i).getZ();
xShift = 8 * pos.getX();
yShift = 8 * pos.getZ();
}
if (page.altarRecipe.getBlocks().get(i).equals(RootsRegistry.ATTUNED_STANDING_STONE.get())) {
if (block.equals(RootsRegistry.ATTUNED_STANDING_STONE.get())) {
v = 64;
xShift = 8 * (int) page.altarRecipe.getPositionsRelative().get(i).getX();
yShift = 8 * (int) page.altarRecipe.getPositionsRelative().get(i).getZ();
xShift = 8 * pos.getX();
yShift = 8 * pos.getZ();
}
this.blit(poseStack, basePosX + 93 + xShift, basePosY + 153 + yShift, u, v, 16, 16);
}
});

for (int i = 0; i < page.altarRecipe.getIngredients().size(); i++) {
slots.add(new ScreenSlotInstance(page.altarRecipe.getIngredients().get(i), (int) basePosX + 64 + 24 * i, (int) basePosY + 56));
var stack = page.altarRecipe.getIngredients().get(i).getItems()[0];
slots.add(new ScreenSlotInstance(stack, (int) basePosX + 64 + 24 * i, (int) basePosY + 56));
}
for (int i = 0; i < page.altarRecipe.getIncenses().size(); i++) {
slots.add(new ScreenSlotInstance(page.altarRecipe.getIncenses().get(i), (int) basePosX + 76 + 16 * i, (int) basePosY + 88));
var stack = page.altarRecipe.getIncenses().get(i).getItems()[0];
slots.add(new ScreenSlotInstance(stack, (int) basePosX + 76 + 16 * i, (int) basePosY + 88));
}

title = makeTitle();
textLines.add(new ScreenTextInstance(title, basePosX + 96 - (this.font.width(title) / 2.0f), basePosY + 12, RootsUtil.intColor(255, 255, 255)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTic
}
poseStack.popPose();
}
}
}
Loading