Skip to content

Commit

Permalink
wip: Allow attuned shards to all kinds of waystones
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Dec 16, 2023
1 parent 6a75fb3 commit b7a95b5
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.blay09.mods.balm.api.Balm;
import net.blay09.mods.waystones.api.IWaystone;
import net.blay09.mods.waystones.block.entity.LandingStoneBlockEntity;
import net.blay09.mods.waystones.block.entity.ModBlockEntities;
import net.blay09.mods.waystones.block.entity.WarpPlateBlockEntity;
import net.blay09.mods.waystones.block.entity.WaystoneBlockEntityBase;
import net.minecraft.core.BlockPos;
Expand All @@ -11,6 +12,7 @@
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
Expand Down Expand Up @@ -57,4 +59,8 @@ protected InteractionResult handleActivation(Level world, BlockPos pos, Player p
return InteractionResult.SUCCESS;
}

@Override
public BlockEntityType<? extends WaystoneBlockEntityBase> getTickingBlockEntityType() {
return ModBlockEntities.landingStone.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import net.blay09.mods.balm.api.network.BalmNetworking;
import net.blay09.mods.waystones.api.IWaystone;
import net.blay09.mods.waystones.api.WaystoneOrigin;
import net.blay09.mods.waystones.block.entity.ModBlockEntities;
import net.blay09.mods.waystones.block.entity.PortstoneBlockEntity;
import net.blay09.mods.waystones.block.entity.WaystoneBlockEntityBase;
import net.blay09.mods.waystones.menu.WaystoneSelectionMenu;
import net.blay09.mods.waystones.core.WarpMode;
import net.blay09.mods.waystones.core.Waystone;
Expand All @@ -27,6 +29,8 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
Expand Down Expand Up @@ -164,4 +168,5 @@ public void appendHoverText(ItemStack stack, @Nullable BlockGetter world, List<C

super.appendHoverText(stack, world, list, flag);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.blay09.mods.balm.api.Balm;
import net.blay09.mods.waystones.api.IWaystone;
import net.blay09.mods.waystones.block.entity.ModBlockEntities;
import net.blay09.mods.waystones.block.entity.SharestoneBlockEntity;
import net.blay09.mods.waystones.block.entity.WaystoneBlockEntityBase;
import net.minecraft.ChatFormatting;
Expand All @@ -16,6 +17,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
Expand Down Expand Up @@ -92,4 +94,8 @@ public DyeColor getColor() {
return color;
}

@Override
public BlockEntityType<? extends WaystoneBlockEntityBase> getTickingBlockEntityType() {
return ModBlockEntities.sharestone.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,13 @@ public static Component getGalacticName(IWaystone waystone) {
return galacticName;
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level world, BlockState state, BlockEntityType<T> type) {
return world.isClientSide ? null : createTickerHelper(type,
ModBlockEntities.warpPlate.get(),
(level, pos, state2, blockEntity) -> blockEntity.serverTick());
protected boolean shouldOpenMenuWhenPlaced() {
return false;
}

@Override
protected boolean shouldOpenMenuWhenPlaced() {
return false;
public BlockEntityType<? extends WaystoneBlockEntityBase> getTickingBlockEntityType() {
return ModBlockEntities.warpPlate.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.blay09.mods.balm.api.Balm;
import net.blay09.mods.waystones.api.IWaystone;
import net.blay09.mods.waystones.block.entity.ModBlockEntities;
import net.blay09.mods.waystones.block.entity.WaystoneBlockEntity;
import net.blay09.mods.waystones.block.entity.WaystoneBlockEntityBase;
import net.blay09.mods.waystones.config.WaystonesConfig;
Expand All @@ -22,6 +23,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
Expand Down Expand Up @@ -162,4 +164,8 @@ public boolean isPathfindable(BlockState blockState, BlockGetter blockGetter, Bl
return false;
}

@Override
public BlockEntityType<? extends WaystoneBlockEntityBase> getTickingBlockEntityType() {
return ModBlockEntities.waystone.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import net.minecraft.world.level.*;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.*;
Expand Down Expand Up @@ -202,7 +204,7 @@ protected InteractionResult handleEditActions(Level world, Player player, Waysto
return InteractionResult.SUCCESS;
}

if (!world.isClientSide && shouldOpenMenuWhenPlaced()) {
if (!world.isClientSide) {
MenuProvider settingsContainerProvider = tileEntity.getSettingsMenuProvider();
if (settingsContainerProvider != null) {
Balm.getNetworking().openGui(player, settingsContainerProvider);
Expand Down Expand Up @@ -361,7 +363,7 @@ public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable L
WaystoneEditPermissions result = PlayerWaystoneManager.mayEditWaystone(player, world, waystoneTileEntity.getWaystone());
if (result == WaystoneEditPermissions.ALLOW) {
MenuProvider settingsContainerProvider = waystoneTileEntity.getSettingsMenuProvider();
if (settingsContainerProvider != null) {
if (settingsContainerProvider != null && shouldOpenMenuWhenPlaced()) {
Balm.getNetworking().openGui(player, settingsContainerProvider);
}
}
Expand All @@ -384,4 +386,19 @@ public BlockState mirror(BlockState state, Mirror mirror) {
return state.rotate(mirror.getRotation(state.getValue(FACING)));
}

public BlockEntityType<? extends WaystoneBlockEntityBase> getTickingBlockEntityType() {
return null;
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level world, BlockState state, BlockEntityType<T> type) {
final var tickingBlockEntityType = getTickingBlockEntityType();
if (tickingBlockEntityType == null) {
return null;
}
return world.isClientSide ? null : createTickerHelper(type,
tickingBlockEntityType,
(level, pos, state2, blockEntity) -> blockEntity.serverTick());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ public PortstoneBlockEntity(BlockPos worldPosition, BlockState state) {
public AABB getRenderBoundingBox() {
return new AABB(worldPosition.getX(), worldPosition.getY(), worldPosition.getZ(), worldPosition.getX() + 1, worldPosition.getY() + 2, worldPosition.getZ() + 1);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.blay09.mods.waystones.block.entity;

import net.blay09.mods.balm.api.Balm;
import net.blay09.mods.balm.api.container.ImplementedContainer;
import net.blay09.mods.balm.api.menu.BalmMenuProvider;
import net.blay09.mods.waystones.Waystones;
import net.blay09.mods.waystones.api.*;
Expand All @@ -16,17 +15,13 @@
import net.blay09.mods.waystones.worldgen.namegen.NameGenerationMode;
import net.blay09.mods.waystones.worldgen.namegen.NameGenerator;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.ContainerHelper;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.Nameable;
import net.minecraft.world.effect.MobEffectInstance;
Expand All @@ -37,7 +32,6 @@
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ContainerData;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.RecipeHolder;
Expand Down Expand Up @@ -215,31 +209,15 @@ private boolean isEntityOnWarpPlate(Entity entity) {
&& entity.getZ() >= worldPosition.getZ() && entity.getZ() < worldPosition.getZ() + 1;
}

@Override
protected void craft(WarpPlateRecipe recipe) {
super.craft(recipe);
this.completedFirstAttunement = true;
}

@Override
public void serverTick() {
WarpPlateRecipe recipe = trySelectRecipe();
if (recipe != null) {
attunementTicks++;

if (attunementTicks >= getMaxAttunementTicks()) {
attunementTicks = 0;
ItemStack attunedShard = recipe.assemble(this, RegistryAccess.EMPTY);
WaystonesAPI.setBoundWaystone(attunedShard, getWaystone());
ItemStack centerStack = getItem(0);
if (centerStack.getCount() > 1) {
centerStack = centerStack.copyWithCount(centerStack.getCount() - 1);
if (!Minecraft.getInstance().player.getInventory().add(centerStack)) {
Minecraft.getInstance().player.drop(centerStack, false);
}
}
setItem(0, attunedShard);
for (int i = 1; i <= 4; i++) {
getItem(i).shrink(1);
}
this.completedFirstAttunement = true;
}
} else {
attunementTicks = 0;
}
super.serverTick();

if (getBlockState().getValue(WarpPlateBlock.STATUS) != WarpPlateBlock.WarpPlateStatus.IDLE) {
AABB boundsAbove = new AABB(worldPosition.getX(),
Expand Down Expand Up @@ -269,7 +247,7 @@ public void serverTick() {
ItemStack targetAttunementStack = getTargetAttunementStack();
IWaystone targetWaystone = WaystonesAPI.getBoundWaystone(targetAttunementStack).orElse(null);
if (targetWaystone != null && targetWaystone.isValid()) {
teleportToWarpPlate(entity, targetWaystone, targetAttunementStack);
teleportToTarget(entity, targetWaystone, targetAttunementStack);
}

if (entity instanceof Player) {
Expand Down Expand Up @@ -306,7 +284,7 @@ private int getWarpPlateUseTime() {
return Mth.clamp((int) (configuredUseTime * useTimeMultiplier), 1, configuredUseTime * 2);
}

private void teleportToWarpPlate(Entity entity, IWaystone targetWaystone, ItemStack targetAttunementStack) {
private void teleportToTarget(Entity entity, IWaystone targetWaystone, ItemStack targetAttunementStack) {
WaystonesAPI.createDefaultTeleportContext(entity, targetWaystone, WarpMode.WARP_PLATE, getWaystone())
.flatMap(ctx -> {
ctx.setWarpItem(targetAttunementStack);
Expand Down Expand Up @@ -383,19 +361,6 @@ private void applyWarpPlateEffects(Entity entity) {
}
}

@Nullable
private WarpPlateRecipe trySelectRecipe() {
if (!readyForAttunement || level == null) {
return null;
}
if (getItem(0).getCount() > 1) {
return null; //prevents crafting when more than 1 ingredient is present
}

return level.getRecipeManager().getRecipeFor(ModRecipes.warpPlateRecipeType, this, level)
.map(RecipeHolder::value).orElse(null);
}

public ItemStack getTargetAttunementStack() {
boolean shouldRoundRobin = false;
boolean shouldPrioritizeSingleUseShards = false;
Expand Down Expand Up @@ -429,7 +394,13 @@ public Optional<IWaystone> getTargetWaystone() {
return WaystonesAPI.getBoundWaystone(getTargetAttunementStack());
}


@Nullable
protected WarpPlateRecipe trySelectRecipe() {
if (!readyForAttunement) {
return null;
}
return super.trySelectRecipe();
}

/**
* We delay attunement until the menu is opened to show the player what's happening inside the slots before converting the items to an attuned shard.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
import net.blay09.mods.balm.common.BalmBlockEntity;
import net.blay09.mods.waystones.api.IWaystone;
import net.blay09.mods.waystones.api.WaystoneOrigin;
import net.blay09.mods.waystones.api.WaystonesAPI;
import net.blay09.mods.waystones.block.WaystoneBlock;
import net.blay09.mods.waystones.block.WaystoneBlockBase;
import net.blay09.mods.waystones.core.*;
import net.blay09.mods.waystones.recipe.ModRecipes;
import net.blay09.mods.waystones.recipe.WarpPlateRecipe;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.Tag;
Expand All @@ -20,6 +25,7 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.inventory.ContainerData;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
Expand Down Expand Up @@ -228,4 +234,47 @@ public NonNullList<ItemStack> getItems() {
public ContainerData getContainerData() {
return dataAccess;
}

@Nullable
protected WarpPlateRecipe trySelectRecipe() {
if (level == null) {
return null;
}
if (getItem(0).getCount() > 1) {
return null; //prevents crafting when more than 1 ingredient is present
}

return level.getRecipeManager().getRecipeFor(ModRecipes.warpPlateRecipeType, this, level)
.map(RecipeHolder::value).orElse(null);
}

public void serverTick() {
WarpPlateRecipe recipe = trySelectRecipe();
if (recipe != null) {
attunementTicks++;

if (attunementTicks >= getMaxAttunementTicks()) {
attunementTicks = 0;
craft(recipe);
}
} else {
attunementTicks = 0;
}
}

protected void craft(WarpPlateRecipe recipe) {
ItemStack attunedShard = recipe.assemble(this, RegistryAccess.EMPTY);
WaystonesAPI.setBoundWaystone(attunedShard, getWaystone());
ItemStack centerStack = getItem(0);
if (centerStack.getCount() > 1) {
centerStack = centerStack.copyWithCount(centerStack.getCount() - 1);
if (!Minecraft.getInstance().player.getInventory().add(centerStack)) {
Minecraft.getInstance().player.drop(centerStack, false);
}
}
setItem(0, attunedShard);
for (int i = 1; i <= 4; i++) {
getItem(i).shrink(1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int mouseX,
RenderSystem.setShader(GameRenderer::getPositionTexShader);
guiGraphics.setColor(1f, 1f, 1f, 1f);
guiGraphics.blit(WAYSTONE_GUI_TEXTURES, leftPos, topPos, 0, 0, imageWidth, imageHeight);

guiGraphics.blit(WAYSTONE_GUI_TEXTURES, leftPos + 107 - (int) (10 * menu.getAttunementProgress()), topPos + 54, 176, 0, (int) (10 * menu.getAttunementProgress()), 4);
guiGraphics.blit(WAYSTONE_GUI_TEXTURES, leftPos + 69, topPos + 54, 176, 0, (int) (10 * menu.getAttunementProgress()), 4);
guiGraphics.blit(WAYSTONE_GUI_TEXTURES, leftPos + 72, topPos + 68 - (int) (10 * menu.getAttunementProgress()), 176, 4, 4, (int) (10 * menu.getAttunementProgress()));
guiGraphics.blit(WAYSTONE_GUI_TEXTURES, leftPos + 100, topPos + 68 - (int) (10 * menu.getAttunementProgress()), 176, 4, 4, (int) (10 * menu.getAttunementProgress()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public enum WarpMode {
WARP_STONE(() -> WaystonesConfig.getActive().xpCost.warpStoneXpCostMultiplier, WarpMode::waystoneIsActivated, false),
WAYSTONE_TO_WAYSTONE(() -> WaystonesConfig.getActive().xpCost.waystoneXpCostMultiplier, WarpMode::waystoneIsActivated, false),
SHARESTONE_TO_SHARESTONE(() -> WaystonesConfig.getActive().xpCost.sharestoneXpCostMultiplier, WarpMode::sharestonesOnly, false),
WARP_PLATE(() -> WaystonesConfig.getActive().xpCost.warpPlateXpCostMultiplier, WarpMode::warpPlatesOnly, false),
WARP_PLATE(() -> WaystonesConfig.getActive().xpCost.warpPlateXpCostMultiplier, WarpMode::always, false),
PORTSTONE_TO_WAYSTONE(() -> WaystonesConfig.getActive().xpCost.portstoneXpCostMultiplier, WarpMode::waystoneIsActivated, false),
CUSTOM(() -> 0.0, WarpMode::always, false);

Expand Down
Loading

0 comments on commit b7a95b5

Please sign in to comment.