-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19add0d
commit f7651c4
Showing
60 changed files
with
695 additions
and
665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/main/java/artifality/block/entity/TradingPedestalBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/artifality/client/render/TradingPedestalHud.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
}); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/artifality/client/render/TradingPedestalRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.