Skip to content

Commit

Permalink
1.17.x-1.20.x support
Browse files Browse the repository at this point in the history
  • Loading branch information
JoakimThorsen committed Dec 26, 2023
1 parent 4cd2ccb commit cdaae63
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 51 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ preprocess {
def mc117 = createNode('1.17.1' , 1_17_01, 'yarn')
def mc118 = createNode('1.18.2' , 1_18_02, 'yarn')
def mc119 = createNode('1.19.4' , 1_19_04, 'yarn')
def mc120 = createNode('1.20.2' , 1_20_04, 'yarn')
def mc120 = createNode('1.20.2' , 1_20_02, 'yarn')

mc115.link(mc114, null)
mc115.link(mc116, null)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Mod Properties
mod_id=joacarpet
mod_name=JoaCarpet
mod_version=1.0.0
mod_version=2.0.0
maven_group=me.fallenbreath
archives_base_name=joacarpet

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/joacarpet/HelloWorldTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@
import net.fabricmc.loader.api.metadata.ModMetadata;

//#if MC >= 11800
import com.mojang.logging.LogUtils;
import org.slf4j.Logger;
//$$ import com.mojang.logging.LogUtils;
//$$ import org.slf4j.Logger;
//#else
//$$ import org.apache.logging.log4j.LogManager;
//$$ import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
//#endif

public class HelloWorldTemplate implements ModInitializer
{
public static final Logger LOGGER =
//#if MC >= 11800
LogUtils.getLogger();
//$$ LogUtils.getLogger();
//#else
//$$ LogManager.getLogger();
LogManager.getLogger();
//#endif

public static final String MOD_ID = "com/joacarpet";
public static String MOD_VERSION = "b2.0.0";
public static String MOD_VERSION = "2.0.0";
public static String MOD_NAME = "JoaCarpet";

@Override
Expand Down
12 changes: 3 additions & 9 deletions src/main/java/com/joacarpet/InsaneBehaviors.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,17 @@ public static Vec3 mapUnitVelocityToVec3(ArrayList<Float> velocity, int factor,
public static int resetCounterAndResolution(CommandSourceStack c) {
counter = 0;
resolution = 2;
if(c.getPlayer() != null) {
Messenger.m(c.getPlayer(), "w Reset.");
}
JoaCarpetMod.messagePlayerIfExists(c, "w Reset.");
return 1;
}
public static int getState(CommandSourceStack c) {
if(c.getPlayer() != null) {
Messenger.m(c.getPlayer(), "w Current state: Resolution=" + resolution + ", Counter=" + counter);
}
JoaCarpetMod.messagePlayerIfExists(c, "w Current state: Resolution=" + resolution + ", Counter=" + counter);
return 1;
}
public static int setState(CommandSourceStack c, int _resolution, int _counter) {
resolution = _resolution;
counter = _counter;
if(c.getPlayer() != null) {
Messenger.m(c.getPlayer(), "w Updated resolution and counter: Resolution=" + resolution + ", Counter=" + counter);
}
JoaCarpetMod.messagePlayerIfExists(c, "w Updated resolution and counter: Resolution=" + resolution + ", Counter=" + counter);
return 1;
}
}
49 changes: 42 additions & 7 deletions src/main/java/com/joacarpet/JoaCarpetMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,38 @@

import carpet.CarpetExtension;
import carpet.CarpetServer;
import carpet.utils.Messenger;
import carpet.utils.Translations;
import com.joacarpet.commands.InsaneBehaviorsCommand;
import com.mojang.brigadier.CommandDispatcher;
import net.fabricmc.api.ModInitializer;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import java.util.Map;



//#if MC >= 11900
//$$ import net.minecraft.commands.CommandBuildContext;
//#endif
//#if MC >= 11800
//$$ import org.slf4j.Logger;
//$$ import org.slf4j.LoggerFactory;
//#else
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
//#endif


public class JoaCarpetMod implements ModInitializer, CarpetExtension {
public static final Logger LOGGER = LoggerFactory.getLogger("joacarpet");
public static final Logger LOGGER =
//#if MC >= 11800
//$$ LoggerFactory.getLogger("joacarpet");
//#else
LogManager.getLogger("joacarpet");
//#endif


@Override
public void onInitialize() {}
Expand All @@ -44,8 +63,11 @@ public void onInitialize() {}
}

@Override
public void registerCommands(CommandDispatcher<CommandSourceStack> dispatcher,
final CommandBuildContext commandBuildContext) {
public void registerCommands(CommandDispatcher<CommandSourceStack> dispatcher
//#if MC >= 11900
//$$ , final CommandBuildContext commandBuildContext
//#endif
) {
InsaneBehaviorsCommand.register(dispatcher);
}

Expand All @@ -63,4 +85,17 @@ public String version() {
public Map<String, String> canHasTranslations(String lang) {
return Translations.getTranslationFromResourcePath(String.format("assets/joacarpet/lang/%s.json", lang));
}

public static void messagePlayerIfExists(CommandSourceStack c, String message) {

//#if MC >= 11900
//$$ if(c.getPlayer() != null) {
//$$ Messenger.m(c.getPlayer(), message);
//$$ }
//#else
if(c.getEntity() instanceof ServerPlayer) {
Messenger.m((Player) c.getEntity(), message);
}
//#endif
}
}
46 changes: 40 additions & 6 deletions src/main/java/com/joacarpet/JoaCarpetSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,54 @@

package com.joacarpet;

import carpet.api.settings.Rule;
//#if MC >= 11900
//$$ import carpet.api.settings.Rule;
//#else
import carpet.settings.Rule;
//#endif

//#if MC >= 11900
//$$ import static carpet.api.settings.RuleCategory.COMMAND;
//$$ import static carpet.api.settings.RuleCategory.CREATIVE;
//#else
import static carpet.settings.RuleCategory.COMMAND;
import static carpet.settings.RuleCategory.CREATIVE;
//#endif

import static carpet.api.settings.RuleCategory.COMMAND;
import static carpet.api.settings.RuleCategory.CREATIVE;

public class JoaCarpetSettings {
public static final String JOA = "JoaCarpet";

@Rule(categories = {CREATIVE, JOA}, options = {"extreme", "sensible", "off"})
@Rule(
//#if MC >= 11900
//$$ categories = {CREATIVE, JOA},
//#else
category = {CREATIVE, JOA},
desc="Makes the random velocities of droppers and projectiles (as well as both the position and velocity of blocks broken by pistons) systematically iterate through the most extreme values possible, and then repeatedly iterate through all the halfway points in between, in a sense attempting every point in a 3d/5d \"grid\" that slowly increases in resolution.\nFor droppers and projectiles, this setting determines whether the max value corresponds to the old gaussian randomness limits (\"extreme\"), or the limits of the triangular randomness introduced in 1.19 (\"sensible\"). Both settings function the same for blocks being broken by pistons.\nFor the `/insanebehaviors <reset/getstate/setstate>` command, see `/carpet commandInsaneBehaviors`.\nDo note that insaneBehaviors works on a global iterator: any triggering event will step through an iteration from all other insaneBehaviors events, too.",
//#endif
options = {"extreme", "sensible", "off"}
)
public static String insaneBehaviors = "off";

@Rule(categories = {COMMAND, CREATIVE, JOA}, options = {"true", "ops", "false", "0", "1", "2", "3", "4"})
@Rule(
//#if MC >= 11900
//$$ categories = {COMMAND, CREATIVE, JOA},
//#else
category = {COMMAND, CREATIVE, JOA},
desc="The command used for the `insaneBehaviors` rule.\n\"reset\" sets the `resolution` and `counter` back to the default values. \"getstate\" and \"setstate\" are used to manually read and write the current iteration state.",
//#endif
options = {"true", "ops", "false", "0", "1", "2", "3", "4"}
)
public static String commandInsaneBehaviors = "ops";

@Rule(categories = {CREATIVE, JOA}, options = {"off", "blockupdates", "shapeupdates", "both"})
@Rule(
//#if MC >= 11900
//$$ categories = {CREATIVE, JOA},
//#else
category = {CREATIVE, JOA},
desc="Lets you send manual block and/or shape updates to blocks using a feather item. Updates are sent from the block in front of the face you're clicking on. Useful if you're working with update interations off or with budded blocks.",
//#endif
options = {"off", "blockupdates", "shapeupdates", "both"}
)
public static String blockTickling = "off";
}
16 changes: 13 additions & 3 deletions src/main/java/com/joacarpet/commands/InsaneBehaviorsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@

package com.joacarpet.commands;

import carpet.utils.CommandHelper;
import com.joacarpet.InsaneBehaviors;
import com.joacarpet.JoaCarpetMod;
import com.joacarpet.JoaCarpetSettings;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import net.minecraft.commands.CommandSourceStack;

import java.util.Objects;

//#if MC >= 11900
//$$ import carpet.utils.CommandHelper;
//#else
import carpet.settings.SettingsManager;
//#endif

import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;

Expand All @@ -38,7 +42,13 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(
literal("insanebehaviors")
.requires(c -> !Objects.equals(JoaCarpetSettings.insaneBehaviors, "normal") &&
CommandHelper.canUseCommand(c, JoaCarpetSettings.commandInsaneBehaviors))
//#if MC >= 11900
//$$ CommandHelper.canUseCommand(c, JoaCarpetSettings.commandInsaneBehaviors))
//#else
SettingsManager.canUseCommand(c, JoaCarpetSettings.commandInsaneBehaviors))
//#endif


.executes(c -> 1)
.then(
literal("reset")
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/com/joacarpet/mixin/blockTickling/ItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

package com.joacarpet.mixin.blockTickling;

import com.joacarpet.JoaCarpetMod;
import com.joacarpet.JoaCarpetSettings;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -44,15 +46,23 @@ public void useOn(UseOnContext useOnContext, CallbackInfoReturnable<InteractionR
if (level.isClientSide) {
return;
}
BlockPos blockPos = useOnContext.getClickedPos();
BlockPos neighborPos = blockPos.relative(useOnContext.getClickedFace());
BlockPos clickedPos = useOnContext.getClickedPos();
BlockPos neighborPos = clickedPos.relative(useOnContext.getClickedFace());
BlockState neighborBlockState = level.getBlockState(neighborPos);

JoaCarpetMod.LOGGER.info("NeighborPos: {}", neighborPos);

if (JoaCarpetSettings.blockTickling.equals("blockupdates") || JoaCarpetSettings.blockTickling.equals("both")) {
level.neighborChanged(blockPos, neighborBlockState.getBlock(), neighborPos);
level.neighborChanged(clickedPos, neighborBlockState.getBlock(), neighborPos);
}
if (JoaCarpetSettings.blockTickling.equals("shapeupdates") || JoaCarpetSettings.blockTickling.equals("both")) {
level.neighborShapeChanged(useOnContext.getClickedFace(), neighborBlockState, blockPos, neighborPos, 2, 512);
//#if MC >= 11900
//$$ level.neighborShapeChanged(useOnContext.getClickedFace(), neighborBlockState, clickedPos, neighborPos, 2, 512);
//#else
BlockState clickedBlockState = level.getBlockState(clickedPos);
BlockState newState = clickedBlockState.updateShape(useOnContext.getClickedFace(), neighborBlockState, level, clickedPos, neighborPos);
Block.updateOrDestroy(clickedBlockState, newState, level, clickedPos, 2, 512);
//#endif
}
cir.setReturnValue(InteractionResult.SUCCESS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class DefaultDispenseItemBehaviorMixin {

@Redirect(method = "spawnItem", at = @At(
value = "INVOKE",
target = "net/minecraft/world/entity/item/ItemEntity.setDeltaMovement (DDD)V"
target = "Lnet/minecraft/world/entity/item/ItemEntity;setDeltaMovement(DDD)V"
))
private static void setDeltaMovement(ItemEntity itemEntity, double d, double e, double f, Level _level, ItemStack _itemStack, int i, Direction direction, Position _position) {
if (JoaCarpetSettings.insaneBehaviors.equals("off")) {
Expand Down Expand Up @@ -70,12 +70,4 @@ private static void setDeltaMovement(ItemEntity itemEntity, double d, double e,
};
itemEntity.setDeltaMovement(velocity);
}

// @Redirect(method = "spawnItem", expect = 3, at = @At(
// value = "INVOKE",
// target = "net/minecraft/util/RandomSource.triangle (DD)D"
// ))
// private static double triangle(RandomSource randomSource, double d, double e) {
// return d + e * (randomSource.nextDouble() - randomSource.nextDouble()) + 1;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ private void dropResources(BlockState blockState, LevelAccessor levelAccessor, B
customPopResource(level, blockPos, itemStack);
}
});
blockState.spawnAfterBreak((ServerLevel)levelAccessor, blockPos, ItemStack.EMPTY, true);
//#if MC >= 11900
//$$ blockState.spawnAfterBreak((ServerLevel)levelAccessor, blockPos, ItemStack.EMPTY, true);
//#else
blockState.spawnAfterBreak((ServerLevel)levelAccessor, blockPos, ItemStack.EMPTY);
//#endif
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class ProjectileMixin {
@Redirect(method = "shoot", at = @At(
value = "INVOKE",
target = "net/minecraft/world/phys/Vec3.add (DDD)Lnet/minecraft/world/phys/Vec3;"
target = "Lnet/minecraft/world/phys/Vec3;add(DDD)Lnet/minecraft/world/phys/Vec3;"
))
private Vec3 add(Vec3 vec3, double d, double e, double f, double deltaMovementX, double deltaMovementY, double deltaMovementZ, float deltaMovementMultiplier, float divergence) {
if (JoaCarpetSettings.insaneBehaviors.equals("off")) {
Expand Down
2 changes: 1 addition & 1 deletion versions/1.20.2/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Build Information
# The target mc versions for the mod during mod publishing, separated with \n
game_versions=1.20.2
game_versions=1.20.2\n1.20.1

# Dependencies
# fabric_api_version=0.91.3+1.20.4
Expand Down
2 changes: 1 addition & 1 deletion versions/mainProject
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.19.4
1.17.1

0 comments on commit cdaae63

Please sign in to comment.