Skip to content

Commit

Permalink
Port to 1.18.2
Browse files Browse the repository at this point in the history
Fixed an issue whereModMenu add-ons could not be accessed
  • Loading branch information
PTOM76 committed Apr 10, 2022
1 parent a6435fe commit 9052c50
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 74 deletions.
19 changes: 7 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugins {
id 'fabric-loom' version '0.8-SNAPSHOT'
id 'fabric-loom' version '0.11-SNAPSHOT'
id 'maven-publish'
id "com.modrinth.minotaur" version "1.2.1"
}

sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

archivesBaseName = project.archives_base_name
version = project.mod_version
Expand Down Expand Up @@ -48,14 +48,9 @@ dependencies {
processResources {
inputs.property "version", project.version

from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
filesMatching("fabric.mod.json") {
expand "version": project.version
}

from(sourceSets.main.resources.srcDirs) {
exclude "fabric.mod.json"
}
}

tasks.withType(JavaCompile).configureEach {
Expand All @@ -65,8 +60,8 @@ tasks.withType(JavaCompile).configureEach {
// If Javadoc is generated, this must be specified in that task too.
it.options.encoding = "UTF-8"

// Minecraft 1.17 (21w19a) upwards uses Java 16.
it.options.release = 16
// Minecraft 1.18 upwards uses Java 17.
it.options.release = 17
}

java {
Expand All @@ -91,7 +86,7 @@ task publishModrinth (type: TaskModrinthUpload){
projectId = 'ssUbhMkL'
versionType = com.modrinth.minotaur.request.VersionType.RELEASE
uploadFile = remapJar // This is the java jar task
addGameVersion('1.17')
addGameVersion('1.18.2')
addLoader('fabric')
}

Expand Down
20 changes: 10 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.jvmargs=-Xmx3G

# Fabric Properties
# check these on https://fabricmc.net/use

minecraft_version=1.17
yarn_mappings=1.17+build.10
loader_version=0.11.3
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.2
loader_version=0.13.3

# Mod Properties
mod_version = v1.10
mod_version = v1.11
maven_group = net.guavy
archives_base_name = gravestones

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.35.1+1.17
cloth_config_version=5.0.34
auto_config_version=3.3.1
mod_menu_version=2.0.2
trinkets_version=3.0.0
fabric_version=0.48.0+1.18.2
cloth_config_version=6.2.57
auto_config_version=3.4.0
mod_menu_version=3.1.0
trinkets_version=3.3.0
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 @@
#Sun Jun 21 15:11:58 MST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Expand Down
26 changes: 14 additions & 12 deletions src/main/java/net/guavy/gravestones/Gravestones.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.GsonConfigSerializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
//import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.fabricmc.loader.api.FabricLoader;
import net.guavy.gravestones.api.GravestonesApi;
import net.guavy.gravestones.block.GravestoneBlock;
Expand Down Expand Up @@ -39,15 +41,15 @@

public class Gravestones implements ModInitializer {

public static final GravestoneBlock GRAVESTONE = new GravestoneBlock(FabricBlockSettings.of(Material.ORGANIC_PRODUCT).strength(0.8f, -1f).build());
public static final GravestoneBlock GRAVESTONE = new GravestoneBlock(FabricBlockSettings.of(Material.ORGANIC_PRODUCT).strength(0.8f, -1f));
public static BlockEntityType<GravestoneBlockEntity> GRAVESTONE_BLOCK_ENTITY;

public static final ArrayList<GravestonesApi> apiMods = new ArrayList<>();

@Override
public void onInitialize() {
Registry.register(Registry.BLOCK, new Identifier("gravestones", "gravestone"), GRAVESTONE);
GRAVESTONE_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE, "gravestones:gravestone", BlockEntityType.Builder.create(GravestoneBlockEntity::new, GRAVESTONE).build(null));
GRAVESTONE_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE, "gravestones:gravestone", FabricBlockEntityTypeBuilder.create(GravestoneBlockEntity::new, GRAVESTONE).build(null));
Registry.register(Registry.ITEM, new Identifier("gravestones", "gravestone"), new BlockItem(GRAVESTONE, new Item.Settings().group(ItemGroup.DECORATIONS)));

AutoConfig.register(GravestonesConfig.class, GsonConfigSerializer::new);
Expand Down Expand Up @@ -80,7 +82,6 @@ public static void placeGrave(World world, Vec3d pos, PlayerEntity player) {
BlockState blockState = world.getBlockState(blockPos);
Block block = blockState.getBlock();

GravestoneBlockEntity gravestoneBlockEntity = new GravestoneBlockEntity();

DefaultedList<ItemStack> combinedInventory = DefaultedList.of();

Expand All @@ -92,10 +93,6 @@ public static void placeGrave(World world, Vec3d pos, PlayerEntity player) {
combinedInventory.addAll(gravestonesApi.getInventory(player));
}

gravestoneBlockEntity.setItems(combinedInventory);
gravestoneBlockEntity.setGraveOwner(player.getGameProfile());
gravestoneBlockEntity.setXp(player.totalExperience);

player.totalExperience = 0;
player.experienceProgress = 0;
player.experienceLevel = 0;
Expand All @@ -106,10 +103,15 @@ public static void placeGrave(World world, Vec3d pos, PlayerEntity player) {

for (BlockPos gravePos : BlockPos.iterateOutwards(blockPos.add(new Vec3i(0, 1, 0)), 5, 5, 5)) {
if(canPlaceGravestone(world, block, gravePos)) {
world.setBlockState(gravePos, Gravestones.GRAVESTONE.getDefaultState().with(Properties.HORIZONTAL_FACING, player.getHorizontalFacing()));
world.setBlockEntity(gravePos, gravestoneBlockEntity);

gravestoneBlockEntity.sync();
BlockState graveState = Gravestones.GRAVESTONE.getDefaultState().with(Properties.HORIZONTAL_FACING, player.getHorizontalFacing());
world.setBlockState(gravePos, graveState);
GravestoneBlockEntity gravestoneBlockEntity = new GravestoneBlockEntity(gravePos, graveState);
gravestoneBlockEntity.setItems(combinedInventory);
gravestoneBlockEntity.setGraveOwner(player.getGameProfile());
gravestoneBlockEntity.setXp(player.totalExperience);
world.addBlockEntity(gravestoneBlockEntity);

gravestoneBlockEntity.markDirty();
block.onBreak(world, blockPos, blockState, player);

if (GravestonesConfig.getConfig().mainSettings.sendGraveCoordinates) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.guavy.gravestones.config.GravestonesConfig;

@Environment(EnvType.CLIENT)
class GravestonesModMenuImpl implements ModMenuApi {
public class GravestonesModMenuImpl implements ModMenuApi {

@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/guavy/gravestones/block/GravestoneBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos
@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new GravestoneBlockEntity();
return new GravestoneBlockEntity(pos, state);
}

private boolean RetrieveGrave(PlayerEntity playerEntity, World world, BlockPos pos) {
Expand All @@ -89,7 +89,7 @@ private boolean RetrieveGrave(PlayerEntity playerEntity, World world, BlockPos p
if(!(be instanceof GravestoneBlockEntity)) return false;
GravestoneBlockEntity blockEntity = (GravestoneBlockEntity) be;

blockEntity.sync();
blockEntity.markDirty();

if(blockEntity.getItems() == null) return false;
if(blockEntity.getGraveOwner() == null) return false;
Expand Down Expand Up @@ -128,12 +128,12 @@ private boolean RetrieveGrave(PlayerEntity playerEntity, World world, BlockPos p
List<ItemStack> mainInventory = items.subList(0, 36);

for (int i = 0; i < mainInventory.size(); i++) {
playerEntity.equip(i, mainInventory.get(i));
playerEntity.getInventory().insertStack(i, mainInventory.get(i));
}

DefaultedList<ItemStack> extraItems = DefaultedList.of();

List<Integer> openArmorSlots = getInventoryOpenSlots(playerEntity.inventory.armor);
List<Integer> openArmorSlots = getInventoryOpenSlots(playerEntity.getInventory().armor);

for(int i = 0; i < 4; i++) {
if(openArmorSlots.contains(i)) {
Expand All @@ -155,7 +155,7 @@ private boolean RetrieveGrave(PlayerEntity playerEntity, World world, BlockPos p
List<Integer> openSlots = getInventoryOpenSlots(playerEntity.getInventory().main);

for(int i = 0; i < openSlots.size(); i++) {
playerEntity.equip(openSlots.get(i), extraItems.get(i));
playerEntity.getInventory().insertStack(openSlots.get(i), extraItems.get(i));
}

DefaultedList<ItemStack> dropItems = DefaultedList.of();
Expand Down Expand Up @@ -203,7 +203,7 @@ public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity p

GravestoneBlockEntity gravestoneBlockEntity = (GravestoneBlockEntity) blockEntity;

gravestoneBlockEntity.setCustomName(itemStack.getOrCreateSubTag("display").getString("Name"));
gravestoneBlockEntity.setCustomName(itemStack.getOrCreateSubNbt("display").getString("Name"));
}

public BlockState getPlacementState(ItemPlacementContext ctx) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
package net.guavy.gravestones.block.entity;

import com.mojang.authlib.GameProfile;
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
//import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
import net.guavy.gravestones.Gravestones;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.inventory.Inventories;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.network.Packet;
import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;

public class GravestoneBlockEntity extends BlockEntity implements BlockEntityClientSerializable {
import javax.annotation.Nullable;

public class GravestoneBlockEntity extends BlockEntity {
// implements BlockEntityClientSerializable {
private DefaultedList<ItemStack> items;
private int xp;
private GameProfile graveOwner;
private String customName;

public GravestoneBlockEntity() {
super(Gravestones.GRAVESTONE_BLOCK_ENTITY);
public GravestoneBlockEntity(BlockPos pos, BlockState state) {
super(Gravestones.GRAVESTONE_BLOCK_ENTITY, pos, state);

this.customName = "";
this.graveOwner = null;
Expand Down Expand Up @@ -80,7 +88,7 @@ public void readNbt(NbtCompound tag) {
}

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

tag.putInt("ItemCount", this.items.size());
Expand All @@ -93,10 +101,19 @@ public NbtCompound writeNbt(NbtCompound tag) {
tag.put("GraveOwner", NbtHelper.writeGameProfile(new NbtCompound(), graveOwner));
if(customName != null && !customName.isEmpty())
tag.putString("CustomName", customName);
}

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

@Override
public NbtCompound toInitialChunkDataNbt() {
return createNbt();
}
/*
@Override
public NbtCompound toClientTag(NbtCompound tag) {
if(graveOwner != null)
Expand All @@ -114,4 +131,5 @@ public void fromClientTag(NbtCompound tag) {
if(tag.contains("CustomName"))
this.customName = tag.getString("CustomName");
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.gui.registry.GuiRegistry;
import me.shedaniel.autoconfig.util.Utils;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.rendereregistry.v1.BlockEntityRendererRegistry;
Expand Down
Loading

0 comments on commit 9052c50

Please sign in to comment.