Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.20.1' into 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Dec 11, 2024
2 parents 3adf1a9 + 30e3e1f commit 5484c0a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 51 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.caching=true

loom_version = 1.6.+

mod_version = 2.3.7
mod_version = 2.3.9

# https://fabricmc.net/develop
minecraft_version = 1.20.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,57 @@
import java.util.List;
import java.util.Objects;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;

import com.llamalad7.mixinextras.sugar.Local;

import io.github.fabricators_of_create.porting_lib.core.PortingLib;
import io.github.fabricators_of_create.porting_lib.util.StructureTemplateUtils;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.levelgen.structure.BoundingBox;

import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureEntityInfo;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;

import io.github.fabricators_of_create.porting_lib.core.PortingLib;
import io.github.fabricators_of_create.porting_lib.extensions.extensions.StructureTemplateExtensions;
import io.github.fabricators_of_create.porting_lib.util.StructureTemplateUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureEntityInfo;
import net.minecraft.world.phys.Vec3;

import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(StructureTemplate.class)
public abstract class StructureTemplateMixin implements StructureTemplateExtensions {
@Unique
private static final ThreadLocal<StructurePlaceSettings> currentSettings = new ThreadLocal<>();

@Shadow
@Final
private List<StructureEntityInfo> entityInfoList;

@Shadow
protected abstract void placeEntities(ServerLevelAccessor serverLevelAccessor, BlockPos blockPos, Mirror mirror, Rotation rotation, BlockPos blockPos2, @Nullable BoundingBox boundingBox, boolean bl);

@Unique
private static final ThreadLocal<StructurePlaceSettings> currentSettings = new ThreadLocal<>();

@Inject(
@WrapOperation(
method = "placeInWorld",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate;placeEntities(Lnet/minecraft/world/level/ServerLevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/Mirror;Lnet/minecraft/world/level/block/Rotation;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/levelgen/structure/BoundingBox;Z)V"
)
)
private void grabSettings(ServerLevelAccessor level, BlockPos pos, BlockPos pivot, StructurePlaceSettings settings,
RandomSource random, int i, CallbackInfoReturnable<Boolean> cir) {
private void grabSettings(StructureTemplate self, ServerLevelAccessor level, BlockPos pos, Mirror mirror, Rotation rotation,
BlockPos pivot, BoundingBox bounds, boolean finalize, Operation<Void> original,
@Local(argsOnly = true) StructurePlaceSettings settings) {
currentSettings.set(settings);
original.call(self, level, pos, mirror, rotation, pivot, bounds, finalize);
currentSettings.remove();
}

@ModifyExpressionValue(
Expand Down Expand Up @@ -111,11 +109,6 @@ private Vec3 dontProcessVecTwice(Vec3 original, @Local StructureEntityInfo info)
return original;
}

@Inject(method = "placeEntities", at = @At("RETURN"))
private void clearGrabbedSettings(CallbackInfo ci) {
currentSettings.remove(); // clear the settings when done to avoid leaking it
}

// --- deprecated API ---

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.github.fabricators_of_create.porting_lib.tool.ToolAction;
import io.github.fabricators_of_create.porting_lib.tool.ToolActions;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.AxeItem;
import net.minecraft.world.item.HoneycombItem;
Expand All @@ -13,6 +14,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.WeatheringCopper;
import net.minecraft.world.level.block.state.BlockState;

Expand All @@ -29,18 +31,28 @@ public interface BlockExtensions {
* {@link ToolActions#SHOVEL_FLATTEN a shovel can path}, or {@link ToolActions#HOE_TILL a hoe can till}.
* Returns {@code null} if nothing should happen.
*
* @param state The current state
* @param context The use on context that the action was performed in
* @param state The current state
* @param context The use on context that the action was performed in
* @param toolAction The action being performed by the tool
* @param simulate If {@code true}, no actions that modify the world in any way should be performed. If {@code false}, the world may be modified.
* @param simulate If {@code true}, no actions that modify the world in any way should be performed. If {@code false}, the world may be modified.
* @return The resulting state after the action has been performed
*/
@Nullable
default BlockState getToolModifiedState(BlockState state, UseOnContext context, ToolAction toolAction, boolean simulate) {
BlockState toolModifiedState = getToolModifiedState(state, context.getLevel(), context.getClickedPos(),
context.getPlayer(), context.getItemInHand(), toolAction);
ItemStack itemStack = context.getItemInHand();
if (!itemStack.canPerformAction(toolAction))
return null;

if (toolModifiedState == null && ToolActions.HOE_TILL == toolAction && context.getItemInHand().canPerformAction(ToolActions.HOE_TILL)) {
if (ToolActions.AXE_STRIP == toolAction) {
Block block = AxeItem.STRIPPABLES.get(state.getBlock());
return block != null ? block.defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)) : null;
} else if (ToolActions.AXE_SCRAPE == toolAction) {
return WeatheringCopper.getPrevious(state).orElse(null);
} else if (ToolActions.AXE_WAX_OFF == toolAction) {
return Optional.ofNullable(HoneycombItem.WAX_OFF_BY_BLOCK.get().get(state.getBlock())).map(block -> block.withPropertiesOf(state)).orElse(null);
} else if (ToolActions.SHOVEL_FLATTEN == toolAction) {
return ShovelItem.FLATTENABLES.get(state.getBlock());
} else if (ToolActions.HOE_TILL == toolAction) {
// Logic copied from HoeItem#TILLABLES; needs to be kept in sync during updating
Block block = state.getBlock();
if (block == Blocks.ROOTED_DIRT) {
Expand All @@ -54,35 +66,37 @@ default BlockState getToolModifiedState(BlockState state, UseOnContext context,
}
}

return toolModifiedState;
return null;
}

/**
* Returns the state that this block should transform into when right clicked by a tool.
* For example: Used to determine if an axe can strip, a shovel can path, or a hoe can till.
* Return null if vanilla behavior should be disabled.
*
* @param state The current state
* @param world The world
* @param pos The block position in world
* @param player The player clicking the block
* @param stack The stack being used by the player
* @param state The current state
* @param world The world
* @param pos The block position in world
* @param player The player clicking the block
* @param stack The stack being used by the player
* @param toolAction The action being performed by the tool
* @return The resulting state after the action has been performed
* @deprecated Use {@link #getToolModifiedState(UseOnContext, ToolAction, boolean)} instead
*/
@Nullable
@Nullable // Uhh this should have been removed in the 1.19.2 or 1.20 port and removing it now would likely just break mods so ¯\_(ツ)_/¯
// TODO 1.19: Remove
@Deprecated(forRemoval = true, since = "1.20.1")
default BlockState getToolModifiedState(BlockState state, Level world, BlockPos pos, Player player, ItemStack stack, ToolAction toolAction) {
if (!stack.canPerformAction(toolAction)) return null;
if (ToolActions.AXE_STRIP.equals(toolAction)) {
if (ToolActions.AXE_STRIP == toolAction) {
Block block = AxeItem.STRIPPABLES.get(state.getBlock());
return block != null ? block.defaultBlockState() : null;
}
else if(ToolActions.AXE_SCRAPE.equals(toolAction)) return WeatheringCopper.getPrevious(state).orElse(null);
else if(ToolActions.AXE_WAX_OFF.equals(toolAction)) return Optional.ofNullable(HoneycombItem.WAX_OFF_BY_BLOCK.get().get(state.getBlock())).map((p_150694_) -> {
return p_150694_.withPropertiesOf(state);
}).orElse(null);
//else if(ToolActions.HOE_TILL.equals(toolAction)) return HoeItem.getHoeTillingState(state); //TODO HoeItem bork
else if (ToolActions.SHOVEL_FLATTEN.equals(toolAction)) return ShovelItem.FLATTENABLES.get(state.getBlock());
return block != null ? block.defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)) : null;
} else if (ToolActions.AXE_SCRAPE == toolAction) return WeatheringCopper.getPrevious(state).orElse(null);
else if (ToolActions.AXE_WAX_OFF == toolAction)
return Optional.ofNullable(HoneycombItem.WAX_OFF_BY_BLOCK.get().get(state.getBlock())).map((p_150694_) -> {
return p_150694_.withPropertiesOf(state);
}).orElse(null);
else if (ToolActions.SHOVEL_FLATTEN == toolAction) return ShovelItem.FLATTENABLES.get(state.getBlock());
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ default BlockState getToolModifiedState(UseOnContext context, ToolAction toolAct
* @return The resulting state after the action has been performed
*/
@Nullable
@Deprecated(forRemoval = true)
default BlockState getToolModifiedState(Level world, BlockPos pos, Player player, ItemStack stack, ToolAction toolAction) {
return ((BlockState) this).getBlock().getToolModifiedState(((BlockState) this), world, pos, player, stack, toolAction);
}
Expand Down

0 comments on commit 5484c0a

Please sign in to comment.