Skip to content

Commit

Permalink
1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
gliscowo committed Sep 4, 2024
1 parent a7d6039 commit 9bf91d0
Show file tree
Hide file tree
Showing 22 changed files with 187 additions and 116 deletions.
14 changes: 9 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
plugins {
id 'fabric-loom' version '1.5-SNAPSHOT'
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

archivesBaseName = project.archives_base_name
version = "${project.mod_version}+${project.minecraft_base_version}"
group = project.maven_group

loom {
accessWidenerPath = project.file("src/main/resources/outthedoor.accesswidener");
}

repositories {
// modmenu, trinkets
maven { url "https://maven.terraformersmc.com/" }
Expand Down Expand Up @@ -55,8 +59,8 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
it.options.release = 17
// Minecraft 1.21 upwards uses Java 21.
it.options.release = 21
}

java {
Expand Down
22 changes: 11 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_base_version=1.20.3
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
loader_version=0.15.6
minecraft_base_version=1.21
minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
loader_version=0.16.3

fabric_version=0.95.0+1.20.4
fabric_version=0.103.0+1.21.1

# Mod Properties
mod_version=0.1.0
Expand All @@ -17,16 +17,16 @@

# Dependencies
# https://maven.terraformersmc.com/releases/dev/emi/trinkets
trinkets_version=3.8.0
trinkets_version=3.10.0

# https://github.com/Ladysnake/Cardinal-Components-API/releases/tag/5.4.0
cca_version=5.4.0
# https://github.com/Ladysnake/Cardinal-Components-API/releases
cca_version=6.1.1

# https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/
rei_version=14.0.688
rei_version=16.0.754

# https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu
modmenu_version=9.0.0
modmenu_version=11.0.2

# https://maven.wispforest.io/io/wispforest/owo-lib/
owo_version=0.12.3+1.20.3
owo_version=0.12.12+1.21
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
16 changes: 7 additions & 9 deletions src/main/java/io/wispforest/outthedoor/OutTheDoor.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package io.wispforest.outthedoor;

import dev.emi.trinkets.TrinketsNetwork;
import dev.emi.trinkets.data.EntitySlotLoader;
import io.wispforest.outthedoor.item.BackpackItem;
import io.wispforest.outthedoor.misc.BackpackScreenHandler;
import io.wispforest.outthedoor.misc.BackpackType;
import io.wispforest.outthedoor.misc.OutTheDoorConfig;
import io.wispforest.outthedoor.mixin.EntitySlotLoaderAccessor;
import io.wispforest.outthedoor.object.OutTheDoorBackpackTypes;
import io.wispforest.outthedoor.object.OutTheDoorBlocks;
import io.wispforest.outthedoor.object.OutTheDoorItems;
import io.wispforest.owo.itemgroup.Icon;
import io.wispforest.owo.itemgroup.OwoItemGroup;
import io.wispforest.owo.network.OwoNetChannel;
import io.wispforest.owo.registration.reflect.FieldRegistrationHandler;
import io.wispforest.owo.serialization.CodecUtils;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.fabricmc.fabric.api.event.registry.RegistryAttribute;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
Expand All @@ -39,7 +37,7 @@ public class OutTheDoor implements ModInitializer {
.attribute(RegistryAttribute.SYNCED)
.buildAndRegister();

public static final ScreenHandlerType<BackpackScreenHandler> BACKPACK_SCREEN_HANDLER = new ExtendedScreenHandlerType<>(BackpackScreenHandler::client);
public static final ScreenHandlerType<BackpackScreenHandler> BACKPACK_SCREEN_HANDLER = new ExtendedScreenHandlerType<>(BackpackScreenHandler::client, CodecUtils.toPacketCodec(BackpackItem.ScreenData.ENDEC));

@Override
public void onInitialize() {
Expand All @@ -50,14 +48,14 @@ public void onInitialize() {

Registry.register(Registries.SCREEN_HANDLER, id("backpack"), BACKPACK_SCREEN_HANDLER);

ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
sender.sendPacket(TrinketsNetwork.SYNC_SLOTS, ((EntitySlotLoaderAccessor) EntitySlotLoader.SERVER).otd$getSlotsPacket());
});
// ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
// sender.sendPacket(TrinketsNetwork.SYNC_SLOTS, ((EntitySlotLoaderAccessor) EntitySlotLoader.SERVER).otd$getSlotsPacket());
// });

GROUP.initialize();
}

public static Identifier id(String path) {
return new Identifier(MOD_ID, path);
return Identifier.of(MOD_ID, path);
}
}
12 changes: 4 additions & 8 deletions src/main/java/io/wispforest/outthedoor/block/BackpackBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mojang.serialization.MapCodec;
import dev.emi.trinkets.api.TrinketItem;
import io.wispforest.outthedoor.OutTheDoor;
import io.wispforest.outthedoor.item.BackpackItem;
import io.wispforest.outthedoor.misc.BackpackScreenHandler;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
Expand All @@ -13,13 +12,11 @@
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.state.StateManager;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -64,18 +61,17 @@ public BlockState getPlacementState(ItemPlacementContext ctx) {
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
if (world.getBlockEntity(pos) instanceof BackpackBlockEntity backpack && backpack.hasBackpack()) {
if (!world.isClient) {
if (player.isSneaking()) {
if (!TrinketItem.equipItem(player, backpack.backpack())) return ActionResult.PASS;
world.removeBlock(pos, false);
} else {
player.openHandledScreen(new ExtendedScreenHandlerFactory() {
player.openHandledScreen(new ExtendedScreenHandlerFactory<BackpackItem.ScreenData>() {
@Override
public void writeScreenOpeningData(ServerPlayerEntity player, PacketByteBuf buf) {
buf.writeRegistryValue(OutTheDoor.BACKPACK_REGISTRY, backpack.type());
buf.writeBoolean(false);
public BackpackItem.ScreenData getScreenOpeningData(ServerPlayerEntity player) {
return new BackpackItem.ScreenData(backpack.type(), false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.wispforest.outthedoor.block;

import io.wispforest.endec.impl.KeyedEndec;
import io.wispforest.outthedoor.item.BackpackItem;
import io.wispforest.outthedoor.misc.BackpackType;
import io.wispforest.outthedoor.object.OutTheDoorBlocks;
import io.wispforest.owo.ops.WorldOps;
import io.wispforest.owo.serialization.endec.BuiltInEndecs;
import io.wispforest.owo.serialization.endec.KeyedEndec;
import io.wispforest.owo.serialization.endec.MinecraftEndecs;
import net.fabricmc.fabric.api.blockview.v2.RenderDataBlockEntity;
import net.fabricmc.fabric.api.transfer.v1.item.InventoryStorage;
import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage;
Expand All @@ -17,12 +17,13 @@
import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;

public class BackpackBlockEntity extends BlockEntity implements RenderDataBlockEntity {

public static final KeyedEndec<ItemStack> BACKPACK = BuiltInEndecs.ITEM_STACK.keyed("Backpack", ItemStack.EMPTY);
public static final KeyedEndec<ItemStack> BACKPACK = MinecraftEndecs.ITEM_STACK.keyed("Backpack", ItemStack.EMPTY);

private ItemStack backpack = ItemStack.EMPTY;
private SimpleInventory inventory = new SimpleInventory(0);
Expand All @@ -37,8 +38,8 @@ public boolean hasBackpack() {

public BackpackType type() {
return this.hasBackpack()
? ((BackpackItem) this.backpack.getItem()).type
: null;
? ((BackpackItem) this.backpack.getItem()).type
: null;
}

public SimpleInventory inventory() {
Expand All @@ -50,21 +51,21 @@ public BackpackItem cast() {
}

@Override
public void readNbt(NbtCompound nbt) {
super.readNbt(nbt);
this.setBackpack(nbt.get(BACKPACK));
public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) {
super.readNbt(nbt, registries);
this.setBackpack(ItemStack.fromNbtOrEmpty(registries, nbt.getCompound(BACKPACK.key())));
}

@Override
protected void writeNbt(NbtCompound nbt) {
super.writeNbt(nbt);
nbt.put(BACKPACK, this.backpack);
protected void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) {
super.writeNbt(nbt, registries);
nbt.put(BACKPACK.key(), this.backpack.encode(registries));
}

@Override
public NbtCompound toInitialChunkDataNbt() {
var nbt = super.toInitialChunkDataNbt();
this.writeNbt(nbt);
public NbtCompound toInitialChunkDataNbt(RegistryWrapper.WrapperLookup registries) {
var nbt = super.toInitialChunkDataNbt(registries);
this.writeNbt(nbt, registries);
return nbt;
}

Expand Down Expand Up @@ -95,8 +96,8 @@ public ItemStack backpack() {
@Override
public @Nullable Object getRenderData() {
return this.backpack.getItem() instanceof BackpackItem backpackItem
? backpackItem.type.model()
: null;
? backpackItem.type.model()
: null;
}

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin;
import net.fabricmc.fabric.api.client.rendering.v1.TooltipComponentCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ingame.HandledScreens;
Expand All @@ -39,12 +39,14 @@ public class OutTheDoorClient implements ClientModInitializer {
public void onInitializeClient() {
BlockRenderLayerMap.INSTANCE.putBlock(OutTheDoorBlocks.BACKPACK, RenderLayer.getCutout());

ModelLoadingRegistry.INSTANCE.registerResourceProvider(resourceManager -> (resourceId, context) -> {
if (resourceId.equals(OutTheDoor.id("block/backpack"))) {
return new BackpackUnbakedModel();
} else {
return null;
}
ModelLoadingPlugin.register(pluginContext -> {
pluginContext.resolveModel().register(context -> {
if (OutTheDoor.id("block/backpack").equals(context.id())) {
return new BackpackUnbakedModel();
} else {
return null;
}
});
});

ClientTickEvents.END_CLIENT_TICK.register(client -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ public void setParents(Function<Identifier, UnbakedModel> modelLoader) {
});
}

@Nullable
@Override
@SuppressWarnings("DataFlowIssue")
public BakedModel bake(Baker baker, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings bakeSettings, Identifier modelId) {
public @Nullable BakedModel bake(Baker baker, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings bakeSettings) {
var models = ImmutableMap.<Identifier, BakedModel>builder();

for (var backpackType : OutTheDoor.BACKPACK_REGISTRY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

public class BackpackScreen extends HandledScreen<BackpackScreenHandler> {

public static final Identifier GENERIC_54_TEXTURE = new Identifier("textures/gui/container/generic_54.png");
public static final Identifier GENERIC_54_TEXTURE = Identifier.of("textures/gui/container/generic_54.png");

public static final int PLAYER_INVENTORY_HEIGHT = 76;
public static final int SEPARATOR_HEIGHT = 14;
Expand Down
Loading

0 comments on commit 9bf91d0

Please sign in to comment.