Skip to content

Commit

Permalink
Make spitting apply knockback and allow punch to work on it
Browse files Browse the repository at this point in the history
Spitting projectiles now apply a bit of knockback, which can be boosted with punch, same rates as arrows
Punch now works on any ranged weapon, though it won't do anything for slings, probably too much to make punch add to power there
While changing knockback stuff, merged the two recipes for knocback between chestplates and melee, holdover from when those were distinct modiiers
  • Loading branch information
KnightMiner committed Dec 21, 2023
1 parent 76df1d5 commit c1977ac
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"type": "tconstruct:modifier_salvage",
"tools": {
"tag": "tconstruct:modifiable/melee"
},
"tools": [
{
"tag": "tconstruct:modifiable/melee"
},
{
"tag": "tconstruct:modifiable/armor/chestplate"
}
],
"slots": {
"upgrades": 1
},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "tconstruct:modifier_salvage",
"tools": {
"tag": "tconstruct:modifiable/ranged/bows"
"tag": "tconstruct:modifiable/ranged"
},
"slots": {
"upgrades": 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
"item": "minecraft:slime_block"
}
],
"tools": {
"tag": "tconstruct:modifiable/melee"
},
"tools": [
{
"tag": "tconstruct:modifiable/melee"
},
{
"tag": "tconstruct:modifiable/armor/chestplate"
}
],
"slots": {
"upgrades": 1
},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
],
"tools": {
"tag": "tconstruct:modifiable/ranged/bows"
"tag": "tconstruct:modifiable/ranged"
},
"slots": {
"upgrades": 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ private void addModifierRecipes(Consumer<FinishedRecipe> consumer) {
.addInput(TinkerWorld.slime.get(SlimeType.EARTH))
.setMaxLevel(3) // max +2.5 knockback points (knockback 5) (whatever that number means in vanilla)
.setSlots(SlotType.UPGRADE, 1)
.setTools(TinkerTags.Items.MELEE)
.setTools(ingredientFromTags(TinkerTags.Items.MELEE, TinkerTags.Items.CHESTPLATES))
.saveSalvage(consumer, prefix(TinkerModifiers.knockback, upgradeSalvage))
.save(consumer, prefix(TinkerModifiers.knockback, upgradeFolder));
ModifierRecipeBuilder.modifier(TinkerModifiers.padded)
Expand Down Expand Up @@ -527,7 +527,7 @@ private void addModifierRecipes(Consumer<FinishedRecipe> consumer) {
.addInput(TinkerWorld.slime.get(SlimeType.SKY))
.setMaxLevel(5) // vanilla caps at 2, that is boring
.setSlots(SlotType.UPGRADE, 1)
.setTools(TinkerTags.Items.BOWS) // TODO: can we make punch work on spitting?
.setTools(TinkerTags.Items.RANGED)
.saveSalvage(consumer, prefix(TinkerModifiers.punch, upgradeSalvage))
.save(consumer, prefix(TinkerModifiers.punch, upgradeFolder));
ModifierRecipeBuilder.modifier(TinkerModifiers.impaling)
Expand Down Expand Up @@ -773,15 +773,6 @@ private void addModifierRecipes(Consumer<FinishedRecipe> consumer) {
.setSlots(SlotType.UPGRADE, 1)
.saveSalvage(consumer, prefix(TinkerModifiers.itemFrame, upgradeSalvage))
.save(consumer, prefix(TinkerModifiers.itemFrame, upgradeFolder));
// upgrade - chestplate
ModifierRecipeBuilder.modifier(TinkerModifiers.knockback)
.setTools(TinkerTags.Items.CHESTPLATES)
.addInput(Items.PISTON)
.addInput(TinkerWorld.slime.get(SlimeType.EARTH))
.setSlots(SlotType.UPGRADE, 1)
.setMaxLevel(3)
.saveSalvage(consumer, wrap(TinkerModifiers.knockback, upgradeSalvage, "_armor"))
.save(consumer, wrap(TinkerModifiers.knockback, upgradeFolder, "_armor"));
// upgrade - leggings
hasteRecipes(consumer, ModifierIds.speedy, Ingredient.of(TinkerTags.Items.LEGGINGS), 3, upgradeFolder, upgradeSalvage);
// leaping lets you disable skyslime geodes in case you don't like fun
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
Expand All @@ -18,6 +19,7 @@
import net.minecraft.world.item.UseAnim;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.FluidStack;
import slimeknights.tconstruct.fluids.TinkerFluids;
Expand Down Expand Up @@ -152,10 +154,12 @@ public boolean onStoppedUsing(IToolStackView tool, ModifierEntry modifier, Livin

/** Projectile entity for spitting */
public static class FluidSpitEntity extends LlamaSpit {
@Setter
private int power = 1;
private static final EntityDataAccessor<FluidStack> FLUID = SynchedEntityData.defineId(FluidSpitEntity.class, TinkerFluids.FLUID_DATA_SERIALIZER);

@Setter
private int power = 1;
@Setter @Getter
private int knockback = 1;
public FluidSpitEntity(EntityType<? extends FluidSpitEntity> type, Level level) {
super(type, level);
}
Expand Down Expand Up @@ -183,12 +187,19 @@ protected void onHitEntity(EntityHitResult result) {
FluidStack fluid = getFluid();
if (!level.isClientSide && !fluid.isEmpty() && getOwner() instanceof LivingEntity living) {
SpillingFluid recipe = SpillingFluidManager.INSTANCE.find(fluid.getFluid());
Entity target = result.getEntity();
if (recipe.hasEffects()) {
Entity target = result.getEntity();
recipe.applyEffects(fluid.copy(), power, new ToolAttackContext(
living, living instanceof Player p ? p : null, InteractionHand.MAIN_HAND,
target, ToolAttackUtil.getLivingEntity(target), false, 1.0f, false));
}
// apply knockback to the entity regardless of fluid type
if (knockback > 0) {
Vec3 vec3 = this.getDeltaMovement().multiply(1, 0, 1).normalize().scale(knockback * 0.6);
if (vec3.lengthSqr() > 0) {
target.push(vec3.x, 0.1, vec3.z);
}
}
}
}

Expand All @@ -205,6 +216,7 @@ protected void defineSynchedData() {
protected void addAdditionalSaveData(CompoundTag nbt) {
super.addAdditionalSaveData(nbt);
nbt.putInt("power", power);
nbt.putInt("knockback", knockback);
FluidStack fluid = getFluid();
if (!fluid.isEmpty()) {
nbt.put("fluid", fluid.writeToNBT(new CompoundTag()));
Expand All @@ -215,6 +227,7 @@ protected void addAdditionalSaveData(CompoundTag nbt) {
protected void readAdditionalSaveData(CompoundTag nbt) {
super.readAdditionalSaveData(nbt);
this.power = nbt.getInt("power");
this.knockback = nbt.getInt("knockback");
setFluid(FluidStack.loadFluidStackFromNBT(nbt.getCompound("fluid")));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import slimeknights.tconstruct.library.modifiers.util.ModifierHookMap.Builder;
import slimeknights.tconstruct.library.tools.nbt.IToolStackView;
import slimeknights.tconstruct.library.tools.nbt.NamespacedNBT;
import slimeknights.tconstruct.tools.modifiers.ability.fluid.SpittingModifier.FluidSpitEntity;

import javax.annotation.Nullable;

Expand All @@ -23,6 +24,8 @@ protected void registerHooks(Builder hookBuilder) {
public void onProjectileLaunch(IToolStackView tool, ModifierEntry modifier, LivingEntity shooter, Projectile projectile, @Nullable AbstractArrow arrow, NamespacedNBT persistentData, boolean primary) {
if (arrow != null) {
arrow.setKnockback(modifier.getLevel());
} else if (projectile instanceof FluidSpitEntity spit) {
spit.setKnockback(spit.getKnockback() + modifier.getLevel());
}
}
}

0 comments on commit c1977ac

Please sign in to comment.