Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0.0 for 1.20.2 #6

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ allprojects {
apply plugin: "maven-publish"
apply plugin: "signing"

group = 'net.rotgruengelb'
version = "${project.mod_version}+${rootProject.mod_minecraft_base_version}"

def ENV = System.getenv()
def publishType = System.getenv("PUBLISH_TYPE")

version = "${project.mod_version}+${project.mod_minecraft_base_version}"
def uniqueId = System.getenv("UNIQUE_ID")

if (publishType == "SNAPSHOT") {
version = "${project.mod_version}+${rootProject.mod_minecraft_base_version}-SNAPSHOT"
version = "${version}-${uniqueId}-SNAPSHOT"
}

group = rootProject.maven_group
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.20.2+build.4
loader_version=0.14.24

# Mod Properties
mod_version=2.0.2
mod_version=3.0.0
mod_minecraft_base_version=1.20.2

# Maven/Publishing
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/net/rotgruengelb/quirl/Quirl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import net.minecraft.block.Blocks;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.rotgruengelb.quirl.api.mechanic.interact.axe.v1.CustomAxeBlockInteract;
import net.rotgruengelb.quirl.api.mechanic.interact.shovel.v1.CustomShovelBlockInteract;
import net.rotgruengelb.quirl.api.mechanic.interact.onblock.AxeBlockInteractRegistry;
import net.rotgruengelb.quirl.api.mechanic.interact.onblock.ShovelBlockInteractRegistry;
import net.rotgruengelb.quirl.internal.command.CommandNodes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Quirl implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("quirl");
public static final String MOD_ID = "quirl";
public static final Boolean MOD_TEST_MODE = false;
public static final Boolean MOD_TEST_MODE = true;

@Override
public void onInitialize() {
Expand All @@ -24,10 +24,9 @@ public void onInitialize() {

if (MOD_TEST_MODE) {
LOGGER.warn("quirl is in test mode! do not release with 'MOD_TEST_MOD = true'!");
CustomShovelBlockInteract.addResult(Blocks.ACACIA_PLANKS.getDefaultState(), Blocks.DIRT.getDefaultState(), SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, true);
CustomShovelBlockInteract.addResult(Blocks.SPRUCE_PLANKS.getDefaultState(), Blocks.DIRT.getDefaultState(), SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS);
CustomAxeBlockInteract.addResult(Blocks.AMETHYST_BLOCK.getDefaultState(), Blocks.BLUE_ICE.getDefaultState(), SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS);

ShovelBlockInteractRegistry.register(Blocks.ACACIA_PLANKS.getDefaultState(), Blocks.DIRT.getDefaultState(), SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, true);
ShovelBlockInteractRegistry.register(Blocks.SPRUCE_PLANKS.getDefaultState(), Blocks.DIRT.getDefaultState(), SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS);
AxeBlockInteractRegistry.register(Blocks.AMETHYST_BLOCK.getDefaultState(), Blocks.BLUE_ICE.getDefaultState(), SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.rotgruengelb.quirl.api.mechanic.interact.onblock;

import net.minecraft.block.BlockState;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;

public class AxeBlockInteractRegistry {

private static final Map<BlockState, ToolBlockInteractResult> REG = new HashMap<>();

public static void register(BlockState starting_blockstate, BlockState new_blockstate, SoundEvent sound_event, SoundCategory sound_category) {
REG.put(starting_blockstate, new ToolBlockInteractResult(new_blockstate, sound_event, sound_category, false));
}

public static @Nullable ToolBlockInteractResult getResult(BlockState blockState) {
return REG.get(blockState);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.rotgruengelb.quirl.api.mechanic.interact.onblock;

import net.minecraft.block.BlockState;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;

public class ShovelBlockInteractRegistry {

private static final Map<BlockState, ToolBlockInteractResult> REG = new HashMap<>();

public static void register(BlockState starting_blockstate, BlockState new_blockstate, SoundEvent sound_event, SoundCategory sound_category) {
REG.put(starting_blockstate, new ToolBlockInteractResult(new_blockstate, sound_event, sound_category, false));
}

public static void register(BlockState starting_blockstate, BlockState new_blockstate, SoundEvent sound_event, SoundCategory sound_category, Boolean disable_surrounding_checks) {
REG.put(starting_blockstate, new ToolBlockInteractResult(new_blockstate, sound_event, sound_category, disable_surrounding_checks));
}

public static @Nullable ToolBlockInteractResult getResult(BlockState blockState) {
return REG.get(blockState);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package net.rotgruengelb.quirl.api.mechanic.interact.result.v1;
package net.rotgruengelb.quirl.api.mechanic.interact.onblock;

import net.minecraft.block.BlockState;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;

public class ToolBlockInteractResult {

BlockState new_blockstate;
SoundEvent interact_sound_event;
SoundCategory interact_sound_category;
Boolean disable_surrounding_checks;
final BlockState new_blockstate;
final SoundEvent interact_sound_event;
final SoundCategory interact_sound_category;
final Boolean disable_surrounding_checks;

public ToolBlockInteractResult(BlockState newBlockstate, SoundEvent interactSoundEvent, SoundCategory interactSoundCategory, Boolean disableSurroundingChecks) {
new_blockstate = newBlockstate;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.rotgruengelb.quirl.lib.feature.item;

import net.fabricmc.api.Environment;
import net.minecraft.client.model.ModelPart;
import net.minecraft.entity.LivingEntity;

/**
* This interface is used to add custom arm poses to items. <br>
* The methods positionRightArm and positionLeftArm are called by the mixin BipedEntityModelMixin.
*/
@Environment(net.fabricmc.api.EnvType.CLIENT)
public interface HasCustomArmPose {
void positionRightArm(ModelPart rightArm, LivingEntity entity, ModelPart head, ModelPart hat, ModelPart body, ModelPart leftArm, ModelPart rightLeg, ModelPart leftLeg);

void positionLeftArm(ModelPart leftArm, LivingEntity entity, ModelPart head, ModelPart hat, ModelPart body, ModelPart rightArm, ModelPart rightLeg, ModelPart leftLeg);
}
23 changes: 11 additions & 12 deletions src/main/java/net/rotgruengelb/quirl/mixin/AxeItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
import net.rotgruengelb.quirl.api.mechanic.interact.result.v1.ToolBlockInteractResult;
import net.rotgruengelb.quirl.api.mechanic.interact.onblock.AxeBlockInteractRegistry;
import net.rotgruengelb.quirl.api.mechanic.interact.onblock.ToolBlockInteractResult;
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;

import static net.rotgruengelb.quirl.api.mechanic.interact.axe.v1.CustomAxeBlockInteract.CUSTOM_AXE_INTERACT_RESULTS;

@Mixin(AxeItem.class)
public class AxeItemMixin {

Expand All @@ -26,22 +25,22 @@ private void add_custom_useOn(ItemUsageContext context, CallbackInfoReturnable<A
BlockPos blockPos = context.getBlockPos();
BlockState blockState = world.getBlockState(blockPos);
PlayerEntity playerEntity = context.getPlayer();
ToolBlockInteractResult shovelInteractResult = CUSTOM_AXE_INTERACT_RESULTS.get(blockState);
ToolBlockInteractResult shovelInteractResult = AxeBlockInteractRegistry.getResult(blockState);
BlockState blockState3 = null;
if (shovelInteractResult != null) {
world.playSound(playerEntity, blockPos, shovelInteractResult.getInteract_sound_event(), shovelInteractResult.getInteract_sound_category(), 1.0f, 1.0f);
blockState3 = shovelInteractResult.getNew_blockstate();
}
if (blockState3 != null) {
if (!world.isClient) {
world.setBlockState(blockPos, blockState3, Block.NOTIFY_ALL | Block.REDRAW_ON_MAIN_THREAD);
world.emitGameEvent(GameEvent.BLOCK_CHANGE, blockPos, GameEvent.Emitter.of(playerEntity, blockState3));
if (playerEntity != null) {
context.getStack().damage(1, playerEntity, p -> p.sendToolBreakStatus(context.getHand()));
}
if (!world.isClient) {
world.setBlockState(blockPos, blockState3, Block.NOTIFY_ALL | Block.REDRAW_ON_MAIN_THREAD);
world.emitGameEvent(GameEvent.BLOCK_CHANGE, blockPos, GameEvent.Emitter.of(playerEntity, blockState3));
if (playerEntity != null) {
context.getStack().damage(1, playerEntity, p -> p.sendToolBreakStatus(context.getHand()));
}
cir.setReturnValue(ActionResult.success(world.isClient));
cir.cancel();
}
cir.setReturnValue(ActionResult.success(world.isClient));
cir.cancel();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package net.rotgruengelb.quirl.mixin;

import net.fabricmc.api.Environment;
import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.entity.model.BipedEntityModel;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.Item;
import net.rotgruengelb.quirl.lib.feature.item.HasCustomArmPose;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Environment(net.fabricmc.api.EnvType.CLIENT)
@Mixin(BipedEntityModel.class)
public class BipedEntityModelMixin {

@Shadow
@Final
public ModelPart rightArm;

@Shadow
@Final
public ModelPart head;

@Shadow
@Final
public ModelPart leftArm;

@Shadow
@Final
public ModelPart hat;

@Shadow
@Final
public ModelPart body;

@Shadow
@Final
public ModelPart leftLeg;

@Shadow
@Final
public ModelPart rightLeg;

@Inject(at = @At(value = "TAIL"), method = "positionRightArm")
void positionRightArm(LivingEntity entity, CallbackInfo ci) {
Item activeItem = entity.getActiveItem().getItem();
if (activeItem instanceof HasCustomArmPose) {
((HasCustomArmPose) activeItem).positionRightArm(this.rightArm, entity, this.head, this.hat, this.body, this.leftArm, this.rightLeg, this.leftLeg);
}
}

@Inject(at = @At(value = "TAIL"), method = "positionLeftArm")
void positionLeftArm(LivingEntity entity, CallbackInfo ci) {
Item activeItem = entity.getActiveItem().getItem();
if (activeItem instanceof HasCustomArmPose) {
((HasCustomArmPose) activeItem).positionLeftArm(this.leftArm, entity, this.head, this.hat, this.body, this.rightArm, this.rightLeg, this.leftLeg);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
import net.rotgruengelb.quirl.api.mechanic.interact.result.v1.ToolBlockInteractResult;
import net.rotgruengelb.quirl.api.mechanic.interact.onblock.ShovelBlockInteractRegistry;
import net.rotgruengelb.quirl.api.mechanic.interact.onblock.ToolBlockInteractResult;
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;

import static net.rotgruengelb.quirl.api.mechanic.interact.shovel.v1.CustomShovelBlockInteract.CUSTOM_SHOVEL_INTERACT_RESULTS;

@Mixin(ShovelItem.class)
public class ShovelItemMixin {

Expand All @@ -27,7 +26,7 @@ private void add_custom_useOn(ItemUsageContext context, CallbackInfoReturnable<A
BlockPos blockPos = context.getBlockPos();
BlockState blockState = world.getBlockState(blockPos);
PlayerEntity playerEntity = context.getPlayer();
ToolBlockInteractResult shovelInteractResult = CUSTOM_SHOVEL_INTERACT_RESULTS.get(blockState);
ToolBlockInteractResult shovelInteractResult = ShovelBlockInteractRegistry.getResult(blockState);
BlockState blockState3 = null;
if (shovelInteractResult != null) {
if ((world.getBlockState(blockPos.up()).isAir() && (context.getSide() != Direction.DOWN)) || shovelInteractResult.getDisable_surrounding_checks()) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/quirl.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
],
"injectors": {
"defaultRequire": 1
}
},
"client": [
"BipedEntityModelMixin"
]
}