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

feat: re-write Toss with new augments #1330

Merged
merged 2 commits into from
Jul 21, 2024
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
2 changes: 1 addition & 1 deletion src/generated/resources/assets/ars_nouveau/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@
"ars_nouveau.glyph_desc.glyph_summon_undead": "Summons a number of Skeleton allies that will attack nearby hostile enemies. These Skeletons will last a short time until they begin to take damage, but time may be extended with the Extend Time augment. Additionally, their summoned weapons are changed using augments, use Amplify to give it a better sword, or Pierce to give it a bow. Adding Split after the effect will add to the number of summoned skeletons.",
"ars_nouveau.glyph_desc.glyph_summon_vex": "Summons three Vex allies that will attack nearby hostile enemies. These Vex will last a short time until they begin to take damage, but time may be extended with the Extend Time augment.",
"ars_nouveau.glyph_desc.glyph_summon_wolves": "Summons two wolves that will fight with you. Extend Time will increase the amount of time on the summons. Applies Summoning Sickness to the caster, preventing other summoning magic.",
"ars_nouveau.glyph_desc.glyph_toss": "Causes the caster to place an item from their inventory to a location. If this glyph is used on an inventory, the item will attempt to be inserted into it.",
"ars_nouveau.glyph_desc.glyph_toss": "Causes the caster to place an item from their inventory to a location. If this glyph is used on an inventory, the item will attempt to be inserted into it. Toss throws 64 items by default. Dampen will halve the amount each time. Amplify will double the amount each time. Randomize will select a random stack.",
"ars_nouveau.glyph_desc.glyph_touch": "Applies spells at the block or entity that is targeted.",
"ars_nouveau.glyph_desc.glyph_underfoot": "Targets the spell on the block beneath the player.",
"ars_nouveau.glyph_desc.glyph_wall": "Creates a lingering wall that applies spells on nearby entities for a short time. Applying Sensitive will make this spell target blocks instead. AOE will expand the effective range, Accelerate will cast spells faster, Dampen will ignore gravity, and Extend Time will increase the duration.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import com.hollingsworth.arsnouveau.api.spell.*;
import com.hollingsworth.arsnouveau.api.spell.wrapped_caster.TileCaster;
import com.hollingsworth.arsnouveau.common.lib.GlyphLib;
import com.hollingsworth.arsnouveau.common.spell.augment.AugmentAmplify;
import com.hollingsworth.arsnouveau.common.spell.augment.AugmentDampen;
import com.hollingsworth.arsnouveau.common.spell.augment.AugmentExtract;
import com.hollingsworth.arsnouveau.common.spell.augment.AugmentRandomize;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
Expand All @@ -20,6 +24,9 @@
import org.jetbrains.annotations.NotNull;

import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

public class EffectToss extends AbstractEffect {

Expand All @@ -29,33 +36,56 @@ public EffectToss() {
super(GlyphLib.EffectTossID, "Toss");
}

public int getStackSize(SpellStats spellStats) {
if (spellStats.hasBuff(AugmentExtract.INSTANCE)) return 1;

double amp = spellStats.getAmpMultiplier();

return (int) (64 * Math.pow(2, amp));
}

private ExtractedStack extractItem(InventoryManager inventory, Predicate<ItemStack> predicate, int count, boolean randomized) {
if (randomized) {
return inventory.extractRandomItem(predicate, count);
}
return inventory.extractItem(predicate, count);
}

@Override
public void onResolveEntity(EntityHitResult rayTraceResult, Level world, @NotNull LivingEntity shooter, SpellStats spellStats, SpellContext spellContext, SpellResolver resolver) {
BlockPos pos = rayTraceResult.getEntity().blockPosition();
summonStack(shooter, spellContext, world, pos, new InventoryManager(spellContext.getCaster()));
summonStack(shooter, spellContext, spellStats, world, pos, new InventoryManager(spellContext.getCaster()));
}

public void summonStack(LivingEntity shooter, SpellContext context, Level world, BlockPos pos, InventoryManager inventoryManager) {
ExtractedStack casterStack = inventoryManager.extractItem((i) ->{
// Let tiles export items regardless of the shooter. Runes mimic the player as the shooter.
if(!i.isEmpty() && context.getCaster() instanceof TileCaster){
return true;
}
if (!i.isEmpty() && shooter instanceof Player) {
return !ItemStack.matches(shooter.getMainHandItem(), i);
}
return false;
}, 64);
world.addFreshEntity(new ItemEntity(world, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, casterStack.stack.copy()));
casterStack.stack.setCount(0);
public void processStacks(LivingEntity shooter, SpellContext context, SpellStats spellStats, InventoryManager inventoryManager, Consumer<ExtractedStack> consumer) {
int amount = getStackSize(spellStats);
while (amount > 0) {
int size = Math.min(amount, 64);
ExtractedStack casterStack = this.extractItem(inventoryManager, (i) -> {
if (i.isEmpty()) return false;
if (context.getCaster() instanceof TileCaster) {
return true;
}
return shooter instanceof Player && !ItemStack.matches(shooter.getMainHandItem(), i);
}, size, spellStats.isRandomized());
consumer.accept(casterStack);
amount -= size;
}
}

public void summonStack(LivingEntity shooter, SpellContext context, SpellStats spellStats, Level world, BlockPos pos, InventoryManager inventoryManager) {
this.processStacks(shooter, context, spellStats, inventoryManager, stack -> {
world.addFreshEntity(new ItemEntity(world, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, stack.stack.copy()));
stack.stack.setCount(0);
});
}

@Override
public void onResolveBlock(BlockHitResult rayTraceResult, Level world, @NotNull LivingEntity shooter, SpellStats spellStats, SpellContext spellContext, SpellResolver resolver) {
BlockPos pos = rayTraceResult.getBlockPos().relative(rayTraceResult.getDirection());
InventoryManager manager = new InventoryManager(spellContext.getCaster());
if (world.getBlockEntity(rayTraceResult.getBlockPos()) == null) {
summonStack(shooter, spellContext, world, pos, manager);
summonStack(shooter, spellContext, spellStats, world, pos, manager);
return;
}
BlockEntity tileEntity = world.getBlockEntity(rayTraceResult.getBlockPos());
Expand All @@ -64,31 +94,11 @@ public void onResolveBlock(BlockHitResult rayTraceResult, Level world, @NotNull
if (targetInv == null) {
return;
}
// Extracts a stack from the caster that can be inserted into the target inventory
ExtractedStack casterStack = manager.extractByAmount(stackToExtract ->{
if(stackToExtract.isEmpty())
return 0;
if (shooter instanceof Player && ItemStack.matches(shooter.getMainHandItem(), stackToExtract)) {
return 0;
}
for (int i = 0; i < targetInv.getSlots(); i++) {
ItemStack stackInTarget = targetInv.getStackInSlot(i);
if(stackInTarget.isEmpty()){
return targetInv.getSlotLimit(i);
}else if (ItemHandlerHelper.canItemStacksStack(stackInTarget, stackToExtract)) {
int origSize = stackToExtract.getCount();
ItemStack simReturn = targetInv.insertItem(i, stackToExtract, true);
int maxRoom = origSize - simReturn.getCount();
int adjustedMax = Math.min(maxRoom, targetInv.getSlotLimit(i));
if(adjustedMax > 0) {
return adjustedMax;
}
}
}
return 0;

this.processStacks(shooter, spellContext, spellStats, manager, (stack) -> {
stack.stack = ItemHandlerHelper.insertItemStacked(targetInv, stack.getStack(), false);
stack.returnOrDrop(world, pos);
});
casterStack.stack = ItemHandlerHelper.insertItemStacked(targetInv, casterStack.getStack(), false);
casterStack.returnOrDrop(world, pos);
}

@NotNull
Expand All @@ -104,12 +114,12 @@ public int getDefaultManaCost() {

@Override
public String getBookDescription() {
return "Causes the caster to place an item from their inventory to a location. If this glyph is used on an inventory, the item will attempt to be inserted into it.";
return "Causes the caster to place an item from their inventory to a location. If this glyph is used on an inventory, the item will attempt to be inserted into it. Toss throws 64 items by default. Dampen will halve the amount each time. Amplify will double the amount each time. Randomize will select a random stack.";
}

@NotNull
@Override
public Set<AbstractAugment> getCompatibleAugments() {
return augmentSetOf();
return augmentSetOf(AugmentExtract.INSTANCE, AugmentRandomize.INSTANCE, AugmentDampen.INSTANCE, AugmentAmplify.INSTANCE);
}
}