Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void generateItemModels(ItemModelGenerator generator) {
AETHUM_MAP_PROTOTYPE, REALIZED_AETHUM_MAP, ANTHRACITE_POWDER, RESPLENDENT_GEM,
AFFINITEA, INERT_WISP_MATTER, WISE_WISP_MATTER, VICIOUS_WISP_MATTER, DRAGON_DROP);

handheld(generator, COLLECTION_STAFF, NIMBLE_STAFF, WAND_OF_INQUIRY);
handheld(generator, COLLECTION_STAFF, NIMBLE_STAFF, TIME_STAFF, WAND_OF_INQUIRY);

generatedWithTexture(generator, Affinity.id("item/ranthracite_dust"), RANTHRACITE_WIRE.asItem());

Expand Down
123 changes: 123 additions & 0 deletions src/main/java/io/wispforest/affinity/item/TimeStaffItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package io.wispforest.affinity.item;

import io.wispforest.affinity.component.AffinityComponents;
import io.wispforest.affinity.object.AffinityItems;
import io.wispforest.affinity.object.AffinityParticleSystems;
import io.wispforest.owo.nbt.NbtKey;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameRules;
import net.minecraft.world.World;

public class TimeStaffItem extends Item implements DirectInteractionHandler {
public static final NbtKey<Mode> MODE = new NbtKey<>("Mode", NbtKey.Type.STRING.then(Mode::byId, mode -> mode.id));

public TimeStaffItem() {
super(AffinityItems.settings(AffinityItemGroup.MAIN).maxCount(1));
}

@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
if (user.isSneaking()) {
var stack = user.getStackInHand(hand);

stack.mutate(MODE, Mode::next);

return TypedActionResult.success(stack, world.isClient);
}

user.setCurrentHand(hand);
return TypedActionResult.consume(user.getStackInHand(hand));
}

@Override
public int getMaxUseTime(ItemStack stack) {
return 72000;
}

@SuppressWarnings("unchecked")
@Override
public void usageTick(World world, LivingEntity user, ItemStack stack, int remainingUseTicks) {
Mode mode = stack.get(MODE);

var aethum = AffinityComponents.PLAYER_AETHUM.get(user);
if (aethum.getAethum() < mode.aethumDrain) return;

aethum.setAethum(aethum.getAethum() - mode.aethumDrain);

if (world.isClient) return;

var res = (BlockHitResult) user.raycast(5, 0, false);

if (world.random.nextInt(4) == 0)
AffinityParticleSystems.WISP_ATTACK.spawn(world, user.getEyePos(), new AffinityParticleSystems.LineData(
Vec3d.ofCenter(res.getBlockPos()), 0xFFFFFF
));

for (int i = 0; i < mode.repeatTicks; i++) {
BlockState state = world.getBlockState(res.getBlockPos());
BlockEntity be = world.getBlockEntity(res.getBlockPos());

if (be != null) {
BlockEntityTicker<BlockEntity> ticker = state.getBlockEntityTicker(world, (BlockEntityType<BlockEntity>) be.getType());

if (ticker != null) {
ticker.tick(world, res.getBlockPos(), state, be);
}
}

if (state.hasRandomTicks()) {
int randomTickPeriod = 4096 / world.getGameRules().getInt(GameRules.RANDOM_TICK_SPEED);

if (world.random.nextInt(randomTickPeriod) == 0) {
state.randomTick((ServerWorld) world, res.getBlockPos(), world.random);
}
}
}
}

@Override
public boolean shouldHandleInteraction(World world, BlockPos pos, BlockState state) {
return true;
}

public enum Mode {
NORMAL("normal", 1, 0.1f),
FAST("fast", 3, 0.4f),
LUDICROUS("ludicrous", 7, 1);

private final String id;
private final int repeatTicks;
private final float aethumDrain;

Mode(String id, int repeatTicks, float aethumDrain) {
this.id = id;
this.repeatTicks = repeatTicks;
this.aethumDrain = aethumDrain;
}

public Mode next() {
return Mode.values()[(this.ordinal() + 1) % Mode.values().length];
}

public static Mode byId(String id) {
return switch (id) {
default -> Mode.NORMAL;
case "fast" -> Mode.FAST;
case "ludicrous" -> Mode.LUDICROUS;
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class AffinityItems implements ItemRegistryContainer {
public static final Item GEOLOGICAL_RESONATOR = new GeologicalResonatorItem();
public static final Item COLLECTION_STAFF = new CollectionStaffItem();
public static final Item NIMBLE_STAFF = new NimbleStaffItem();
public static final Item TIME_STAFF = new TimeStaffItem();

public static final Item AZALEA_FLOWERS = new Item(settings(AffinityItemGroup.NATURE).food(new FoodComponent.Builder().hunger(2).saturationModifier(.5f)
.statusEffect(new StatusEffectInstance(AffinityStatusEffects.DRIPPING, 1200, 0, false, false, true), 1).build()));
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/affinity/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"item.affinity.geological_resonator": "Geological Resonator",
"item.affinity.collection_staff": "Collection Staff",
"item.affinity.nimble_staff": "Nimble Staff",
"item.affinity.time_staff": "Time Staff",
"item.affinity.aethum_flux_bottle": "Bottle of Aethum Flux",
"item.affinity.resplendent_gem": "Resplendent Gem",
"item.affinity.echo_shard": "Echo Shard",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "affinity:item/time_staff"
}
}