-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement tool action transform module
Replaces the old block transform modifier, for implementing effects such as tilling and stripping This commit comes with three small behavioral changes: * When using pathing, campfire extinguishing and making path blocks no longer connect as part of the same AOE * axe_scrape and axe_wax_off were merged into stripping, meaning tools given stripping now can scrap copper * Priorities of stripping, tilling, pathing, and firestarter are all 100 now, meaning they have the same precedence as most other interaction modifiers. Workstation lets you reorder them and they by default are later due to fallback in any case
- Loading branch information
1 parent
717fc45
commit 7beb503
Showing
22 changed files
with
524 additions
and
55 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
src/generated/resources/data/tconstruct/tinkering/modifiers/axe_scrape.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"redirects": [ | ||
{ | ||
"id": "tconstruct:stripping" | ||
} | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
src/generated/resources/data/tconstruct/tinkering/modifiers/axe_wax_off.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"redirects": [ | ||
{ | ||
"id": "tconstruct:stripping" | ||
} | ||
] | ||
} |
19 changes: 19 additions & 0 deletions
19
src/generated/resources/data/tconstruct/tinkering/modifiers/pathing.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"type": "tconstruct:composable", | ||
"level_display": "tconstruct:no_levels", | ||
"tooltip_display": "always", | ||
"modules": [ | ||
{ | ||
"type": "tconstruct:show_offhand" | ||
}, | ||
{ | ||
"type": "tconstruct:campfire_extinguish" | ||
}, | ||
{ | ||
"type": "tconstruct:tool_action_transform", | ||
"tool_action": "shovel_flatten", | ||
"sound": "minecraft:item.shovel.flatten", | ||
"require_ground": true | ||
} | ||
] | ||
} |
30 changes: 30 additions & 0 deletions
30
src/generated/resources/data/tconstruct/tinkering/modifiers/stripping.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"type": "tconstruct:composable", | ||
"level_display": "tconstruct:default", | ||
"tooltip_display": "always", | ||
"modules": [ | ||
{ | ||
"type": "tconstruct:show_offhand" | ||
}, | ||
{ | ||
"type": "tconstruct:tool_action_transform", | ||
"tool_action": "axe_strip", | ||
"sound": "minecraft:item.axe.strip", | ||
"require_ground": false | ||
}, | ||
{ | ||
"type": "tconstruct:tool_action_transform", | ||
"tool_action": "axe_scrape", | ||
"sound": "minecraft:item.axe.scrape", | ||
"require_ground": false, | ||
"event_id": 3005 | ||
}, | ||
{ | ||
"type": "tconstruct:tool_action_transform", | ||
"tool_action": "axe_wax_off", | ||
"sound": "minecraft:item.axe.wax_off", | ||
"require_ground": false, | ||
"event_id": 3004 | ||
} | ||
] | ||
} |
16 changes: 16 additions & 0 deletions
16
src/generated/resources/data/tconstruct/tinkering/modifiers/tilling.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"type": "tconstruct:composable", | ||
"level_display": "tconstruct:default", | ||
"tooltip_display": "always", | ||
"modules": [ | ||
{ | ||
"type": "tconstruct:show_offhand" | ||
}, | ||
{ | ||
"type": "tconstruct:tool_action_transform", | ||
"tool_action": "till", | ||
"sound": "minecraft:item.hoe.till", | ||
"require_ground": false | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
...java/slimeknights/tconstruct/library/modifiers/modules/behavior/BlockTransformModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package slimeknights.tconstruct.library.modifiers.modules.behavior; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.entity.EquipmentSlot; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.context.UseOnContext; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import slimeknights.tconstruct.library.modifiers.ModifierEntry; | ||
import slimeknights.tconstruct.library.modifiers.ModifierHook; | ||
import slimeknights.tconstruct.library.modifiers.TinkerHooks; | ||
import slimeknights.tconstruct.library.modifiers.hook.interaction.BlockInteractionModifierHook; | ||
import slimeknights.tconstruct.library.modifiers.hook.interaction.InteractionSource; | ||
import slimeknights.tconstruct.library.modifiers.modules.ModifierModule; | ||
import slimeknights.tconstruct.library.tools.definition.aoe.IAreaOfEffectIterator; | ||
import slimeknights.tconstruct.library.tools.definition.module.ToolModuleHooks; | ||
import slimeknights.tconstruct.library.tools.helper.ToolDamageUtil; | ||
import slimeknights.tconstruct.library.tools.nbt.IToolStackView; | ||
import slimeknights.tconstruct.library.utils.MutableUseOnContext; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
public abstract class BlockTransformModule implements ModifierModule, BlockInteractionModifierHook { | ||
private static final List<ModifierHook<?>> DEFAULT_HOOKS = List.of(TinkerHooks.BLOCK_INTERACT); | ||
|
||
protected final boolean requireGround; | ||
|
||
@Override | ||
public List<ModifierHook<?>> getDefaultHooks() { | ||
return DEFAULT_HOOKS; | ||
} | ||
|
||
@Override | ||
public InteractionResult afterBlockUse(IToolStackView tool, ModifierEntry modifier, UseOnContext context, InteractionSource source) { | ||
// tool must not be broken | ||
if (tool.isBroken() || !tool.getDefinitionData().getModule(ToolModuleHooks.INTERACTION).canInteract(tool, modifier.getId(), source)) { | ||
return InteractionResult.PASS; | ||
} | ||
|
||
Player player = context.getPlayer(); | ||
if (player != null && player.isShiftKeyDown()) { | ||
return InteractionResult.PASS; | ||
} | ||
|
||
// for hoes and shovels, must have nothing but plants above | ||
if (requireGround && context.getClickedFace() == Direction.DOWN) { | ||
return InteractionResult.PASS; | ||
} | ||
|
||
// must actually transform | ||
Level world = context.getLevel(); | ||
BlockPos pos = context.getClickedPos(); | ||
BlockState original = world.getBlockState(pos); | ||
ItemStack stack = context.getItemInHand(); | ||
boolean didTransform = transform(tool, context, original, true); | ||
|
||
// if we made a successful transform, client can stop early | ||
EquipmentSlot slotType = source.getSlot(context.getHand()); | ||
if (didTransform) { | ||
if (world.isClientSide) { | ||
return InteractionResult.SUCCESS; | ||
} | ||
|
||
// if the tool breaks or it was a campfire, we are done | ||
if (ToolDamageUtil.damage(tool, 1, player, stack)) { | ||
if (player != null) { | ||
player.broadcastBreakEvent(slotType); | ||
} | ||
return InteractionResult.CONSUME; | ||
} | ||
} | ||
|
||
// AOE transforming, run even if we did not transform the center | ||
// note we consider anything effective, as hoes are not effective on all tillable blocks | ||
if (player != null && !tool.isBroken()) { | ||
int totalTransformed = 0; | ||
Iterator<BlockPos> aoePos = tool.getDefinition().getData().getAOE().getBlocks(tool, stack, player, original, world, pos, context.getClickedFace(), IAreaOfEffectIterator.AOEMatchType.TRANSFORM).iterator(); | ||
if (aoePos.hasNext()) { | ||
MutableUseOnContext offsetContext = new MutableUseOnContext(context); | ||
do { | ||
BlockPos newPos = aoePos.next(); | ||
if (pos.equals(newPos)) { | ||
continue; | ||
} | ||
|
||
// try interacting with the new position | ||
offsetContext.setOffsetPos(newPos); | ||
|
||
BlockState newTarget = world.getBlockState(newPos); | ||
|
||
// limit to playing 40 sounds, that's more than enough for most transforms | ||
if (transform(tool, offsetContext, newTarget, totalTransformed < 40)) { | ||
totalTransformed++; | ||
didTransform = true; | ||
|
||
if (world.isClientSide) { | ||
break; | ||
} | ||
|
||
// stop if the tool broke | ||
if (ToolDamageUtil.damageAnimated(tool, 1, player, slotType)) { | ||
break; | ||
} | ||
} | ||
} while (aoePos.hasNext()); | ||
|
||
// sweep attack if we transformed any | ||
if (totalTransformed > 0) { | ||
player.sweepAttack(); | ||
} | ||
} | ||
} | ||
|
||
// if anything happened, return success | ||
return didTransform ? InteractionResult.sidedSuccess(world.isClientSide) : InteractionResult.PASS; | ||
} | ||
|
||
/** Applies this transformation */ | ||
protected abstract boolean transform(IToolStackView tool, UseOnContext context, BlockState original, boolean playSound); | ||
} |
48 changes: 48 additions & 0 deletions
48
.../slimeknights/tconstruct/library/modifiers/modules/behavior/ExtinguishCampfireModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package slimeknights.tconstruct.library.modifiers.modules.behavior; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.sounds.SoundEvents; | ||
import net.minecraft.sounds.SoundSource; | ||
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.CampfireBlock; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import slimeknights.mantle.data.GenericLoaderRegistry.IGenericLoader; | ||
import slimeknights.mantle.data.GenericLoaderRegistry.SingletonLoader; | ||
import slimeknights.tconstruct.library.modifiers.modules.ModifierModule; | ||
import slimeknights.tconstruct.library.tools.nbt.IToolStackView; | ||
|
||
/** | ||
* Module which performs AOE removing of campfires | ||
*/ | ||
public class ExtinguishCampfireModule extends BlockTransformModule { | ||
public static final ExtinguishCampfireModule INSTANCE = new ExtinguishCampfireModule(); | ||
public static final IGenericLoader<ExtinguishCampfireModule> LOADER = new SingletonLoader<>(INSTANCE); | ||
|
||
private ExtinguishCampfireModule() { | ||
super(false); | ||
} | ||
|
||
@Override | ||
public IGenericLoader<? extends ModifierModule> getLoader() { | ||
return LOADER; | ||
} | ||
|
||
@Override | ||
protected boolean transform(IToolStackView tool, UseOnContext context, BlockState original, boolean playSound) { | ||
if (original.getBlock() instanceof CampfireBlock && original.getValue(CampfireBlock.LIT)) { | ||
Level level = context.getLevel(); | ||
BlockPos pos = context.getClickedPos(); | ||
if (!level.isClientSide) { | ||
if (playSound) { | ||
level.playSound(null, pos, SoundEvents.GENERIC_EXTINGUISH_FIRE, SoundSource.BLOCKS, 1.0F, 1.0F); | ||
} | ||
CampfireBlock.dowse(context.getPlayer(), level, pos, original); | ||
} | ||
level.setBlock(pos, original.setValue(CampfireBlock.LIT, false), Block.UPDATE_ALL_IMMEDIATE); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...in/java/slimeknights/tconstruct/library/modifiers/modules/behavior/ShowOffhandModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package slimeknights.tconstruct.library.modifiers.modules.behavior; | ||
|
||
import net.minecraft.world.entity.EquipmentSlot; | ||
import slimeknights.mantle.data.GenericLoaderRegistry.IGenericLoader; | ||
import slimeknights.mantle.data.GenericLoaderRegistry.SingletonLoader; | ||
import slimeknights.tconstruct.library.modifiers.ModifierEntry; | ||
import slimeknights.tconstruct.library.modifiers.ModifierHook; | ||
import slimeknights.tconstruct.library.modifiers.TinkerHooks; | ||
import slimeknights.tconstruct.library.modifiers.hook.armor.EquipmentChangeModifierHook; | ||
import slimeknights.tconstruct.library.modifiers.modules.ModifierModule; | ||
import slimeknights.tconstruct.library.tools.capability.TinkerDataKeys; | ||
import slimeknights.tconstruct.library.tools.context.EquipmentChangeContext; | ||
import slimeknights.tconstruct.library.tools.helper.ModifierUtil; | ||
import slimeknights.tconstruct.library.tools.nbt.IToolStackView; | ||
|
||
import java.util.List; | ||
|
||
/** Module to show the offhand for a tool that can interact using the offhand */ | ||
public enum ShowOffhandModule implements ModifierModule, EquipmentChangeModifierHook { | ||
INSTANCE; | ||
|
||
private static final List<ModifierHook<?>> DEFAULT_HOOKS = List.of(TinkerHooks.EQUIPMENT_CHANGE); | ||
public static final IGenericLoader<ShowOffhandModule> LOADER = new SingletonLoader<>(INSTANCE); | ||
|
||
@Override | ||
public List<ModifierHook<?>> getDefaultHooks() { | ||
return DEFAULT_HOOKS; | ||
} | ||
|
||
@Override | ||
public void onEquip(IToolStackView tool, ModifierEntry modifier, EquipmentChangeContext context) { | ||
if (context.getChangedSlot() == EquipmentSlot.CHEST) { | ||
ModifierUtil.addTotalArmorModifierLevel(tool, context, TinkerDataKeys.SHOW_EMPTY_OFFHAND, 1); | ||
} | ||
} | ||
|
||
@Override | ||
public void onUnequip(IToolStackView tool, ModifierEntry modifier, EquipmentChangeContext context) { | ||
if (context.getChangedSlot() == EquipmentSlot.CHEST) { | ||
ModifierUtil.addTotalArmorModifierLevel(tool, context, TinkerDataKeys.SHOW_EMPTY_OFFHAND, -1); | ||
} | ||
} | ||
|
||
@Override | ||
public IGenericLoader<? extends ModifierModule> getLoader() { | ||
return LOADER; | ||
} | ||
} |
Oops, something went wrong.