Skip to content

Commit

Permalink
feat: updated to MC 1.18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Slexom committed Feb 28, 2022
1 parent f8aa364 commit 864be86
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 124 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ bin/
# fabric

run/
remappedSrc/
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
43 changes: 10 additions & 33 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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.
}
}
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
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-6.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
9 changes: 4 additions & 5 deletions src/main/java/slexom/vf/funnel/FunnelMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
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;

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;
Expand All @@ -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");
}

}
13 changes: 9 additions & 4 deletions src/main/java/slexom/vf/funnel/block/FunnelBlock.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -129,4 +129,9 @@ public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos po
return false;
}

@Nullable
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
return world.isClient ? null : checkType(type, FunnelMod.FUNNEL_BLOCK_ENTITY, FunnelBlockEntity::serverTick);
}

}
73 changes: 45 additions & 28 deletions src/main/java/slexom/vf/funnel/block/entity/FunnelBlockEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemStack> inventory = DefaultedList.ofSize(5, ItemStack.EMPTY);
public class FunnelBlockEntity extends LootableContainerBlockEntity implements NamedScreenHandlerFactory, BlockEntityInventory {
private DefaultedList<ItemStack> 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<ItemStack> getInvStackList() {
return this.inventory;
}

@Override
protected void setInvStackList(DefaultedList<ItemStack> 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<ItemStack> getItems() {
return inventory;
Expand All @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/slexom/vf/funnel/screen/FunnelScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
66 changes: 33 additions & 33 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -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"
}
Loading

0 comments on commit 864be86

Please sign in to comment.