Skip to content

Commit

Permalink
trading pedestal and new dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
PinkGoosik committed Jan 12, 2024
1 parent 19add0d commit f7651c4
Show file tree
Hide file tree
Showing 60 changed files with 695 additions and 665 deletions.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ dependencies {
// modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-api:${project.cca_version}"
modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cca_version}"
modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cca_version}"

modLocalRuntime "maven.modrinth:here-be-no-dragons:1.0.0"
modLocalRuntime "maven.modrinth:limitless-structure-block:1.0"
modLocalRuntime "dev.emi:emi-fabric:1.0.29+1.20.1"
}

loom {
accessWidenerPath = file("src/main/resources/artifality.accesswidener")
}

base {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ archives_base_name = artifality
# Dependencies
minecraft_version = 1.20.1
yarn_mappings = 1.20.1+build.10
fabric_loader = 0.15.2
fabric_loader = 0.15.3
fabric_api = 0.91.0+1.20.1
trinkets_version = 3.7.1
cca_version = 5.2.2
3 changes: 3 additions & 0 deletions src/main/java/artifality/ArtifalityMod.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package artifality;

import artifality.command.ArtifalityCommands;
import artifality.data.ArtifalityLootTables;
import artifality.registry.*;
import net.fabricmc.api.ModInitializer;
Expand Down Expand Up @@ -36,11 +37,13 @@ public class ArtifalityMod implements ModInitializer {
public void onInitialize() {
ArtifalityItems.init();
ArtifalityBlocks.init();
ArtifalityBlockEntities.init();
ArtifalityEnchants.init();
ArtifalityFeatures.init();
ArtifalityEvents.init();
ArtifalityLootTables.init();
ArtifalityEffects.init();
ArtifalityCommands.init();

Registry.register(Registries.ITEM_GROUP, id("items"), ITEM_GROUP);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/artifality/block/CrateBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class CrateBlock extends BaseBlock implements Waterloggable {
public static final VoxelShape SHAPE = createCuboidShape(2, 0, 2, 14, 12, 14);
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;

public static final ArrayList<Item> CRYSTALS = new ArrayList<>(List.of(INCREMENTAL_CRYSTAL, LUNAR_CRYSTAL, LIFE_CRYSTAL, WRATH_CRYSTAL));
public static final ArrayList<Item> CRYSTALS = new ArrayList<>(List.of(INCREMENTAL_CRYSTAL, LUNAR_CRYSTAL, LIFE_CRYSTAL));

private final ArrayList<Item> commonArtifacts = new ArrayList<>();
private final ArrayList<Item> rareArtifacts = new ArrayList<>();
Expand All @@ -58,7 +58,7 @@ public CrateBlock(Settings settings, ArtifactRarity rarity) {
this.rarity = rarity;
ArtifalityItems.ITEMS.forEach((id, item) -> {
if(item instanceof ArtifactItem artifact) {
ArtifactRarity artifactRarity = artifact.config.rarity;
ArtifactRarity artifactRarity = artifact.artifactSettings.rarity;
switch (artifactRarity) {
case COMMON -> commonArtifacts.add(item);
case RARE -> rareArtifacts.add(item);
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/artifality/block/LunarPortalBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package artifality.block;

import artifality.extension.PlayerExtension;
import artifality.registry.ArtifalityDimensions;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import java.util.Set;

public class LunarPortalBlock extends Block {

public LunarPortalBlock(Settings settings) {
super(settings);
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
MinecraftServer server = world.getServer();

if(server != null && player instanceof PlayerExtension ex) {
if (!world.getDimensionKey().getValue().equals(ArtifalityDimensions.LUNAR_BAZAAR.getValue())) {
ex.savePrevPosition();
player.teleport(server.getWorld(ArtifalityDimensions.LUNAR_BAZAAR), -20.5, 120.0, -20.5, Set.of(), -45, 0);
}
else {
ex.teleportToPrevPosition();
}
return ActionResult.SUCCESS;
}

return super.onUse(state, world, pos, player, hand, hit);
}
}
46 changes: 46 additions & 0 deletions src/main/java/artifality/block/TradingPedestalBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package artifality.block;

import artifality.block.base.BaseBlock;
import artifality.block.entity.TradingPedestalBlockEntity;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

public class TradingPedestalBlock extends BaseBlock implements BlockEntityProvider {

public TradingPedestalBlock(Settings settings) {
super(settings);
}

@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new TradingPedestalBlockEntity(pos, state);
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if(world.getBlockEntity(pos) instanceof TradingPedestalBlockEntity be) {
// player.sendMessage(Text.literal(be.sellingItem.getName().getString() + " x" + be.sellingItem.getCount()));
// player.sendMessage(Text.literal(be.chargeItem.getName().getString() + " x" + be.chargeItem.getCount()));

if(!be.sellingItem.isEmpty()) {
if(!world.isClient()) {
dropStack(world, pos.up(), be.sellingItem.copy());
be.sellingItem = ItemStack.EMPTY;
be.updateListeners();
}
return ActionResult.SUCCESS;
}
}
return super.onUse(state, world, pos, player, hand, hit);
}
}
2 changes: 1 addition & 1 deletion src/main/java/artifality/block/UpgradingPedestalBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ else if(stack.isOf(Items.NETHER_STAR) && getCharges(state) != 4) {
stack.decrement(1);
return ActionResult.SUCCESS;
}
else if(item instanceof ArtifactItem artifact && artifact.config.hasTiers) {
else if(item instanceof ArtifactItem artifact && artifact.artifactSettings.hasTiers) {
if(getCharges(state) == 3 && TiersUtils.getTier(stack) == 1) {
world.playSound(null, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, SoundEvents.BLOCK_RESPAWN_ANCHOR_DEPLETE.value(), SoundCategory.BLOCKS, 1.0F, 1.0F);
player.setStackInHand(Hand.MAIN_HAND, TiersUtils.withTier(item, 2));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package artifality.block.entity;

import artifality.registry.ArtifalityBlockEntities;
import artifality.registry.ArtifalityItems;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;

public class TradingPedestalBlockEntity extends BlockEntity {
public ItemStack sellingItem = ItemStack.EMPTY;
public ItemStack chargeItem = new ItemStack(ArtifalityItems.LUNAR_CRYSTAL, 10);

public TradingPedestalBlockEntity(BlockPos pos, BlockState state) {
super(ArtifalityBlockEntities.TRADING_PEDESTAL, pos, state);
}

@Override
public void writeNbt(NbtCompound nbt) {
super.writeNbt(nbt);

NbtCompound sellingItemNbt = new NbtCompound();
sellingItemNbt.putString("item", Registries.ITEM.getId(sellingItem.getItem()).toString());
sellingItemNbt.put("nbt", sellingItem.getOrCreateNbt());
sellingItemNbt.putInt("count", sellingItem.getCount());
nbt.put("sellingItem", sellingItemNbt);

NbtCompound chargeItemNbt = new NbtCompound();
chargeItemNbt.putString("item", Registries.ITEM.getId(chargeItem.getItem()).toString());
chargeItemNbt.put("nbt", chargeItem.getOrCreateNbt());
chargeItemNbt.putInt("count", chargeItem.getCount());
nbt.put("chargeItem", chargeItemNbt);
}

@Override
public void readNbt(NbtCompound nbt) {
super.readNbt(nbt);

if(nbt.contains("sellingItem")) {
NbtCompound sellingItemNbt = nbt.getCompound("sellingItem");
var item = Registries.ITEM.getOrEmpty(new Identifier(sellingItemNbt.getString("item")));

if(item.isPresent()) {
this.sellingItem = new ItemStack(item.get(), sellingItemNbt.getInt("count"));
this.sellingItem.setNbt((NbtCompound)sellingItemNbt.get("nbt"));
}
}

if(nbt.contains("chargeItem")) {
NbtCompound chargeItemNbt = nbt.getCompound("chargeItem");
var item = Registries.ITEM.getOrEmpty(new Identifier(chargeItemNbt.getString("item")));

if(item.isPresent()) {
this.chargeItem = new ItemStack(item.get(), chargeItemNbt.getInt("count"));
this.chargeItem.setNbt((NbtCompound)chargeItemNbt.get("nbt"));
}
}
}

@Override
public NbtCompound toInitialChunkDataNbt() {
NbtCompound nbtCompound = new NbtCompound();
this.writeNbt(nbtCompound);
return nbtCompound;
}

@Nullable
@Override
public Packet<ClientPlayPacketListener> toUpdatePacket() {
return BlockEntityUpdateS2CPacket.create(this);
}

public void updateListeners() {
this.markDirty();
this.getWorld().updateListeners(this.getPos(), this.getCachedState(), this.getCachedState(), Block.NOTIFY_ALL);
}
}
20 changes: 12 additions & 8 deletions src/main/java/artifality/client/ArtifalityClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import artifality.ArtifalityMod;
import artifality.block.CrateBlock;
import artifality.block.base.*;
import artifality.client.render.TradingPedestalHud;
import artifality.client.render.TradingPedestalRenderer;
import artifality.item.base.ArtifactItem;
import artifality.registry.ArtifalityBlockEntities;
import artifality.registry.ArtifalityBlocks;
import artifality.api.TwoModelsItemRegistry;
import artifality.registry.ArtifalityItems;
Expand All @@ -12,24 +15,25 @@
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;
import net.minecraft.client.util.ModelIdentifier;

public class ArtifalityClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
BlockEntityRendererFactories.register(ArtifalityBlockEntities.TRADING_PEDESTAL, ctx -> new TradingPedestalRenderer<>());

TradingPedestalHud.register();
ArtifalityParticles.register();

ArtifalityItems.ITEMS.forEach((id, item) -> {
if(item instanceof ArtifactItem artifact) {
if (artifact.config.renderer != null) {
TrinketRendererRegistry.registerRenderer(item, artifact.config.renderer);
if (artifact.artifactSettings.renderer != null) {
TrinketRendererRegistry.registerRenderer(item, artifact.artifactSettings.renderer);
}
if(artifact.config.hasTwoModels) {
if(artifact.artifactSettings.hasTwoModels) {
TwoModelsItemRegistry.register(item);
}
}
Expand Down Expand Up @@ -71,7 +75,7 @@ public void onInitializeClient() {
// });

// Thanks Juce! :)
FabricLoader.getInstance().getModContainer(ArtifalityMod.MOD_ID).ifPresent(artifality ->
ResourceManagerHelper.registerBuiltinResourcePack(ArtifalityMod.id("fancyclusters"), artifality, ResourcePackActivationType.NORMAL));
// FabricLoader.getInstance().getModContainer(ArtifalityMod.MOD_ID).ifPresent(artifality ->
// ResourceManagerHelper.registerBuiltinResourcePack(ArtifalityMod.id("fancyclusters"), artifality, ResourcePackActivationType.NORMAL));
}
}
37 changes: 37 additions & 0 deletions src/main/java/artifality/client/render/TradingPedestalHud.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package artifality.client.render;

import artifality.block.TradingPedestalBlock;
import artifality.block.entity.TradingPedestalBlockEntity;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;

public class TradingPedestalHud {

public static void register() {
HudRenderCallback.EVENT.register((drawContext, tickDelta) -> {
MinecraftClient client = MinecraftClient.getInstance();
HitResult hitResult = client.crosshairTarget;

if (hitResult != null && hitResult.getType() == HitResult.Type.BLOCK) {
BlockPos blockPos = ((BlockHitResult)hitResult).getBlockPos();
BlockState block = client.world.getBlockState(blockPos);

if(block.getBlock() instanceof TradingPedestalBlock && client.world.getBlockEntity(blockPos) instanceof TradingPedestalBlockEntity entity && !entity.sellingItem.isEmpty()) {
drawContext.getMatrices().push();
var height = drawContext.getScaledWindowHeight();
var width = drawContext.getScaledWindowWidth();

var text = Text.literal("Requires: " + entity.chargeItem.getName().getString() + " x" + entity.chargeItem.getCount());
drawContext.drawItem(entity.chargeItem, (width / 2) + 7, (height / 2) - 7);
drawContext.drawTextWithShadow(client.textRenderer, text, (width / 2) - (client.textRenderer.getWidth(text) / 2), (height / 2) + 10, 16777215);
drawContext.getMatrices().pop();
}
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package artifality.client.render;

import artifality.block.entity.TradingPedestalBlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.RotationAxis;
import org.joml.Vector3f;

public class TradingPedestalRenderer<T extends TradingPedestalBlockEntity> implements BlockEntityRenderer<T> {

@Override
public void render(T entity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
var world = entity.getWorld();

if(world != null && !entity.isRemoved()) {
matrices.push();

ItemStack stack = entity.sellingItem;
MinecraftClient client = MinecraftClient.getInstance();
BakedModel model = client.getItemRenderer().getModel(stack, world, null, 0);
Vector3f translate = model.getTransformation().ground.translation;
matrices.translate(translate.x() + 0.5, translate.y() + 1.25, translate.z() + 0.5);

if (stack.getItem() instanceof BlockItem) {
matrices.scale(1.5F, 1.5F, 1.5F);
}
else {
matrices.scale(1.25F, 1.25F, 1.25F);
}

float rotation = ((int) (MinecraftClient.getInstance().world.getTime() % 314) + tickDelta) / 25.0F + 6.0F;
matrices.multiply(RotationAxis.POSITIVE_Y.rotation(rotation));
client.getItemRenderer().renderItem(stack, ModelTransformationMode.GROUND, false, matrices, vertexConsumers, light, overlay, model);

matrices.pop();
}
}

}
Loading

0 comments on commit f7651c4

Please sign in to comment.