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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ dependencies {

modLocalRuntime "com.ptsmods:devlogin:2.0"
modLocalRuntime "maven.modrinth:emoji-type:1.0.3"
modLocalRuntime "maven.modrinth:lazydfu:0.1.2"

modLocalRuntime ("io.vram:canvas-fabric-mc118:${project.canvas_version}") {
exclude group: "net.fabricmc.fabric-api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,16 @@ public void tickServer() {

world.playSound(null, pos, SoundEvents.BLOCK_BREWING_STAND_BREW, SoundCategory.BLOCKS, 1, 1);

this.storedPotion = cachedRecipe.craftPotion(items);

for (var ingredient : cachedRecipe.getItemInputs()) {
for (int i = 0; i < items.size(); i++) {
if (!ingredient.test(items.get(i))) continue;
if (!ingredient.ingredient().test(items.get(i))) continue;
items.set(i, ItemStack.EMPTY);
break;
}
}

this.storedPotion = new PotionMixture(cachedRecipe.getPotionOutput());
this.markDirty(true);

processTick = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class PotionMixingDisplay implements Display {
public PotionMixingDisplay(PotionMixingRecipe recipe) {

final var inputBuilder = new ImmutableList.Builder<EntryIngredient>();
recipe.getItemInputs().forEach(ingredient -> inputBuilder.add(EntryIngredients.ofIngredient(ingredient)));
recipe.getItemInputs().forEach(ingredient -> inputBuilder.add(EntryIngredients.ofIngredient(ingredient.ingredient())));
inputs = inputBuilder.build();

final var potionStack = new ItemStack(Items.POTION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dev.onyxstudios.cca.api.v3.entity.RespawnCopyStrategy;
import io.wispforest.affinity.Affinity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;

public class AffinityComponents implements EntityComponentInitializer, ChunkComponentInitializer {

Expand All @@ -21,11 +22,15 @@ public class AffinityComponents implements EntityComponentInitializer, ChunkComp
public static final ComponentKey<EntityFlagComponent> ENTITY_FLAGS =
ComponentRegistry.getOrCreate(Affinity.id("entity_flags"), EntityFlagComponent.class);

public static final ComponentKey<TransportationComponent> TRANSPORTATION =
ComponentRegistry.getOrCreate(Affinity.id("transportation"), TransportationComponent.class);

@Override
public void registerEntityComponentFactories(EntityComponentFactoryRegistry registry) {
registry.registerForPlayers(GLOWING_COLOR, GlowingColorComponent::new, RespawnCopyStrategy.NEVER_COPY);
registry.registerForPlayers(PLAYER_AETHUM, PlayerAethumComponent::new, RespawnCopyStrategy.ALWAYS_COPY);
registry.registerFor(Entity.class, ENTITY_FLAGS, entity -> new EntityFlagComponent());
registry.registerFor(LivingEntity.class, TRANSPORTATION, player -> new TransportationComponent());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.wispforest.affinity.component;

import dev.onyxstudios.cca.api.v3.component.Component;
import io.wispforest.owo.util.VectorSerializer;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

public class TransportationComponent implements Component {
private Identifier world = World.OVERWORLD.getValue();
private Vec3d pos = Vec3d.ZERO;

public TransportationComponent() {

}

@Override
public void readFromNbt(NbtCompound tag) {
world = new Identifier(tag.getString("World"));
pos = VectorSerializer.get(tag, "Pos");
}

@Override
public void writeToNbt(NbtCompound tag) {
tag.putString("World", world.toString());
VectorSerializer.store(pos, tag, "Pos");
}

public Identifier getWorld() {
return world;
}

public void setWorld(Identifier world) {
this.world = world;
}

public Vec3d getPos() {
return pos;
}

public void setPos(Vec3d pos) {
this.pos = pos;
}
}
55 changes: 55 additions & 0 deletions src/main/java/io/wispforest/affinity/item/EchoShardItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.wispforest.affinity.item;

import io.wispforest.affinity.object.AffinityItems;
import io.wispforest.owo.util.NbtKey;
import io.wispforest.owo.util.VectorSerializer;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class EchoShardItem extends Item {
public static final NbtKey<Vec3d> POS = new NbtKey<>("Pos", NbtKey.Type.of(NbtElement.LIST_TYPE, VectorSerializer::get, (tag, s, vec3d) -> VectorSerializer.store(vec3d, tag, s)));
public static final NbtKey<Identifier> WORLD = new NbtKey<>("World", NbtKey.Type.of(NbtElement.STRING_TYPE, (tag, s) -> new Identifier(tag.getString(s)), (tag, s, id) -> tag.putString(s, id.toString())));

public EchoShardItem() {
super(AffinityItems.settings(0));
}

public static void formatLocationTooltip(NbtCompound data, List<Text> tooltip) {
var pos = POS.get(data);
var targetWorld = WORLD.get(data);
var worldText = new TranslatableText("dimension." + targetWorld.getNamespace() + "." + targetWorld.getPath());

tooltip.add(new TranslatableText("text.affinity.echo_shard_location", worldText, (int)pos.x, (int)pos.y, (int)pos.z));
}

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

POS.put(stack.getOrCreateNbt(), user.getPos());
WORLD.put(stack.getOrCreateNbt(), world.getRegistryKey().getValue());

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

@Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
if (stack.hasNbt() && stack.getNbt().contains("Pos", NbtElement.LIST_TYPE)) {
formatLocationTooltip(stack.getNbt(), tooltip);
}
}
}
38 changes: 38 additions & 0 deletions src/main/java/io/wispforest/affinity/misc/EntityTeleporter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.wispforest.affinity.misc;

import io.wispforest.owo.ops.WorldOps;
import net.minecraft.entity.Entity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Vec3d;

public final class EntityTeleporter {
private EntityTeleporter() {

}

@SuppressWarnings("unchecked")
public static <E extends Entity> E teleport(E entity, ServerWorld to, Vec3d pos, float yaw, float pitch) {
if (entity instanceof ServerPlayerEntity player) {
WorldOps.teleportToWorld(player, to, pos, yaw, pitch);
}

if (entity.getEntityWorld() != to) {
entity.detach();
E newEntity = (E) entity.getType().create(to);

newEntity.copyFrom(entity);
newEntity.refreshPositionAndAngles(pos.x, pos.y, pos.z, yaw, pitch);
newEntity.setHeadYaw(yaw);
to.onDimensionChanged(newEntity);
entity.remove(Entity.RemovalReason.CHANGED_DIMENSION);

return newEntity;
} else {
entity.refreshPositionAndAngles(pos.x, pos.y, pos.z, yaw, pitch);
entity.setHeadYaw(yaw);

return entity;
}
}
}
9 changes: 9 additions & 0 deletions src/main/java/io/wispforest/affinity/misc/MixinHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import io.wispforest.affinity.Affinity;
import io.wispforest.affinity.enchantment.impl.BerserkerEnchantment;
import io.wispforest.affinity.enchantment.template.AffinityDamageEnchantment;
import io.wispforest.affinity.statuseffects.AffinityStatusEffect;
import io.wispforest.affinity.statuseffects.ImpendingDoomStatusEffect;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.potion.PotionUtil;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -48,4 +51,10 @@ public static boolean isDoomPotion(ItemStack stack) {
return PotionUtil.getPotion(stack) == Registry.POTION.get(IMPENDING_DOOM_ID);
}

public static void tryInvokePotionApplied(StatusEffectInstance effect, LivingEntity target, NbtCompound data) {
if (effect.getEffectType() instanceof AffinityStatusEffect ase) {
ase.onPotionApplied(target, data);
}
}

}
26 changes: 26 additions & 0 deletions src/main/java/io/wispforest/affinity/misc/ServerTaskScheduler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.wispforest.affinity.misc;

import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.server.MinecraftServer;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public final class ServerTaskScheduler {
private static final List<Consumer<MinecraftServer>> TASKS = new ArrayList<>();

static {
ServerTickEvents.END_SERVER_TICK.register(server -> {
for (var task : TASKS) {
task.accept(server);
}

TASKS.clear();
});
}

public static void scheduleTask(Consumer<MinecraftServer> task) {
TASKS.add(task);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,32 @@
*/
public class PotionMixture {

public static final PotionMixture EMPTY = new PotionMixture(Potions.EMPTY, ImmutableList.of(), true);
public static final PotionMixture EMPTY = new PotionMixture(Potions.EMPTY, ImmutableList.of(), true, null);
public static final Potion DUBIOUS_POTION = new Potion("dubious");

private final Potion basePotion;
private final List<StatusEffectInstance> effects;
private final boolean pure;
private final int color;
private final NbtCompound extraNbt;

public PotionMixture(Potion basePotion) {
public PotionMixture(Potion basePotion, NbtCompound extraNbt) {
this.basePotion = basePotion;
this.effects = ImmutableList.of();
this.pure = true;
this.extraNbt = extraNbt;

final var colorEffects = new ArrayList<>(effects);
if (basePotion != Potions.EMPTY) colorEffects.addAll(basePotion.getEffects());

this.color = PotionUtil.getColor(colorEffects);
}

public PotionMixture(Potion basePotion, List<StatusEffectInstance> effects, boolean pure) {
public PotionMixture(Potion basePotion, List<StatusEffectInstance> effects, boolean pure, NbtCompound extraNbt) {
this.basePotion = basePotion;
this.effects = ImmutableList.copyOf(effects);
this.pure = pure;
this.extraNbt = extraNbt;

final var colorEffects = new ArrayList<>(effects);
if (basePotion != Potions.EMPTY) colorEffects.addAll(basePotion.getEffects());
Expand All @@ -62,14 +65,14 @@ public PotionMixture mix(PotionMixture other) {
effects.addAll(basePotion.getEffects());
effects.addAll(other.basePotion.getEffects());

return new PotionMixture(Potions.EMPTY, effects, false);
return new PotionMixture(Potions.EMPTY, effects, false, null);
}

public static PotionMixture fromStack(ItemStack stack) {
final var potion = PotionUtil.getPotion(stack);
final var effects = PotionUtil.getCustomPotionEffects(stack);

return new PotionMixture(potion, effects, true);
return new PotionMixture(potion, effects, true, stack.hasNbt() && stack.getNbt().contains("ExtraPotionNbt", NbtElement.COMPOUND_TYPE) ? stack.getNbt().getCompound("ExtraPotionNbt") : null);
}

public static PotionMixture fromNbt(NbtCompound nbt) {
Expand All @@ -89,7 +92,13 @@ public static PotionMixture fromNbt(NbtCompound nbt) {
}
}

return new PotionMixture(potion, effects, nbt.getBoolean("Pure"));
NbtCompound extraNbt = null;

if (nbt.contains("ExtraNbt", NbtElement.COMPOUND_TYPE)) {
extraNbt = nbt.getCompound("ExtraNbt");
}

return new PotionMixture(potion, effects, nbt.getBoolean("Pure"), extraNbt);
}

public NbtCompound toNbt() {
Expand Down Expand Up @@ -126,6 +135,10 @@ public ItemStack toStack() {
PotionUtil.setPotion(stack, DUBIOUS_POTION);
}

if (extraNbt != null) {
stack.getOrCreateNbt().put("ExtraPotionNbt", extraNbt);
}

return stack;
}

Expand All @@ -145,6 +158,10 @@ public Potion basePotion() {
return basePotion;
}

public NbtCompound extraNbt() {
return extraNbt;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.wispforest.affinity.misc.quack;

import net.minecraft.nbt.NbtCompound;

public interface ExtendedAreaEffectCloudEntity {
void affinity$setExtraPotionNbt(NbtCompound tag);
}
Loading