Skip to content

Commit

Permalink
add customer gui and block textures
Browse files Browse the repository at this point in the history
  • Loading branch information
IAFEnvoy committed Dec 24, 2024
1 parent b50151e commit 0ec3dd3
Show file tree
Hide file tree
Showing 42 changed files with 682 additions and 35 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/iafenvoy/nee/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
public class Constants {
public static final Identifier CHEQUE_CHECK_IN = Identifier.of(NotEnoughEconomy.MOD_ID, "cheque_check_in");
public static final Identifier CHEQUE_CHECK_OUT = Identifier.of(NotEnoughEconomy.MOD_ID, "cheque_check_out");
public static final Identifier TRADE = Identifier.of(NotEnoughEconomy.MOD_ID, "trade");
}
5 changes: 5 additions & 0 deletions src/main/java/com/iafenvoy/nee/NotEnoughEconomyClient.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.iafenvoy.nee;

import com.iafenvoy.nee.registry.NeeRenderers;
import com.iafenvoy.nee.registry.NeeScreenHandlers;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

@Environment(EnvType.CLIENT)
public final class NotEnoughEconomyClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
NeeRenderers.registerBlockEntityRenderers();
NeeScreenHandlers.registerScreen();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.iafenvoy.nee.NotEnoughEconomy;
import com.iafenvoy.nee.screen.handler.ChequeTableScreenHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -21,7 +20,7 @@
import java.util.Optional;
import java.util.function.BiFunction;

public class ChequeTableBlock extends Block {
public class ChequeTableBlock extends WorkStationBlock {
public ChequeTableBlock() {
super(Settings.copy(Blocks.CRAFTING_TABLE));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.iafenvoy.nee.NotEnoughEconomy;
import com.iafenvoy.nee.screen.handler.ExchangeStationScreenHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -21,7 +20,7 @@
import java.util.Optional;
import java.util.function.BiFunction;

public class ExchangeStationBlock extends Block {
public class ExchangeStationBlock extends WorkStationBlock {
public ExchangeStationBlock() {
super(Settings.copy(Blocks.CRAFTING_TABLE));
}
Expand Down
11 changes: 2 additions & 9 deletions src/main/java/com/iafenvoy/nee/item/block/TradeStationBlock.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.iafenvoy.nee.item.block;

import com.iafenvoy.nee.item.block.entity.TradeStationBlockEntity;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.LivingEntity;
Expand All @@ -16,7 +15,7 @@
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

public class TradeStationBlock extends BlockWithEntity {
public class TradeStationBlock extends WorkStationBlock implements BlockEntityProvider {
public TradeStationBlock() {
super(Settings.copy(Blocks.CRAFTING_TABLE));
}
Expand All @@ -40,11 +39,5 @@ public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable Livi
super.onPlaced(world, pos, state, placer, itemStack);
if (world.getBlockEntity(pos) instanceof TradeStationBlockEntity blockEntity && placer instanceof PlayerEntity player)
blockEntity.setOwner(player.getUuid());

}

@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/iafenvoy/nee/item/block/WorkStationBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.iafenvoy.nee.item.block;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;

public abstract class WorkStationBlock extends Block {
protected WorkStationBlock(Settings settings) {
super(settings);
}

@Override
public VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
return VoxelShapes.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import com.iafenvoy.nee.component.TradeStationComponent;
import com.iafenvoy.nee.registry.NeeBlockEntities;
import com.iafenvoy.nee.screen.handler.TradeStationCustomerScreenHandler;
import com.iafenvoy.nee.screen.handler.TradeStationOwnerScreenHandler;
import com.iafenvoy.nee.screen.inventory.ImplementedInventory;
import com.mojang.authlib.GameProfile;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -27,6 +26,7 @@
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.function.BiFunction;
Expand Down Expand Up @@ -74,6 +74,7 @@ public void writeToNbt(NbtCompound nbt) {
public void readFromNbt(NbtCompound nbt) {
if (nbt.contains(OWNER_KEY, NbtElement.INT_ARRAY_TYPE)) this.owner = nbt.getUuid(OWNER_KEY);
if (nbt.contains(OWNER_NAME_KEY, NbtElement.STRING_TYPE)) this.ownerNameCache = nbt.getString(OWNER_NAME_KEY);
this.display.clear();
Inventories.readNbt(nbt.getCompound("display"), this.display);
}

Expand Down Expand Up @@ -105,20 +106,26 @@ public Text getDisplayName() {

@Override
public @Nullable ScreenHandler createMenu(int syncId, PlayerInventory playerInventory, PlayerEntity player) {
return new TradeStationOwnerScreenHandler(syncId, playerInventory,
ScreenHandlerContext ctx = new ScreenHandlerContext() {
@Override
public <T> Optional<T> get(BiFunction<World, BlockPos, T> getter) {
return Optional.of(getter.apply(TradeStationBlockEntity.this.world, TradeStationBlockEntity.this.pos));
}
};
if (Objects.equals(this.getOwner(), player.getUuid())) return new TradeStationOwnerScreenHandler(syncId,
playerInventory,
ImplementedInventory.of(this.left, this::markDirty),
ImplementedInventory.of(this.right, this::markDirty),
ImplementedInventory.of(this.inventory, this::markDirty),
ImplementedInventory.of(this.display, () -> {
this.markDirty();
TradeStationComponent.COMPONENT.sync(this);
}),
new ScreenHandlerContext() {
@Override
public <T> Optional<T> get(BiFunction<World, BlockPos, T> getter) {
return Optional.of(getter.apply(TradeStationBlockEntity.this.world, TradeStationBlockEntity.this.pos));
}
});
ctx);
else return new TradeStationCustomerScreenHandler(syncId, playerInventory,
ImplementedInventory.of(this.left),
ImplementedInventory.of(this.right),
ctx);
}

public ItemStack getDisplayStack() {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/iafenvoy/nee/registry/NeeBlocks.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.iafenvoy.nee.registry;

import com.iafenvoy.nee.NotEnoughEconomy;
import com.iafenvoy.nee.item.block.ChequeTableBlock;
import com.iafenvoy.nee.item.block.ExchangeStationBlock;
import com.iafenvoy.nee.item.block.TradeStationBlock;
Expand All @@ -8,14 +9,15 @@
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;

public final class NeeBlocks {
public static final ExchangeStationBlock EXCHANGE_STATION = register("exchange_station", new ExchangeStationBlock());
public static final ChequeTableBlock CHEQUE_TABLE = register("cheque_table", new ChequeTableBlock());
public static final TradeStationBlock TRADE_STATION = register("trade_station", new TradeStationBlock());

public static <T extends Block> T register(String id, T block) {
Registry.register(Registries.BLOCK, id, block);
Registry.register(Registries.BLOCK, Identifier.of(NotEnoughEconomy.MOD_ID, id), block);
NeeItems.register(id, new BlockItem(block, new Item.Settings()));
return block;
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/iafenvoy/nee/registry/NeeItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public final class NeeItems {
public static final CoinItem DIAMOND_COIN = register("diamond_coin", new CoinItem(1000));
public static final CoinItem EMERALD_COIN = register("emerald_coin", new CoinItem(10000));
public static final CoinItem NETHERITE_COIN = register("netherite_coin", new CoinItem(100000));
public static final List<CoinItem> COINS = List.of(COPPER_COIN, IRON_COIN, GOLD_COIN, DIAMOND_COIN, EMERALD_COIN, NETHERITE_COIN);

public static final ChequeItem CHEQUE = register("cheque", new ChequeItem());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.iafenvoy.nee.NotEnoughEconomy;
import com.iafenvoy.nee.screen.gui.ChequeTableScreen;
import com.iafenvoy.nee.screen.gui.ExchangeStationScreen;
import com.iafenvoy.nee.screen.gui.TradeStationCustomerScreen;
import com.iafenvoy.nee.screen.gui.TradeStationOwnerScreen;
import com.iafenvoy.nee.screen.handler.ChequeTableScreenHandler;
import com.iafenvoy.nee.screen.handler.ExchangeStationScreenHandler;
import com.iafenvoy.nee.screen.handler.TradeStationCustomerScreenHandler;
import com.iafenvoy.nee.screen.handler.TradeStationOwnerScreenHandler;
import net.minecraft.client.gui.screen.ingame.HandledScreens;
import net.minecraft.registry.Registries;
Expand All @@ -20,14 +22,19 @@ public final class NeeScreenHandlers {
public static final ScreenHandlerType<ExchangeStationScreenHandler> EXCHANGE_STATION = register("exchange_station", new ScreenHandlerType<>(ExchangeStationScreenHandler::new, FeatureSet.of(FeatureFlags.VANILLA)));
public static final ScreenHandlerType<ChequeTableScreenHandler> CHEQUE_TABLE = register("cheque_table", new ScreenHandlerType<>(ChequeTableScreenHandler::new, FeatureSet.of(FeatureFlags.VANILLA)));
public static final ScreenHandlerType<TradeStationOwnerScreenHandler> TRADE_STATION_OWNER = register("trade_station_owner", new ScreenHandlerType<>(TradeStationOwnerScreenHandler::new, FeatureSet.of(FeatureFlags.VANILLA)));
public static final ScreenHandlerType<TradeStationCustomerScreenHandler> TRADE_STATION_CUSTOMER = register("trade_station_customer", new ScreenHandlerType<>(TradeStationCustomerScreenHandler::new, FeatureSet.of(FeatureFlags.VANILLA)));

public static <T extends ScreenHandler> ScreenHandlerType<T> register(String id, ScreenHandlerType<T> handler) {
return Registry.register(Registries.SCREEN_HANDLER, Identifier.of(NotEnoughEconomy.MOD_ID, id), handler);
}

public static void init() {
}

public static void registerScreen(){
HandledScreens.register(EXCHANGE_STATION, ExchangeStationScreen::new);
HandledScreens.register(CHEQUE_TABLE, ChequeTableScreen::new);
HandledScreens.register(TRADE_STATION_OWNER, TradeStationOwnerScreen::new);
HandledScreens.register(TRADE_STATION_CUSTOMER, TradeStationCustomerScreen::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public TradeStationBlockEntityRenderer(BlockEntityRendererFactory.Context ctx) {

@Override
public void render(TradeStationBlockEntity entity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
if (entity.getDisplayStack().isEmpty()) return;
matrices.push();
matrices.translate(0.5, 0.5, 0.5);
this.renderItem(entity, tickDelta, matrices, vertexConsumers, overlay);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.iafenvoy.nee.Constants;
import com.iafenvoy.nee.NotEnoughEconomy;
import com.iafenvoy.nee.screen.handler.ChequeTableScreenHandler;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.minecraft.client.gui.DrawContext;
Expand All @@ -12,6 +14,7 @@
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

@Environment(EnvType.CLIENT)
public class ChequeTableScreen extends HandledScreen<ChequeTableScreenHandler> {
private static final Identifier TEXTURE = Identifier.of(NotEnoughEconomy.MOD_ID, "textures/gui/cheque_table.png");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import com.iafenvoy.nee.NotEnoughEconomy;
import com.iafenvoy.nee.screen.handler.ExchangeStationScreenHandler;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

@Environment(EnvType.CLIENT)
public class ExchangeStationScreen extends HandledScreen<ExchangeStationScreenHandler> {
private static final Identifier TEXTURE = Identifier.of(NotEnoughEconomy.MOD_ID, "textures/gui/exchange_station.png");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.iafenvoy.nee.screen.gui;

import com.iafenvoy.nee.NotEnoughEconomy;
import com.iafenvoy.nee.screen.handler.TradeStationCustomerScreenHandler;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

@Environment(EnvType.CLIENT)
public class TradeStationCustomerScreen extends HandledScreen<TradeStationCustomerScreenHandler> {
private static final Identifier TEXTURE = Identifier.of(NotEnoughEconomy.MOD_ID, "textures/gui/trade_station_customer.png");

public TradeStationCustomerScreen(TradeStationCustomerScreenHandler handler, PlayerInventory inventory, Text title) {
super(handler, inventory, title);
this.backgroundHeight++;
}

@Override
protected void init() {
super.init();
int i = (this.width - this.backgroundWidth) / 2;
int j = (this.height - this.backgroundHeight) / 2;
this.addDrawableChild(ButtonWidget.builder(Text.literal("→"), button -> {

}).position(i + 80, j + 36).size(16, 16).build());
}

@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
this.renderBackground(context);
super.render(context, mouseX, mouseY, delta);
this.drawMouseoverTooltip(context, mouseX, mouseY);
}

@Override
protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) {
int i = (this.width - this.backgroundWidth) / 2;
int j = (this.height - this.backgroundHeight) / 2;
context.drawTexture(TEXTURE, i, j, 0, 0, this.backgroundWidth, this.backgroundHeight);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.iafenvoy.nee.NotEnoughEconomy;
import com.iafenvoy.nee.screen.handler.TradeStationOwnerScreenHandler;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
Expand All @@ -10,6 +12,7 @@
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

@Environment(EnvType.CLIENT)
public class TradeStationOwnerScreen extends HandledScreen<TradeStationOwnerScreenHandler> {
private static final Identifier TEXTURE = Identifier.of(NotEnoughEconomy.MOD_ID, "textures/gui/trade_station_owner.png");

Expand Down
Loading

0 comments on commit 0ec3dd3

Please sign in to comment.