Skip to content

Commit

Permalink
Work on a possible port
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically committed Aug 10, 2021
1 parent 9337e14 commit a6435fe
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 119 deletions.
67 changes: 37 additions & 30 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugins {
id 'fabric-loom' version '0.4-SNAPSHOT'
id 'fabric-loom' version '0.8-SNAPSHOT'
id 'maven-publish'
id "com.modrinth.minotaur" version "1.1.0"
id "com.modrinth.minotaur" version "1.2.1"
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16

archivesBaseName = project.archives_base_name
version = project.mod_version
Expand All @@ -19,9 +19,10 @@ repositories {
url = "https://maven.terraformersmc.com/"
}
maven {
name = "Ladysnake Libs"
url = "https://dl.bintray.com/ladysnake/libs"
name = 'Ladysnake Mods'
url = 'https://ladysnake.jfrog.io/artifactory/mods'
}
maven { url "https://maven.shedaniel.me/" }
}

dependencies {
Expand All @@ -34,14 +35,14 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

//Config
modImplementation "me.shedaniel.cloth:config-2:${project.cloth_config_version}"
modImplementation "me.sargunvohra.mcmods:autoconfig1u:${project.auto_config_version}"
modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") {
exclude(group: "net.fabricmc.fabric-api")
}
//Compat Mods
modImplementation "io.github.prospector:modmenu:${project.mod_menu_version}"
modImplementation "com.terraformersmc:modmenu:${project.mod_menu_version}"
modImplementation "dev.emi:trinkets:${trinkets_version}"

include "me.shedaniel.cloth:config-2:${project.cloth_config_version}"
include "me.sargunvohra.mcmods:autoconfig1u:${project.auto_config_version}"
include "me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}"
}

processResources {
Expand All @@ -57,37 +58,43 @@ processResources {
}
}

// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
tasks.withType(JavaCompile).configureEach {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
// 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
}

java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}

jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
}
}


import com.modrinth.minotaur.TaskModrinthUpload

task publishModrinth (type: TaskModrinthUpload){

token = 'lol' // Use an environment property!
projectId = 'ssUbhMkL'
releaseType = 'release'
versionType = com.modrinth.minotaur.request.VersionType.RELEASE
uploadFile = remapJar // This is the java jar task
addGameVersion('1.16.2')
addGameVersion('1.17')
addLoader('fabric')
}

// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
}

jar {
from "LICENSE"
}

// configure the maven publication
publishing {
publications {
Expand Down
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/use

minecraft_version=1.16.2
yarn_mappings=1.16.2+build.47
loader_version=0.9.3+build.207
minecraft_version=1.17
yarn_mappings=1.17+build.10
loader_version=0.11.3

# Mod Properties
mod_version = v1.10
Expand All @@ -15,8 +15,8 @@ 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.20.1+build.401-1.16
cloth_config_version=4.8.1
auto_config_version=3.2.2
mod_menu_version=1.14.6+build.31
trinkets_version=2.6.7
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
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-6.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.1-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/net/guavy/gravestones/Gravestones.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.guavy.gravestones;

import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
import me.sargunvohra.mcmods.autoconfig1u.serializer.GsonConfigSerializer;
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.event.player.PlayerBlockBreakEvents;
Expand Down Expand Up @@ -58,9 +58,7 @@ public void onInitialize() {
apiMods.addAll(FabricLoader.getInstance().getEntrypoints("gravestones", GravestonesApi.class));

PlayerBlockBreakEvents.BEFORE.register((world, player, pos, state, entity) -> {
if(entity instanceof GravestoneBlockEntity) {
GravestoneBlockEntity gravestoneBlockEntity = (GravestoneBlockEntity) entity;

if(entity instanceof GravestoneBlockEntity gravestoneBlockEntity) {
if(player.hasPermissionLevel(GravestonesConfig.getConfig().mainSettings.minimumOpLevelToLoot) && gravestoneBlockEntity.getGraveOwner() != null && !gravestoneBlockEntity.getGraveOwner().getId().equals(player.getGameProfile().getId())) return true;

if(GravestonesConfig.getConfig().mainSettings.retrievalType != GravestoneRetrievalType.ON_BREAK && gravestoneBlockEntity.getGraveOwner() != null)
Expand All @@ -86,9 +84,9 @@ public static void placeGrave(World world, Vec3d pos, PlayerEntity player) {

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

combinedInventory.addAll(player.inventory.main);
combinedInventory.addAll(player.inventory.armor);
combinedInventory.addAll(player.inventory.offHand);
combinedInventory.addAll(player.getInventory().main);
combinedInventory.addAll(player.getInventory().armor);
combinedInventory.addAll(player.getInventory().offHand);

for (GravestonesApi gravestonesApi : Gravestones.apiMods) {
combinedInventory.addAll(gravestonesApi.getInventory(player));
Expand Down
21 changes: 8 additions & 13 deletions src/main/java/net/guavy/gravestones/GravestonesModMenuImpl.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
package net.guavy.gravestones;

import io.github.prospector.modmenu.api.ConfigScreenFactory;
import io.github.prospector.modmenu.api.ModMenuApi;
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import me.shedaniel.autoconfig.AutoConfig;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.guavy.gravestones.config.GravestonesConfig;
import net.minecraft.client.gui.screen.Screen;

import java.util.Optional;
import java.util.function.Supplier;

public class GravestonesModMenuImpl implements ModMenuApi {
@Override
public String getModId() {
return "gravestones";
}
@Environment(EnvType.CLIENT)
class GravestonesModMenuImpl implements ModMenuApi {

@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parent -> AutoConfig.getConfigScreen(GravestonesConfig.class, parent).get();
}
}
}
26 changes: 13 additions & 13 deletions src/main/java/net/guavy/gravestones/block/GravestoneBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

public class GravestoneBlock extends HorizontalFacingBlock implements BlockEntityProvider {

public GravestoneBlock(Settings settings) {
super(settings);
setDefaultState(this.stateManager.getDefaultState().with(Properties.HORIZONTAL_FACING, Direction.NORTH));
Expand All @@ -44,14 +44,13 @@ protected void appendProperties(StateManager.Builder<Block, BlockState> stateMan
stateManager.add(Properties.HORIZONTAL_FACING);
}

public void onSteppedOn(World world, BlockPos pos, Entity entity) {
if(GravestonesConfig.getConfig().mainSettings.retrievalType == GravestoneRetrievalType.ON_STEP && entity instanceof PlayerEntity) {
PlayerEntity playerEntity = (PlayerEntity) entity;

@Override
public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity) {
if(GravestonesConfig.getConfig().mainSettings.retrievalType == GravestoneRetrievalType.ON_STEP && entity instanceof PlayerEntity playerEntity) {
RetrieveGrave(playerEntity, world, pos);
}

super.onSteppedOn(world, pos, entity);
super.onSteppedOn(world, pos, state, entity);
}

@Override
Expand All @@ -76,8 +75,9 @@ public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos
return VoxelShapes.cuboid(0.1f, 0f, 0.1f, 0.9f, 0.3f, 0.9f);
}

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

Expand All @@ -104,15 +104,15 @@ private boolean RetrieveGrave(PlayerEntity playerEntity, World world, BlockPos p

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

retrievalInventory.addAll(playerEntity.inventory.main);
retrievalInventory.addAll(playerEntity.inventory.armor);
retrievalInventory.addAll(playerEntity.inventory.offHand);
retrievalInventory.addAll(playerEntity.getInventory().main);
retrievalInventory.addAll(playerEntity.getInventory().armor);
retrievalInventory.addAll(playerEntity.getInventory().offHand);

for (GravestonesApi gravestonesApi : Gravestones.apiMods) {
retrievalInventory.addAll(gravestonesApi.getInventory(playerEntity));
}

playerEntity.inventory.clear();
playerEntity.getInventory().clear();

if(GravestonesConfig.getConfig().mainSettings.dropType == GravestoneDropType.PUT_IN_INVENTORY) {
List<ItemStack> armor = items.subList(36, 40);
Expand Down Expand Up @@ -143,7 +143,7 @@ private boolean RetrieveGrave(PlayerEntity playerEntity, World world, BlockPos p
extraItems.add(retrievalInventory.subList(36, 40).get(i));
}

if(playerEntity.inventory.offHand.get(0) == ItemStack.EMPTY)
if(playerEntity.getInventory().offHand.get(0) == ItemStack.EMPTY)
playerEntity.equipStack(EquipmentSlot.OFFHAND, retrievalInventory.get(40));
else
extraItems.add(retrievalInventory.get(40));
Expand All @@ -152,7 +152,7 @@ private boolean RetrieveGrave(PlayerEntity playerEntity, World world, BlockPos p
if (retrievalInventory.size() > 41)
extraItems.addAll(retrievalInventory.subList(41, retrievalInventory.size()));

List<Integer> openSlots = getInventoryOpenSlots(playerEntity.inventory.main);
List<Integer> openSlots = getInventoryOpenSlots(playerEntity.getInventory().main);

for(int i = 0; i < openSlots.size(); i++) {
playerEntity.equip(openSlots.get(i), extraItems.get(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import com.mojang.authlib.GameProfile;
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.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.util.collection.DefaultedList;

Expand Down Expand Up @@ -64,12 +63,12 @@ public void setXp(int xp) {
}

@Override
public void fromTag(BlockState state, CompoundTag tag) {
super.fromTag(state, tag);
public void readNbt(NbtCompound tag) {
super.readNbt(tag);

this.items = DefaultedList.ofSize(tag.getInt("ItemCount"), ItemStack.EMPTY);

Inventories.fromTag(tag.getCompound("Items"), this.items);
Inventories.readNbt(tag.getCompound("Items"), this.items);

this.xp = tag.getInt("XP");

Expand All @@ -81,38 +80,38 @@ public void fromTag(BlockState state, CompoundTag tag) {
}

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

tag.putInt("ItemCount", this.items.size());

tag.put("Items", Inventories.toTag(new CompoundTag(), this.items, true));
tag.put("Items", Inventories.writeNbt(new NbtCompound(), this.items, true));

tag.putInt("XP", xp);

if(graveOwner != null)
tag.put("GraveOwner", NbtHelper.fromGameProfile(new CompoundTag(), graveOwner));
tag.put("GraveOwner", NbtHelper.writeGameProfile(new NbtCompound(), graveOwner));
if(customName != null && !customName.isEmpty())
tag.putString("CustomName", customName);

return tag;
}

@Override
public void fromClientTag(CompoundTag compoundTag) {
if(compoundTag.contains("GraveOwner"))
this.graveOwner = NbtHelper.toGameProfile(compoundTag.getCompound("GraveOwner"));
if(compoundTag.contains("CustomName"))
this.customName = compoundTag.getString("CustomName");
}

@Override
public CompoundTag toClientTag(CompoundTag compoundTag) {
public NbtCompound toClientTag(NbtCompound tag) {
if(graveOwner != null)
compoundTag.put("GraveOwner", NbtHelper.fromGameProfile(new CompoundTag(), this.graveOwner));
tag.put("GraveOwner", NbtHelper.writeGameProfile(new NbtCompound(), this.graveOwner));
if(customName != null && !customName.isEmpty())
compoundTag.putString("CustomName", customName);
tag.putString("CustomName", customName);

return tag;
}

return compoundTag;
@Override
public void fromClientTag(NbtCompound tag) {
if(tag.contains("GraveOwner"))
this.graveOwner = NbtHelper.toGameProfile(tag.getCompound("GraveOwner"));
if(tag.contains("CustomName"))
this.customName = tag.getString("CustomName");
}
}
Loading

0 comments on commit a6435fe

Please sign in to comment.