From 864be8645ed60311a2e5ac4b9395478682b26ed4 Mon Sep 17 00:00:00 2001 From: Carmelo Buscemi Date: Mon, 28 Feb 2022 19:38:57 +0100 Subject: [PATCH] feat: updated to MC 1.18.2 --- .gitignore | 1 + README.md | 3 +- build.gradle | 43 +++-------- gradle.properties | 10 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- src/main/java/slexom/vf/funnel/FunnelMod.java | 9 +-- .../slexom/vf/funnel/block/FunnelBlock.java | 13 +++- .../block/entity/FunnelBlockEntity.java | 73 ++++++++++++------- .../slexom/vf/funnel/screen/FunnelScreen.java | 8 +- src/main/resources/fabric.mod.json | 66 ++++++++--------- src/main/resources/funnel.accesswidener | 3 + src/main/resources/funnel.mixins.json | 11 --- 12 files changed, 118 insertions(+), 124 deletions(-) create mode 100644 src/main/resources/funnel.accesswidener delete mode 100644 src/main/resources/funnel.mixins.json diff --git a/.gitignore b/.gitignore index 09cd281..3b25af4 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ bin/ # fabric run/ +remappedSrc/ \ No newline at end of file diff --git a/README.md b/README.md index 7d492c5..0987f26 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # Funnel ![Version 1.0.0](https://img.shields.io/badge/Version-1.0.0-brightgreen) -![MC 1.16.5](https://img.shields.io/badge/Minecraft-1.16.5-blue) +![MC 1.16.5](https://img.shields.io/badge/MC-1.16.5-blue) +![MC 1.18.2](https://img.shields.io/badge/MC-1.18.2-blue) [![CurseForge Downloads](https://img.shields.io/badge/dynamic/json?logo=curseforge&color=f16436&label=CurseForge&query=%24.downloadCount&suffix=%20Downloads&url=https%3A%2F%2Faddons-ecs.forgesvc.net%2Fapi%2Fv2%2Faddon%2F447511)](https://www.curseforge.com/minecraft/mc-mods/funnel) diff --git a/build.gradle b/build.gradle index 8c07787..97ac934 100644 --- a/build.gradle +++ b/build.gradle @@ -1,15 +1,19 @@ plugins { - id 'fabric-loom' version '0.5-SNAPSHOT' + id 'fabric-loom' version '0.11.+' id 'maven-publish' } -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 +version = "${project.mod_version}+${project.minecraft_version}" group = project.maven_group +loom { + accessWidenerPath = file("src/main/resources/funnel.accesswidener") +} + repositories { // Add repositories to retrieve artifacts from in here. // You should only use this when depending on other mods because @@ -46,13 +50,8 @@ tasks.withType(JavaCompile).configureEach { // If Javadoc is generated, this must be specified in that task too. it.options.encoding = "UTF-8" - // The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too - // JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used. - // We'll use that if it's available, but otherwise we'll use the older option. - def targetVersion = 8 - if (JavaVersion.current().isJava9Compatible()) { - it.options.release = targetVersion - } + // Minecraft 1.17 (21w19a) upwards uses Java 16. + it.options.release = 16 } java { @@ -68,25 +67,3 @@ jar { } } -// configure the maven publication -publishing { - publications { - mavenJava(MavenPublication) { - // add all the jars that should be included when publishing to maven - artifact(remapJar) { - builtBy remapJar - } - artifact(sourcesJar) { - builtBy remapSourcesJar - } - } - } - - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. - // Notice: This block does NOT have the same function as the block in the top level. - // The repositories here will be used for publishing your artifact, not for - // retrieving dependencies. - } -} diff --git a/gradle.properties b/gradle.properties index 8b1abab..618178f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,14 +1,14 @@ # Done to increase the memory available to gradle. -org.gradle.jvmargs=-Xmx1G +org.gradle.jvmargs=-Xmx2G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=1.16.5 -yarn_mappings=1.16.5+build.4 -loader_version=0.11.1 +minecraft_version=1.18.2 +yarn_mappings=1.18.2+build.1 +loader_version=0.13.3 # Mod Properties mod_version=1.0.0 maven_group=slexom.vf archives_base_name=funnel # 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.30.3+1.16 +fabric_version=0.47.8+1.18.2 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index da9702f..2e6e589 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/slexom/vf/funnel/FunnelMod.java b/src/main/java/slexom/vf/funnel/FunnelMod.java index dca1484..ab99692 100644 --- a/src/main/java/slexom/vf/funnel/FunnelMod.java +++ b/src/main/java/slexom/vf/funnel/FunnelMod.java @@ -13,9 +13,8 @@ import net.minecraft.sound.BlockSoundGroup; import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import net.minecraft.util.registry.Registry;import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import slexom.vf.funnel.block.FunnelBlock; import slexom.vf.funnel.block.entity.FunnelBlockEntity; import slexom.vf.funnel.screen.FunnelScreenHandler; @@ -23,7 +22,7 @@ public class FunnelMod implements ModInitializer { public static final String MOD_ID = "funnel"; - public static final Logger LOGGER = LogManager.getLogger("Funnel"); + public static final Logger LOGGER = LoggerFactory.getLogger("Funnel"); public final Identifier REGISTRY_NAME = new Identifier(FunnelMod.MOD_ID, "funnel"); public static Block FUNNEL_BLOCK; @@ -37,7 +36,7 @@ public void onInitialize() { FUNNEL_BLOCK = Registry.register(Registry.BLOCK, REGISTRY_NAME, new FunnelBlock(AbstractBlock.Settings.of(Material.METAL).sounds(BlockSoundGroup.METAL).strength(0.2F).nonOpaque())); FUNNEL_BLOCK_ITEM = Registry.register(Registry.ITEM, REGISTRY_NAME, new BlockItem(FUNNEL_BLOCK, new FabricItemSettings().group(ItemGroup.MISC))); FUNNEL_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE, REGISTRY_NAME, BlockEntityType.Builder.create(FunnelBlockEntity::new, FUNNEL_BLOCK).build(null)); - LOGGER.info("[Animal Feeding Trough] Load Complete! Enjoy :D"); + LOGGER.info("[Funnel] Load Complete! Enjoy :D"); } } diff --git a/src/main/java/slexom/vf/funnel/block/FunnelBlock.java b/src/main/java/slexom/vf/funnel/block/FunnelBlock.java index 382612f..00f3475 100644 --- a/src/main/java/slexom/vf/funnel/block/FunnelBlock.java +++ b/src/main/java/slexom/vf/funnel/block/FunnelBlock.java @@ -1,8 +1,7 @@ package slexom.vf.funnel.block; import net.minecraft.block.*; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.Hopper; +import net.minecraft.block.entity.*; import net.minecraft.entity.ai.pathing.NavigationType; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.screen.NamedScreenHandlerFactory; @@ -21,6 +20,7 @@ import net.minecraft.world.BlockView; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; +import slexom.vf.funnel.FunnelMod; import slexom.vf.funnel.block.entity.FunnelBlockEntity; public class FunnelBlock extends BlockWithEntity { @@ -51,8 +51,8 @@ public VoxelShape getRaycastShape(BlockState state, BlockView world, BlockPos po @Nullable @Override - public BlockEntity createBlockEntity(BlockView world) { - return new FunnelBlockEntity(); + public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + return new FunnelBlockEntity(pos, state); } @Override @@ -129,4 +129,9 @@ public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos po return false; } + @Nullable + public BlockEntityTicker getTicker(World world, BlockState state, BlockEntityType type) { + return world.isClient ? null : checkType(type, FunnelMod.FUNNEL_BLOCK_ENTITY, FunnelBlockEntity::serverTick); + } + } \ No newline at end of file diff --git a/src/main/java/slexom/vf/funnel/block/entity/FunnelBlockEntity.java b/src/main/java/slexom/vf/funnel/block/entity/FunnelBlockEntity.java index 2909d4f..538d1f9 100644 --- a/src/main/java/slexom/vf/funnel/block/entity/FunnelBlockEntity.java +++ b/src/main/java/slexom/vf/funnel/block/entity/FunnelBlockEntity.java @@ -2,64 +2,82 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.block.entity.LootableContainerBlockEntity; import net.minecraft.entity.ItemEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.Inventories; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtCompound; import net.minecraft.screen.NamedScreenHandlerFactory; import net.minecraft.screen.ScreenHandler; import net.minecraft.text.Text; import net.minecraft.text.TranslatableText; -import net.minecraft.util.Tickable; import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; import slexom.vf.funnel.FunnelMod; import slexom.vf.funnel.block.FunnelBlock; import slexom.vf.funnel.inventory.BlockEntityInventory; import slexom.vf.funnel.screen.FunnelScreenHandler; -public class FunnelBlockEntity extends BlockEntity implements NamedScreenHandlerFactory, BlockEntityInventory, Tickable { - private final DefaultedList inventory = DefaultedList.ofSize(5, ItemStack.EMPTY); +public class FunnelBlockEntity extends LootableContainerBlockEntity implements NamedScreenHandlerFactory, BlockEntityInventory { + private DefaultedList inventory = DefaultedList.ofSize(5, ItemStack.EMPTY); private int cooldown; - public FunnelBlockEntity(BlockEntityType type) { - super(type); + public FunnelBlockEntity(BlockPos pos, BlockState state) { + super(FunnelMod.FUNNEL_BLOCK_ENTITY, pos, state); this.cooldown = 6; } - public FunnelBlockEntity() { - this(FunnelMod.FUNNEL_BLOCK_ENTITY); + public void readNbt(NbtCompound nbt) { + super.readNbt(nbt); + if (!this.deserializeLootTable(nbt)) { + Inventories.readNbt(nbt, this.inventory); + } + this.cooldown = nbt.getInt("Cooldown"); } - public void fromTag(BlockState state, CompoundTag tag) { - super.fromTag(state, tag); - Inventories.fromTag(tag, this.inventory); - this.cooldown = tag.getInt("Cooldown"); + public void writeNbt(NbtCompound nbt) { + super.writeNbt(nbt); + if (!this.serializeLootTable(nbt)) { + Inventories.writeNbt(nbt, this.inventory); + } + nbt.putInt("Cooldown", this.cooldown); } - public CompoundTag toTag(CompoundTag tag) { - super.toTag(tag); - Inventories.toTag(tag, this.inventory); - tag.putInt("Cooldown", this.cooldown); - return tag; + @Override + public Text getDisplayName() { + return new TranslatableText(getCachedState().getBlock().getTranslationKey()); } @Override - public Text getDisplayName() { + protected Text getContainerName() { return new TranslatableText(getCachedState().getBlock().getTranslationKey()); } + @Override + protected DefaultedList getInvStackList() { + return this.inventory; + } + + @Override + protected void setInvStackList(DefaultedList list) { + this.inventory = list; + } + @Nullable @Override public ScreenHandler createMenu(int syncId, PlayerInventory playerInventory, PlayerEntity player) { return new FunnelScreenHandler(syncId, playerInventory, this); } + @Override + protected ScreenHandler createScreenHandler(int syncId, PlayerInventory playerInventory) { + return null; + } + @Override public DefaultedList getItems() { return inventory; @@ -85,14 +103,13 @@ private boolean canDropItem() { return this.haveItems() && this.isEnabled() && this.haveSpace(); } - @Override - public void tick() { - if (this.world != null && !this.world.isClient()) { - --this.cooldown; - if (this.cooldown == 0) { - this.cooldown = 8; - if (this.canDropItem()) { - ItemStack itemStack = removeStack(0, 1); + public static void serverTick(World world, BlockPos pos, BlockState state, FunnelBlockEntity blockEntity) { + if (world != null && !world.isClient()) { + --blockEntity.cooldown; + if (blockEntity.cooldown == 0) { + blockEntity.cooldown = 8; + if (blockEntity.canDropItem()) { + ItemStack itemStack = blockEntity.removeStack(0, 1); ItemEntity entity = new ItemEntity(world, pos.getX() + 0.5, pos.getY() - 0.5, pos.getZ() + 0.5, itemStack.copy()); entity.setVelocity(0, 0, 0); world.spawnEntity(entity); diff --git a/src/main/java/slexom/vf/funnel/screen/FunnelScreen.java b/src/main/java/slexom/vf/funnel/screen/FunnelScreen.java index 3588dff..239af84 100644 --- a/src/main/java/slexom/vf/funnel/screen/FunnelScreen.java +++ b/src/main/java/slexom/vf/funnel/screen/FunnelScreen.java @@ -2,6 +2,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.gui.screen.ingame.HandledScreen; +import net.minecraft.client.render.GameRenderer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.screen.ScreenHandler; @@ -19,11 +20,12 @@ public FunnelScreen(ScreenHandler handler, PlayerInventory inventory, Text title @Override protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) { - RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - client.getTextureManager().bindTexture(TEXTURE); + RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + RenderSystem.setShaderTexture(0, TEXTURE); int x = (width - backgroundWidth) / 2; int y = (height - backgroundHeight) / 2; - drawTexture(matrices, x, y, 0, 0, backgroundWidth, backgroundHeight); + drawTexture(matrices, x, y, 0, 0, this.backgroundWidth, this.backgroundHeight); } @Override diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index cbf7e34..453a850 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,36 +1,36 @@ { - "schemaVersion": 1, - "id": "funnel", - "version": "${version}", - "name": "Funnel", - "description": "A funnel that drop items below it.", - "authors": [ - "Slexom" + "schemaVersion": 1, + "id": "funnel", + "version": "${version}", + "name": "Funnel", + "description": "A funnel that drop items below it.", + "authors": [ + "Slexom" + ], + "contact": { + "homepage": "https://github.com/Slexom/funnel", + "sources": "https://github.com/Slexom/funnel" + }, + "license": "CC0-1.0", + "icon": "assets/funnel/icon.png", + "environment": "*", + "entrypoints": { + "main": [ + "slexom.vf.funnel.FunnelMod" ], - "contact": { - "homepage": "https://github.com/Slexom/funnel", - "sources": "https://github.com/Slexom/funnel" - }, - "license": "CC0-1.0", - "icon": "assets/funnel/icon.png", - "environment": "*", - "entrypoints": { - "main": [ - "slexom.vf.funnel.FunnelMod" - ], - "client": [ - "slexom.vf.funnel.FunnelClientMod" - ] - }, - "mixins": [ - "funnel.mixins.json" - ], - "depends": { - "fabricloader": ">=0.7.4", - "fabric": "*", - "minecraft": "1.16.x" - }, - "suggests": { - "another-mod": "*" - } + "client": [ + "slexom.vf.funnel.FunnelClientMod" + ] + }, + "mixins": [ + ], + "depends": { + "fabricloader": ">=0.13.3", + "fabric": "*", + "minecraft": "1.18.x", + "java": ">=17" + }, + "suggests": { + }, + "accessWidener": "funnel.accesswidener" } diff --git a/src/main/resources/funnel.accesswidener b/src/main/resources/funnel.accesswidener new file mode 100644 index 0000000..9c575f4 --- /dev/null +++ b/src/main/resources/funnel.accesswidener @@ -0,0 +1,3 @@ +accessWidener v1 named + +accessible class net/minecraft/block/entity/BlockEntityType$BlockEntityFactory diff --git a/src/main/resources/funnel.mixins.json b/src/main/resources/funnel.mixins.json deleted file mode 100644 index 35cc4cb..0000000 --- a/src/main/resources/funnel.mixins.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "slexom.vf.funnel.mixin", - "compatibilityLevel": "JAVA_8", - "mixins": [], - "client": [], - "injectors": { - "defaultRequire": 1 - } -}