Skip to content

Commit

Permalink
Implement sling modifiers
Browse files Browse the repository at this point in the history
Will lead to the removal of the sling items in 1.19, since they are now implemented in a superior way as modifiers that work on any tool
All sling modifiers can have reduced drawspeed via quick draw and increased strength via power and any velocity boosting modifiers. They also consider accuracy, which will be fun for a future tinkers things tool
Other than warping, they also all consider knockback to boost their effect, allowing non-staffs to boost their effect

Flinging (earth), springing (sky), and warping (ender) work about the same as the slings
Bonking (ichor) has an extra particle, a new sound, and deals melee damage using the tool's modifiers if the tool is a melee weapon (fully reimplementing the old frypan smash attack)
  • Loading branch information
KnightMiner committed Nov 26, 2023
1 parent b465e77 commit 894ad7e
Show file tree
Hide file tree
Showing 41 changed files with 895 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"type": "tconstruct:modifier",
"inputs": [
{
"tag": "forge:ingots/iron"
},
{
"item": "tconstruct:ichor_slime_crystal"
},
{
"tag": "forge:ingots/iron"
},
{
"item": "tconstruct:ichor_congealed_slime"
},
{
"item": "tconstruct:ichor_congealed_slime"
}
],
"tools": {
"tag": "tconstruct:modifiable/interactable/right"
},
"slots": {
"abilities": 1
},
"allow_crystal": true,
"result": {
"name": "tconstruct:bonking",
"level": 1
},
"max_level": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"type": "tconstruct:modifier",
"inputs": [
{
"tag": "forge:string"
},
{
"item": "tconstruct:earth_slime_crystal"
},
{
"tag": "forge:string"
},
{
"item": "tconstruct:earth_congealed_slime"
},
{
"item": "tconstruct:earth_congealed_slime"
}
],
"tools": {
"tag": "tconstruct:modifiable/interactable/right"
},
"slots": {
"abilities": 1
},
"allow_crystal": true,
"result": {
"name": "tconstruct:flinging",
"level": 1
},
"max_level": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"type": "tconstruct:modifier",
"inputs": [
{
"tag": "forge:feathers"
},
{
"item": "tconstruct:sky_slime_crystal"
},
{
"tag": "forge:feathers"
},
{
"item": "tconstruct:sky_congealed_slime"
},
{
"item": "tconstruct:sky_congealed_slime"
}
],
"tools": {
"tag": "tconstruct:modifiable/interactable/right"
},
"slots": {
"abilities": 1
},
"allow_crystal": true,
"result": {
"name": "tconstruct:springing",
"level": 1
},
"max_level": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"type": "tconstruct:modifier",
"inputs": [
{
"tag": "forge:ender_pearls"
},
{
"item": "tconstruct:ender_slime_crystal"
},
{
"tag": "forge:ender_pearls"
},
{
"item": "tconstruct:ender_congealed_slime"
},
{
"item": "tconstruct:ender_congealed_slime"
}
],
"tools": {
"tag": "tconstruct:modifiable/interactable/right"
},
"slots": {
"abilities": 1
},
"allow_crystal": true,
"result": {
"name": "tconstruct:warping",
"level": 1
},
"max_level": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "tconstruct:modifier_salvage",
"tools": {
"tag": "tconstruct:modifiable/interactable/right"
},
"slots": {
"abilities": 1
},
"modifier": "tconstruct:bonking",
"min_level": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "tconstruct:modifier_salvage",
"tools": {
"tag": "tconstruct:modifiable/interactable/right"
},
"slots": {
"abilities": 1
},
"modifier": "tconstruct:flinging",
"min_level": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "tconstruct:modifier_salvage",
"tools": {
"tag": "tconstruct:modifiable/interactable/right"
},
"slots": {
"abilities": 1
},
"modifier": "tconstruct:springing",
"min_level": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "tconstruct:modifier_salvage",
"tools": {
"tag": "tconstruct:modifiable/interactable/right"
},
"slots": {
"abilities": 1
},
"modifier": "tconstruct:warping",
"min_level": 1
}
2 changes: 1 addition & 1 deletion src/main/java/slimeknights/tconstruct/common/Sounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum Sounds {
SHURIKEN_THROW("throw.shuriken"),
LONGBOW_CHARGE("longbow.charge"),
CRYSTALSHOT,
BONK,

// modifiers
NECROTIC_HEAL,
Expand All @@ -53,7 +54,6 @@ public enum Sounds {
EQUIP_PLATE("equip.plate"),

// unused
FRYING_PAN_BOING("frypan_hit"),
TOY_SQUEAK,
CROSSBOW_RELOAD,
STONE_HIT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public final class TinkerGadgets extends TinkerModule {
*/
public static final ItemObject<PiggyBackPackItem> piggyBackpack = ITEMS.register("piggy_backpack", () -> new PiggyBackPackItem(new Properties().tab(TinkerGadgets.TAB_GADGETS).stacksTo(16)));
public static final EnumObject<FrameType,FancyItemFrameItem> itemFrame = ITEMS.registerEnum(FrameType.values(), "item_frame", (type) -> new FancyItemFrameItem(GADGET_PROPS, (world, pos, dir) -> new FancyItemFrameEntity(world, pos, dir, type)));
// slime tools
// slings - TODO: remove in 1.19, replaced by slimestaffs & flinging/springing/bonking/warping
private static final Item.Properties SLING_PROPS = new Item.Properties().tab(TAB_GADGETS).stacksTo(1).durability(250);
public static final EnumObject<SlimeType, BaseSlimeSlingItem> slimeSling = new EnumObject.Builder<SlimeType, BaseSlimeSlingItem>(SlimeType.class)
.put(SlimeType.EARTH, ITEMS.register("earth_slime_sling", () -> new EarthSlimeSlingItem(SLING_PROPS)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.level.Level;
import slimeknights.tconstruct.library.utils.SlimeBounceHandler;
import slimeknights.tconstruct.shared.block.SlimeType;

import net.minecraft.world.item.Item.Properties;

public class EarthSlimeSlingItem extends BaseSlimeSlingItem {

public EarthSlimeSlingItem(Properties props) {
Expand All @@ -22,12 +20,11 @@ public EarthSlimeSlingItem(Properties props) {
/** Called when the player stops using an Item (stops holding the right mouse button). */
@Override
public void releaseUsing(ItemStack stack, Level worldIn, LivingEntity entityLiving, int timeLeft) {
if (!entityLiving.isOnGround() || !(entityLiving instanceof Player)) {
if (!entityLiving.isOnGround() || !(entityLiving instanceof Player player)) {
return;
}

// check if player was targeting a block
Player player = (Player) entityLiving;
BlockHitResult mop = getPlayerPOVHitResult(worldIn, player, ClipContext.Fluid.NONE);
if (mop.getType() == HitResult.Type.BLOCK) {
// we fling the inverted player look vector
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package slimeknights.tconstruct.gadgets.item.slimesling;

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.MinecraftForge;
import slimeknights.tconstruct.common.Sounds;
import slimeknights.tconstruct.library.events.teleport.SlimeslingTeleportEvent;
import slimeknights.tconstruct.shared.block.SlimeType;

import net.minecraft.world.item.Item.Properties;

public class EnderSlimeSlingItem extends BaseSlimeSlingItem {

public EnderSlimeSlingItem(Properties props) {
Expand All @@ -23,11 +21,10 @@ public EnderSlimeSlingItem(Properties props) {
/** Called when the player stops using an Item (stops holding the right mouse button). */
@Override
public void releaseUsing(ItemStack stack, Level worldIn, LivingEntity entityLiving, int timeLeft) {
if (worldIn.isClientSide || !(entityLiving instanceof ServerPlayer)) {
if (worldIn.isClientSide || !(entityLiving instanceof ServerPlayer player)) {
return;
}

ServerPlayer player = (ServerPlayer) entityLiving;
float f = getForce(stack, timeLeft);

Vec3 look = player.getLookAngle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import slimeknights.tconstruct.library.utils.SlimeBounceHandler;
import slimeknights.tconstruct.shared.block.SlimeType;

import net.minecraft.world.item.Item.Properties;

public class SkySlimeSlingItem extends BaseSlimeSlingItem {
private static final float DEGREE_TO_RAD = (float) Math.PI / 180.0F;

Expand All @@ -33,19 +31,17 @@ public float getForce(ItemStack stack, int timeLeft) {
/** Called when the player stops using an Item (stops holding the right mouse button). */
@Override
public void releaseUsing(ItemStack stack, Level worldIn, LivingEntity entityLiving, int timeLeft) {
if (!(entityLiving instanceof Player)) {
if (!(entityLiving instanceof Player player)) {
return;
}

Player player = (Player) entityLiving;

// don't allow free flight when using an elytra, should use fireworks
if (player.isFallFlying()) {
return;
}

player.causeFoodExhaustion(0.2F);
player.setSprinting(true);
//player.setSprinting(true);

float f = getForce(stack, timeLeft);
float speed = f / 3F;
Expand All @@ -55,7 +51,6 @@ public void releaseUsing(ItemStack stack, Level worldIn, LivingEntity entityLivi
(1 + look.y) * speed / 2f,
(look.z * speed));

onSuccess(player, stack);
SlimeBounceHandler.addBounceHandler(player);
if (!worldIn.isClientSide) {
player.getCooldowns().addCooldown(stack.getItem(), 3);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package slimeknights.tconstruct.library.events.teleport;

import lombok.Getter;
import net.minecraft.world.entity.Entity;
import net.minecraftforge.event.entity.EntityTeleportEvent;
import net.minecraftforge.eventbus.api.Cancelable;
import slimeknights.tconstruct.library.modifiers.ModifierEntry;
import slimeknights.tconstruct.library.tools.nbt.IToolStackView;

/** Event fired when an entity teleports using the ender sling modifier */
@Cancelable
public class SlingModifierTeleportEvent extends EntityTeleportEvent {
@Getter
private final IToolStackView tool;
@Getter
private final ModifierEntry entry;
public SlingModifierTeleportEvent(Entity entity, double targetX, double targetY, double targetZ, IToolStackView tool, ModifierEntry entry) {
super(entity, targetX, targetY, targetZ);
this.tool = tool;
this.entry = entry;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import slimeknights.tconstruct.library.tools.capability.TinkerDataKeys;
import slimeknights.tconstruct.library.tools.context.EquipmentChangeContext;
import slimeknights.tconstruct.library.tools.context.ToolHarvestContext;
import slimeknights.tconstruct.library.tools.item.ModifiableLauncherItem;
import slimeknights.tconstruct.library.tools.nbt.IModDataView;
import slimeknights.tconstruct.library.tools.nbt.IToolStackView;
import slimeknights.tconstruct.library.tools.nbt.ModifierNBT;
Expand Down Expand Up @@ -343,6 +344,22 @@ public static void startUsingItem(IToolStackView tool, ModifierId modifier, Livi
living.startUsingItem(hand);
}

/** Starts using the given hand with the given modifier, will allow filtering modifier hooks so only the one for the given modifier is called */
public static void startUsingItemWithDrawtime(IToolStackView tool, ModifierId modifier, LivingEntity living, InteractionHand hand, float speedFactor) {
tool.getPersistentData().putInt(ModifiableLauncherItem.KEY_DRAWTIME, (int)Math.ceil(20f * speedFactor / ConditionalStatModifierHook.getModifiedStat(tool, living, ToolStats.DRAW_SPEED)));
startUsingItem(tool, modifier, living, hand);
}

/** Scales the drawtime from the persistent data like a bow */
public static float getToolCharge(IToolStackView tool, float chargeTime) {
float charge = chargeTime / tool.getPersistentData().getInt(ModifiableLauncherItem.KEY_DRAWTIME);
charge = (charge * charge + charge * 2) / 3;
if (charge > 1) {
charge = 1;
}
return charge;
}

/** Gets the currently active modifier, or null if none is active */
@Nullable
public static ModifierEntry getActiveModifier(IToolStackView tool) {
Expand Down

0 comments on commit 894ad7e

Please sign in to comment.