Skip to content

Commit

Permalink
1.18 initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
RLLD576 committed Sep 10, 2023
1 parent a511460 commit 414c80d
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 13 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
plugins {
id 'fabric-loom' version '0.10-SNAPSHOT'
id 'fabric-loom' version '1.3-SNAPSHOT'
id 'maven-publish'
}

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 @@ -37,7 +37,7 @@ processResources {

tasks.withType(JavaCompile).configureEach {
// Minecraft 1.17 (21w19a) upwards uses Java 16.
it.options.release = 16
it.options.release = 17
}

java {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=1.17.1
yarn_mappings=1.17.1+build.14
loader_version=0.11.6
carpet_core_version=1.4.44+v210714
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.4
loader_version=0.14.22
carpet_core_version=1.4.69+v220331

# Mod Properties
mod_version = 1.0.0
maven_group = net.rober
archives_base_name = rober-carpet

# Dependencies
fabric_version=0.42.1+1.17
fabric_version=0.76.0+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-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
31 changes: 31 additions & 0 deletions remappedSrc/net/rober/robercarpet/RoberCarpet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.rober.robercarpet;

import carpet.CarpetExtension;
import carpet.CarpetServer;
import carpet.settings.SettingsManager;
import net.fabricmc.api.ModInitializer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class RoberCarpet implements ModInitializer, CarpetExtension {
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final String MODID = "robercarpet";
public static final Logger LOGGER = LogManager.getLogger(MODID);

private static final SettingsManager mySettingManager = new SettingsManager("1.0.0", MODID,"Rober-Carpet");

@Override
public void onInitialize() {
// This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.
RoberCarpet extension = new RoberCarpet();
CarpetServer.manageExtension(extension);
}
@Override
public void onGameStarted(){
CarpetServer.settingsManager.parseSettingsClass(RoberCarpetSettings.class);
}
}
14 changes: 14 additions & 0 deletions remappedSrc/net/rober/robercarpet/RoberCarpetSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.rober.robercarpet;

import carpet.settings.Rule;

public class RoberCarpetSettings {
@Rule(desc="Lets dispensers convert dirt into clay with water bottles", category = {"dispenser", "rober"})
public static boolean FarmableClay = false;

@Rule(desc="Sets the game-ticks of delay when you sleep in a bed (Vanilla is 100)",category = "rober")
public static int SleepingDelay = 100;

@Rule(desc="The amount of ticks before thunderstorm that are needed for the mod to warn you about it",category = "rober")
public static int ThunderWarn = 0;
}
45 changes: 45 additions & 0 deletions remappedSrc/net/rober/robercarpet/mixin/FarmableClayMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package net.rober.robercarpet.mixin;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.dispenser.ItemDispenserBehavior;
import net.minecraft.block.entity.DispenserBlockEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.rober.robercarpet.RoberCarpetSettings;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ItemDispenserBehavior.class)
public abstract class FarmableClayMixin {
@Inject( method = "dispenseSilently", at = @At("HEAD"),cancellable = true)
public void BehaviorMixin(BlockPointer pointer, ItemStack stack, CallbackInfoReturnable<ItemStack> cir) {
if(RoberCarpetSettings.FarmableClay) {
World world = pointer.getWorld();
if (world.isClient) {
return;
}
if (pointer.getBlockState().getBlock() != Blocks.DISPENSER) {
return;
}
BlockPos targetPos = pointer.getPos().offset(pointer.getBlockState().get(DispenserBlock.FACING));
BlockState block_state = world.getBlockState(targetPos);
Block block = block_state.getBlock();
Item item = stack.getItem();
if (item == Items.POTION && block == Blocks.DIRT) {
world.setBlockState(targetPos, Blocks.CLAY.getDefaultState());
cir.setReturnValue(new ItemStack(Items.GLASS_BOTTLE, 1));
return;
}
}
return;
}
}
17 changes: 17 additions & 0 deletions remappedSrc/net/rober/robercarpet/mixin/SleepingDelayMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.rober.robercarpet.mixin;

import net.minecraft.entity.player.PlayerEntity;
import net.rober.robercarpet.RoberCarpetSettings;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(PlayerEntity.class)
public abstract class SleepingDelayMixin {
@ModifyConstant(method = "isSleepingLongEnough",constant = @Constant(intValue = 100))
public int SleepingDelayMixin(int a){
return RoberCarpetSettings.SleepingDelay;
}
}
49 changes: 49 additions & 0 deletions remappedSrc/net/rober/robercarpet/mixin/ThunderWarnMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package net.rober.robercarpet.mixin;

import net.minecraft.network.MessageType;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.world.MutableWorldProperties;
import net.minecraft.world.World;
import net.minecraft.world.WorldProperties;
import net.minecraft.world.level.ServerWorldProperties;
import net.rober.robercarpet.RoberCarpetSettings;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.function.BooleanSupplier;

@Mixin(ServerWorld.class)
public abstract class ThunderWarnMixin {
@Shadow protected ServerWorldProperties worldProperties;
@Inject(method = "tick",at=@At("TAIL"))
private void tickMixin(BooleanSupplier shouldKeepTicking,CallbackInfo ci){
if(RoberCarpetSettings.ThunderWarn!=-1) {
ServerWorld server = (ServerWorld) (Object) this;
if((willBeThunderstorm(RoberCarpetSettings.ThunderWarn,worldProperties))){
for (ServerPlayerEntity player : server.getPlayers()){
player.sendMessage(new LiteralText("A storm will begin in "+RoberCarpetSettings.ThunderWarn/60+" minutes"), MessageType.CHAT,player.getUuid());
}
}
}
}
boolean willBeThunderstorm(int delay,ServerWorldProperties worldProperties){
int thunderTime = worldProperties.getThunderTime();
int rainTime = worldProperties.getRainTime();
boolean thundering = worldProperties.isThundering();
boolean raining = worldProperties.isRaining();
if(thunderTime==delay){
return raining == rainTime > delay;
}else if(rainTime==delay){
return thundering == thunderTime > delay;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@Mixin(PlayerEntity.class)
public abstract class SleepingDelayMixin {
@ModifyConstant(method = "isSleepingLongEnough",constant = @Constant(intValue = 100))
@ModifyConstant(method = "canResetTimeBySleeping",constant = @Constant(intValue = 100))
public int SleepingDelayMixin(int a){
return RoberCarpetSettings.SleepingDelay;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"depends": {
"fabricloader": ">=0.11.3",
"fabric": "*",
"minecraft": "1.17.x",
"java": ">=16"
"minecraft": "1.18.x",
"java": ">=17"
},
"suggests": {
"another-mod": "*"
Expand Down

0 comments on commit 414c80d

Please sign in to comment.