Skip to content

Commit

Permalink
Merge pull request #1 from dgrfps/1.20.6
Browse files Browse the repository at this point in the history
1.20.6 Porting
  • Loading branch information
daguerpedro authored Jun 16, 2024
2 parents 0622ff8 + c39c4ae commit 92b88b4
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 82 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
matrix:
# Use these Java versions
java: [
17, # Current Java LTS & minimum supported by Minecraft
21, # Current Java LTS & minimum supported by Minecraft
]
# and run on both Linux and Windows
os: [ubuntu-22.04, windows-2022]
Expand All @@ -33,7 +33,7 @@ jobs:
- name: build
run: ./gradlew build
- name: capture build artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from latest java on one OS
uses: actions/upload-artifact@v3
with:
name: Artifacts
Expand Down
36 changes: 10 additions & 26 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
}

Expand All @@ -10,12 +10,11 @@ base {
archivesName = project.archives_base_name
}

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
repositories {}

wrapper {
gradleVersion = "8.8"
distributionType = Wrapper.DistributionType.BIN
}

loom {
Expand All @@ -28,7 +27,6 @@ loom {
}
}
runs {
// This adds a new gradle task that runs the datagen API: "gradlew runDatagen"
datagen {
inherit server
name "Data Generation"
Expand All @@ -41,7 +39,6 @@ loom {
}
}

// Add the generated resources to the main source set
sourceSets {
main {
resources {
Expand All @@ -52,18 +49,11 @@ sourceSets {
}
}
dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.

// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
}

processResources {
Expand All @@ -75,17 +65,14 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 17
it.options.release = 21
}

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()

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

jar {
Expand All @@ -104,9 +91,6 @@ publishing {

// 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.

}
}
18 changes: 8 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.4
loader_version=0.14.23
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.3
loader_version=0.15.11

# Dependencies
fabric_version=0.100.0+1.20.6

# Mod Properties
mod_version=1.20.2-1.0.1
mod_version=1.20.6-1.1.0
maven_group=dgrfps.pfmc
archives_base_name=pfmc


project.ext.mod_version = modVersion


# Dependencies
fabric_version=0.90.4+1.20.2
project.ext.mod_version = modVersion
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main implements ModInitializer {
import java.util.Random;

public class PFMC implements ModInitializer {
private static final Random random = new Random();
public static final Logger LOGGER = LoggerFactory.getLogger("pfmc");
public static final String MODID = "pfmc";

public static boolean DEV = true;
public static int randRange(int min, int max)
{
return random.nextInt((max - min) + 1) + min;
}

@Override
public void onInitialize() {
ItemRegistry.Init();
LOGGER.info(MODID + " MOD LOADED.");
if(DEV)
LOGGER.warn("LOADED DEV VERSION.");
}
}
26 changes: 19 additions & 7 deletions src/main/java/dgrfps/pfmc/items/ItemRegistry.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
package dgrfps.pfmc.items;

import dgrfps.pfmc.Main;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import dgrfps.pfmc.PFMC;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.fabricmc.fabric.api.registry.CompostingChanceRegistry;
import net.minecraft.item.FoodComponents;
import net.minecraft.component.type.FoodComponent;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.item.Item.Settings;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroups;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;

import java.util.ArrayList;
import java.util.Arrays;

public class ItemRegistry {
public static final Item POOP = registerItem("poop", new PoopItem(new FabricItemSettings().food(FoodComponents.ROTTEN_FLESH)));
public static final Item POOP = registerItem("poop", new PoopItem(new Settings().food(
new FoodComponent(-1, -2, true, 1f, new ArrayList<FoodComponent.StatusEffectEntry>(Arrays.asList(
new FoodComponent.StatusEffectEntry(new StatusEffectInstance(StatusEffects.NAUSEA, 10 * 20), 1),
new FoodComponent.StatusEffectEntry(new StatusEffectInstance(StatusEffects.SLOWNESS, 10 * 20), 1),
new FoodComponent.StatusEffectEntry(new StatusEffectInstance(StatusEffects.HUNGER, 10 * 20), 1)
))
))));

public static void Init()
{
ItemGroupEvents.modifyEntriesEvent(ItemGroups.NATURAL).register((e) -> {
e.add(POOP);
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FOOD_AND_DRINK).register((itemGroupEntries) -> {
itemGroupEntries.add(POOP);
});

CompostingChanceRegistry.INSTANCE.add(POOP, 2f);
}
public static Item registerItem(String name, Item item)
{
return Registry.register(Registries.ITEM, new Identifier(Main.MODID, name), item);
return Registry.register(Registries.ITEM, new Identifier(PFMC.MODID, name), item);
}
}
18 changes: 0 additions & 18 deletions src/main/java/dgrfps/pfmc/items/PoopItem.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
package dgrfps.pfmc.items;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.SoundEvents;
import net.minecraft.world.World;

public class PoopItem extends Item {
public PoopItem(Settings settings)
{
super(settings);
}

@Override
public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) {
if (this.isFood()) {
user.playSound(SoundEvents.ENTITY_VILLAGER_NO, 1f, 1f);

user.addStatusEffect(new StatusEffectInstance(StatusEffects.NAUSEA, 3 * 20));
user.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 3 * 20, 2));

return user.eatFood(world, stack);
}
return stack;
}
}
28 changes: 21 additions & 7 deletions src/main/java/dgrfps/pfmc/mixin/PoopMixin.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package dgrfps.pfmc.mixin;

import dgrfps.pfmc.Main;
import dgrfps.pfmc.PFMC;
import dgrfps.pfmc.items.ItemRegistry;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.entity.passive.PassiveEntity;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -15,13 +14,21 @@

@Mixin(AnimalEntity.class)
public abstract class PoopMixin extends PassiveEntity {

int poop_ticks;

protected PoopMixin(EntityType<? extends PassiveEntity> entityType, World world) {
void setRandomPoopTime()
{
//2 - 10 minutes
int seconds = PFMC.randRange(2, 10) * 60; //1 minute = 60 seconds, 5 minutes = 3 * 60 seconds.

//Minecraft runs at 20 ticks per second.
this.poop_ticks = 20 * seconds;
}


protected PoopMixin(EntityType<? extends PassiveEntity> entityType, World world) {
super(entityType, world);
this.poop_ticks = random.nextInt(20 * 60 * 5) + (20 * 60);
setRandomPoopTime();
}

@Inject(method = "tickMovement()V", at = @At("TAIL"))
Expand All @@ -30,10 +37,17 @@ void shitty(CallbackInfo ci)
this.poop_ticks--;
if(this.poop_ticks <= 0)
{
this.poop_ticks = random.nextInt(20 * 60 * 5) + (20 * 60);
setRandomPoopTime();

for (int i = 0; i < random.nextBetween(0, 5); i++)
this.dropStack(ItemRegistry.POOP.getDefaultStack());
this.getWorld().addParticle(ParticleTypes.CRIT, this.getPos().x, this.getPos().y, this.getPos().z, 0, -.1, 0);

this.getWorld().addParticle(ParticleTypes.HEART, this.getPos().x, this.getPos().y, this.getPos().z, 0, -.2, 0);
this.getWorld().addParticle(ParticleTypes.HEART, this.getPos().x, this.getPos().y, this.getPos().z, -.2, -.2, 0);
this.getWorld().addParticle(ParticleTypes.HEART, this.getPos().x, this.getPos().y, this.getPos().z, +.2, -.2, 0);
this.getWorld().addParticle(ParticleTypes.HEART, this.getPos().x, this.getPos().y, this.getPos().z, 0, -.2, -.2);
this.getWorld().addParticle(ParticleTypes.HEART, this.getPos().x, this.getPos().y, this.getPos().z, 0, -.2, +.2);

}
}
}
13 changes: 7 additions & 6 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
"name": "Poop Fertilizer Minecraft",
"description": "This mod brings poop as a fertilizer to minecraft!",
"authors": [
"dgrfps"
"dgrfps",
"daguerpedro"
],
"contact": {
"sources": "https://github.com/dgrfps/"
"sources": "https://github.com/dgrfps/pfmc"
},
"license": "CC0-1.0",
"icon": "assets/pfmc/icon.png",
"environment": "*",
"entrypoints": {
"main": [
"dgrfps.pfmc.Main"
"dgrfps.pfmc.PFMC"
],
"client": [
"dgrfps.pfmc.pfmcClient"
Expand All @@ -32,9 +33,9 @@
}
],
"depends": {
"fabricloader": ">=0.14.23",
"minecraft": "~1.20.2",
"java": ">=17",
"fabricloader": ">=0.15.11",
"minecraft": "~1.20.6",
"java": ">=21",
"fabric-api": "*"
},
"suggests": {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/pfmc.mixins.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"required": true,
"package": "dgrfps.pfmc.mixin",
"compatibilityLevel": "JAVA_17",
"compatibilityLevel": "JAVA_21",
"mixins": [
"PoopMixin"
],
Expand Down

0 comments on commit 92b88b4

Please sign in to comment.