Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.19-deeper-down' into 1.19-deep…
Browse files Browse the repository at this point in the history
…er-down
  • Loading branch information
Noaaan committed Nov 14, 2023
2 parents 3d4a736 + 3ca00bd commit 53f3832
Show file tree
Hide file tree
Showing 47 changed files with 509 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,22 @@ private static void disenchantItemAndSpawnXP(World world, ItemEntity itemEntity)
if (!enchantments.isEmpty()) {
int randomEnchantmentIndex = world.random.nextInt(enchantments.size());
Enchantment enchantmentToRemove = (Enchantment) enchantments.keySet().toArray()[randomEnchantmentIndex];
Pair<ItemStack, Integer> result = SpectrumEnchantmentHelper.removeEnchantments(itemStack, enchantmentToRemove);

if(result.getRight() > 0) {
int experience = EnchanterBlockEntity.getEnchantingPrice(itemStack, enchantmentToRemove, enchantments.get(enchantmentToRemove));
experience /= EXPERIENCE_DISENCHANT_RETURN_DIV;
if (experience > 0) {
ExperienceOrbEntity experienceOrbEntity = new ExperienceOrbEntity(world, itemEntity.getX(), itemEntity.getY(), itemEntity.getZ(), experience);
world.spawnEntity(experienceOrbEntity);
}

int experience = EnchanterBlockEntity.getEnchantingPrice(itemStack, enchantmentToRemove, enchantments.get(enchantmentToRemove));
experience /= EXPERIENCE_DISENCHANT_RETURN_DIV;
world.playSound(null, itemEntity.getBlockPos(), SoundEvents.BLOCK_GRINDSTONE_USE, SoundCategory.NEUTRAL, 1.0F, 0.9F + world.getRandom().nextFloat() * 0.2F);
SpectrumS2CPacketSender.playParticleWithRandomOffsetAndVelocity((ServerWorld) world, itemEntity.getPos(), SpectrumParticleTypes.GRAY_SPARKLE_RISING, 10, Vec3d.ZERO, new Vec3d(0.2, 0.4, 0.2));

if (experience > 0) {
ExperienceOrbEntity experienceOrbEntity = new ExperienceOrbEntity(world, itemEntity.getX(), itemEntity.getY(), itemEntity.getZ(), experience);
world.spawnEntity(experienceOrbEntity);
itemEntity.setStack(result.getLeft());
itemEntity.setToDefaultPickupDelay();
}
world.playSound(null, itemEntity.getBlockPos(), SoundEvents.BLOCK_GRINDSTONE_USE, SoundCategory.NEUTRAL, 1.0F, 0.9F + world.getRandom().nextFloat() * 0.2F);
SpectrumS2CPacketSender.playParticleWithRandomOffsetAndVelocity((ServerWorld) world, itemEntity.getPos(), SpectrumParticleTypes.GRAY_SPARKLE_RISING, 10, Vec3d.ZERO, new Vec3d(0.2, 0.4, 0.2));
itemEntity.setStack(SpectrumEnchantmentHelper.removeEnchantment(itemStack, enchantmentToRemove).getLeft());
itemEntity.setToDefaultPickupDelay();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.jgrapht.graph.*;

import java.util.*;
import java.util.function.*;

public class PastelTransmissionLogic {

Expand Down Expand Up @@ -103,16 +104,19 @@ private void tryTransferToType(PastelNodeBlockEntity sourceNode, Storage<ItemVar
}

private boolean transferBetween(PastelNodeBlockEntity sourceNode, Storage<ItemVariant> sourceStorage, PastelNodeBlockEntity destinationNode, Storage<ItemVariant> destinationStorage, TransferMode transferMode) {
Predicate<ItemVariant> filter = sourceNode.getTransferFilterTo(destinationNode);

try (Transaction transaction = Transaction.openOuter()) {
for (StorageView<ItemVariant> view : sourceStorage) {
if (view.isResourceBlank()) {
continue;
}

ItemVariant storedResource = view.getResource(); // Current resource
if (storedResource.isBlank()) {
if (storedResource.isBlank() || !filter.test(storedResource)) {
continue;
}

long storedAmount = view.getAmount();
if (storedAmount <= 0) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static void register() {
ClientBookRegistry.INSTANCE.pageTypes.put(SpectrumCommon.locate("liquid_crystal_converting"), PageLiquidCrystalConverting.class);
ClientBookRegistry.INSTANCE.pageTypes.put(SpectrumCommon.locate("midnight_solution_converting"), PageMidnightSolutionConverting.class);
ClientBookRegistry.INSTANCE.pageTypes.put(SpectrumCommon.locate("dragonrot_converting"), PageDragonrotConverting.class);
ClientBookRegistry.INSTANCE.pageTypes.put(SpectrumCommon.locate("mud_converting"), PageMudConverting.class);
ClientBookRegistry.INSTANCE.pageTypes.put(SpectrumCommon.locate("crystallarieum_growing"), PageCrystallarieumGrowing.class);
ClientBookRegistry.INSTANCE.pageTypes.put(SpectrumCommon.locate("cinderhearth_smelting"), PageCinderhearthSmelting.class);
ClientBookRegistry.INSTANCE.pageTypes.put(SpectrumCommon.locate("titration_barrel_fermenting"), PageTitrationBarrelFermenting.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class PageDragonrotConverting extends PageFluidConverting<DragonrotConvertingRecipe> {

private static final Identifier BACKGROUND_TEXTURE = SpectrumCommon.locate("textures/gui/patchouli/dragonrot_still.png");
private static final Identifier BACKGROUND_TEXTURE = SpectrumCommon.locate("textures/gui/patchouli/dragonrot.png");

public PageDragonrotConverting() {
super(SpectrumRecipeTypes.DRAGONROT_CONVERTING);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.dafuqs.spectrum.compat.patchouli.pages;

import de.dafuqs.spectrum.*;
import de.dafuqs.spectrum.recipe.*;
import de.dafuqs.spectrum.recipe.fluid_converting.*;
import net.minecraft.util.*;

public class PageMudConverting extends PageFluidConverting<MudConvertingRecipe> {

private static final Identifier BACKGROUND_TEXTURE = SpectrumCommon.locate("textures/gui/patchouli/mud.png");

public PageMudConverting() {
super(SpectrumRecipeTypes.MUD_CONVERTING);
}

@Override
public Identifier getBackgroundTexture() {
return BACKGROUND_TEXTURE;
}

}
21 changes: 9 additions & 12 deletions src/main/java/de/dafuqs/spectrum/explosion/ExplosionModifiers.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,35 @@ public class ExplosionModifiers {

// MODIFIER TYPES
// A Modifier Type defines an abstract set of modifiers that can be used a set number of times
public static final ExplosionModifierType GENERIC = registerModifierType("generic", new ExplosionModifierType(ExplosionArchetype.DAMAGE_ENTITIES, Integer.MAX_VALUE));
public static final ExplosionModifierType GENERIC = registerModifierType("generic", new ExplosionModifierType(ExplosionArchetype.ALL, Integer.MAX_VALUE)); // general improvements, particles and other cosmetic effects

public static final ExplosionModifierType DAMAGE_SOURCE = registerModifierType("damage_source", new ExplosionModifierType(ExplosionArchetype.DAMAGE_ENTITIES, 1)); // changes the damage source
public static final ExplosionModifierType DAMAGE_TYPE = registerModifierType("damage_type", new ExplosionModifierType(ExplosionArchetype.DAMAGE_ENTITIES, 1)); // changes the damage source
public static final ExplosionModifierType DAMAGE_MODIFICATION = registerModifierType("damage_modification", new ExplosionModifierType(ExplosionArchetype.DAMAGE_ENTITIES, Integer.MAX_VALUE)); // changes the damage source

public static final ExplosionModifierType DESTRUCTION_SHAPE = registerModifierType("destruction_shape", new ExplosionModifierType(ExplosionArchetype.DESTROY_BLOCKS, 1)); // explosion shape
public static final ExplosionModifierType DESTRUCTION_MODIFICATION = registerModifierType("destruction_modification", new ExplosionModifierType(ExplosionArchetype.DESTROY_BLOCKS, Integer.MAX_VALUE)); // all sorts of stuff, like damage improvements

public static final ExplosionModifierType COSMETIC = registerModifierType("cosmetic", new ExplosionModifierType(ExplosionArchetype.COSMETIC, Integer.MAX_VALUE)); // adds particles or other cosmetic effects


// MODIFIERS
// A modifier changes the effect of the modular explosion in some way
// General boosts
public static final ExplosionModifier EXPLOSION_BOOST = registerModifier("explosion_boost", new MoreBoomModifier(GENERIC, 0xffbf40));

// Damage source changers
public static final ExplosionModifier FIRE = registerModifier("fire", new FireModifier(DAMAGE_SOURCE, DamageSource.IN_FIRE, ParticleTypes.FLAME, 0xaff3eb));
public static final ExplosionModifier PRIMORDIAL_FIRE = registerModifier("primordial_fire", new PrimordialFireModifier(DAMAGE_SOURCE, SpectrumDamageSources.PRIMORDIAL_FIRE, SpectrumParticleTypes.PRIMORDIAL_FLAME_SMALL, 0x76254d));
public static final ExplosionModifier LIGHTNING = registerModifier("lightning_damage", new DamageChangingModifier(DAMAGE_SOURCE, DamageSource.LIGHTNING_BOLT, SpectrumParticleTypes.WHITE_EXPLOSION, 0xf0f24d) {
public static final ExplosionModifier FIRE = registerModifier("fire", new FireModifier(DAMAGE_TYPE, DamageSource.IN_FIRE, ParticleTypes.FLAME, 0xaff3eb));
public static final ExplosionModifier PRIMORDIAL_FIRE = registerModifier("primordial_fire", new PrimordialFireModifier(DAMAGE_TYPE, SpectrumDamageSources.PRIMORDIAL_FIRE, SpectrumParticleTypes.PRIMORDIAL_FLAME_SMALL, 0x76254d));
public static final ExplosionModifier LIGHTNING = registerModifier("lightning_damage", new DamageChangingModifier(DAMAGE_TYPE, DamageSource.LIGHTNING_BOLT, SpectrumParticleTypes.WHITE_EXPLOSION, 0xf0f24d) {
@Override
public Optional<DamageSource> getDamageSource(@Nullable Entity owner) {
return Optional.of(DamageSource.LIGHTNING_BOLT);
}
});
public static final ExplosionModifier MAGIC = registerModifier("magic_damage", new DamageChangingModifier(DAMAGE_SOURCE, DamageSource.MAGIC, SpectrumParticleTypes.PURPLE_CRAFTING, 0x5433a5) {
public static final ExplosionModifier MAGIC = registerModifier("magic_damage", new DamageChangingModifier(DAMAGE_TYPE, DamageSource.MAGIC, SpectrumParticleTypes.PURPLE_CRAFTING, 0x5433a5) {
@Override
public Optional<DamageSource> getDamageSource(@Nullable Entity owner) {
return Optional.of(DamageSource.magic(owner, owner));
}
});
public static final ExplosionModifier INCANDESCENCE = registerModifier("incandescence", new DamageChangingModifier(DAMAGE_SOURCE, SpectrumDamageSources.INCANDESCENCE, ParticleTypes.ENCHANT, 0xff59ff) {
public static final ExplosionModifier INCANDESCENCE = registerModifier("incandescence", new DamageChangingModifier(DAMAGE_TYPE, SpectrumDamageSources.INCANDESCENCE, ParticleTypes.ENCHANT, 0xff59ff) {
@Override
public Optional<DamageSource> getDamageSource(@Nullable Entity owner) {
return Optional.of(SpectrumDamageSources.incandescence(owner));
Expand All @@ -73,8 +70,8 @@ public Optional<ExplosionShape> getShape() {
public static final ExplosionModifier INVENTORY_INSERTION = registerModifier("inventory_insertion", new EnchantmentAddingModifier(DESTRUCTION_MODIFICATION, SpectrumEnchantments.INVENTORY_INSERTION, 1, ParticleTypes.ENCHANT, 0x5433a5));

// Cosmetic
public static final ExplosionModifier STARRY = registerModifier("starry", new ParticleAddingModifier(COSMETIC, ParticleTypes.END_ROD, 0xc3c8d4));
public static final ExplosionModifier LIGHT = registerModifier("light", new LightPlacingModifier(COSMETIC, SpectrumParticleTypes.SHIMMERSTONE_SPARKLE, 0xfaf87a));
public static final ExplosionModifier STARRY = registerModifier("starry", new ParticleAddingModifier(GENERIC, ParticleTypes.END_ROD, 0xc3c8d4));
public static final ExplosionModifier LIGHT = registerModifier("light", new LightPlacingModifier(GENERIC, SpectrumParticleTypes.SHIMMERSTONE_SPARKLE, 0xfaf87a));


private static <T extends ExplosionModifier> T registerModifier(String name, T modifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,61 +177,54 @@ public static boolean canCombineAny(Map<Enchantment, Integer> existingEnchantmen

/**
* Removes the enchantments on a stack of items / enchanted book
*
* @param itemStack the stack
* @param enchantments the enchantments to remove
* @return if >0 enchantments could be removed
*/
public static Pair<ItemStack, Boolean> removeEnchantments(@NotNull ItemStack itemStack, Enchantment... enchantments) {
boolean anySuccess = false;
for (Enchantment enchantment : enchantments) {
Pair<ItemStack, Boolean> result = removeEnchantment(itemStack, enchantment);
anySuccess = result.getRight();
itemStack = result.getLeft();
}
return new Pair<>(itemStack, anySuccess);
}

/**
* @return The resulting stack & a boolean to specify if removing was successful
* @return The resulting stack & the count of enchants that were removed
*/
public static Pair<ItemStack, Boolean> removeEnchantment(@NotNull ItemStack itemStack, Enchantment enchantment) {
public static Pair<ItemStack, Integer> removeEnchantments(@NotNull ItemStack itemStack, Enchantment... enchantments) {
NbtCompound compound = itemStack.getNbt();
if (compound == null) {
return new Pair<>(itemStack, false);
return new Pair<>(itemStack, 0);
}

NbtList enchantmentList;
if (itemStack.isOf(Items.ENCHANTED_BOOK)) {
enchantmentList = compound.getList(EnchantedBookItem.STORED_ENCHANTMENTS_KEY, 10);
} else {
enchantmentList = compound.getList(ItemStack.ENCHANTMENTS_KEY, 10);
}

Identifier enchantmentIdentifier = Registry.ENCHANTMENT.getId(enchantment);
boolean success = false;

List<Identifier> enchantIDs = new ArrayList<>();
for(Enchantment enchantment : enchantments) {
enchantIDs.add(Registry.ENCHANTMENT.getId(enchantment));
}

int removals = 0;
for (int i = 0; i < enchantmentList.size(); i++) {
NbtCompound currentCompound = enchantmentList.getCompound(i);
if (currentCompound.contains("id", NbtElement.STRING_TYPE) && Objects.equals(Identifier.tryParse(currentCompound.getString("id")), enchantmentIdentifier)) {
enchantmentList.remove(i);
success = true;
break;
if (currentCompound.contains("id", NbtElement.STRING_TYPE)) {
Identifier currentID = new Identifier(currentCompound.getString("id"));
if(enchantIDs.contains(currentID)) {
enchantmentList.remove(i);
removals++;
break;
}
}
}

if (itemStack.isOf(Items.ENCHANTED_BOOK)) {
if(enchantmentList.isEmpty()) {
ItemStack newStack = new ItemStack(Items.BOOK);
newStack.setCount(itemStack.getCount());
return new Pair<>(newStack, true);
return new Pair<>(newStack, removals);
}
compound.put(EnchantedBookItem.STORED_ENCHANTMENTS_KEY, enchantmentList);
} else {
compound.put(ItemStack.ENCHANTMENTS_KEY, enchantmentList);
}
itemStack.setNbt(compound);
return new Pair<>(itemStack, success);

return new Pair<>(itemStack, removals);
}

public static <T extends Item & ExtendedEnchantable> ItemStack getMaxEnchantedStack(@NotNull T item) {
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/de/dafuqs/spectrum/items/MysteriousCompassItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package de.dafuqs.spectrum.items;

import de.dafuqs.revelationary.api.advancements.*;
import de.dafuqs.spectrum.*;
import de.dafuqs.spectrum.registries.*;
import net.minecraft.entity.*;
import net.minecraft.entity.player.*;
import net.minecraft.item.*;
import net.minecraft.util.*;
import net.minecraft.world.*;
import org.jetbrains.annotations.*;

public class MysteriousCompassItem extends StructureCompassItem {

private static final Identifier REQUIRED_ADVANCEMENT = SpectrumCommon.locate("unlocks/mysterious_locket_socketing");

public MysteriousCompassItem(Settings settings) {
super(settings, SpectrumStructureTags.MYSTERIOUS_COMPASS_LOCATED);
}

@Override
public void inventoryTick(@NotNull ItemStack stack, @NotNull World world, Entity entity, int slot, boolean selected) {
if (!world.isClient && world.getTime() % 200 == 0 && entity instanceof PlayerEntity player)
if(AdvancementHelper.hasAdvancement(player, REQUIRED_ADVANCEMENT)) {
locateStructure(stack, world, entity);
} else {
removeStructurePos(stack);
}
}

}
22 changes: 12 additions & 10 deletions src/main/java/de/dafuqs/spectrum/items/StructureCompassItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ public StructureCompassItem(Settings settings, TagKey<Structure> locatedStructur

@Override
public void inventoryTick(@NotNull ItemStack stack, @NotNull World world, Entity entity, int slot, boolean selected) {
if (!world.isClient) {
if (world.getTime() % 200 == 0) {
Pair<BlockPos, RegistryEntry<Structure>> foundStructure = locateStructure((ServerWorld) world, entity.getBlockPos());
if (foundStructure != null) {
saveStructurePos(stack, world.getRegistryKey(), foundStructure.getFirst());
} else {
removeStructurePos(stack);
}
}
if (!world.isClient && world.getTime() % 200 == 0) {
locateStructure(stack, world, entity);
}
}


protected void locateStructure(@NotNull ItemStack stack, @NotNull World world, Entity entity) {
Pair<BlockPos, RegistryEntry<Structure>> foundStructure = locateStructure((ServerWorld) world, entity.getBlockPos());
if (foundStructure != null) {
saveStructurePos(stack, world.getRegistryKey(), foundStructure.getFirst());
} else {
removeStructurePos(stack);
}
}

public @Nullable Pair<BlockPos, RegistryEntry<Structure>> locateStructure(@NotNull ServerWorld world, @NotNull BlockPos pos) {
Registry<Structure> registry = world.getRegistryManager().get(Registry.STRUCTURE_KEY);
Optional<RegistryEntryList.Named<Structure>> registryEntryList = registry.getEntryList(this.locatedStructures);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.dafuqs.spectrum.energy.*;
import de.dafuqs.spectrum.energy.color.*;
import net.minecraft.client.item.*;
import net.minecraft.enchantment.*;
import net.minecraft.entity.*;
import net.minecraft.entity.damage.*;
import net.minecraft.entity.player.*;
Expand All @@ -25,10 +26,10 @@ public FerociousBidentItem(Settings settings, double damage) {
}

@Override
public int getBuiltinRiptideLevel() {
return BUILTIN_RIPTIDE_LEVEL;
public int getRiptideLevel(ItemStack stack) {
return Math.max(EnchantmentHelper.getRiptide(stack), BUILTIN_RIPTIDE_LEVEL);
}

@Override
public boolean canStartRiptide(PlayerEntity player, ItemStack stack) {
return super.canStartRiptide(player, stack) || InkPowered.tryDrainEnergy(player, RIPTIDE_COST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,9 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
ItemStack handStack = user.getStackInHand(hand);
if (handStack.getDamage() >= handStack.getMaxDamage() - 1) {
return TypedActionResult.fail(handStack);
} else if (!canStartRiptide(user, handStack)) {
user.setCurrentHand(hand);
return TypedActionResult.consume(handStack);
} else if (EnchantmentHelper.getRiptide(handStack) > 0 && !user.isTouchingWaterOrRain()) {
return TypedActionResult.fail(handStack);
} else {
user.setCurrentHand(hand);
return TypedActionResult.consume(handStack);
}
user.setCurrentHand(hand);
return TypedActionResult.consume(handStack);
}

@Override
Expand All @@ -79,10 +73,9 @@ public void onStoppedUsing(ItemStack stack, World world, LivingEntity user, int
int useTime = this.getMaxUseTime(stack) - remainingUseTicks;
if (useTime >= 10) {
player.incrementStat(Stats.USED.getOrCreateStat(this));

int riptideLevel = getRiptideLevel(stack);
if (riptideLevel > 0 && canStartRiptide(player, stack)) {
riptide(world, player, riptideLevel);

if (canStartRiptide(player, stack)) {
riptide(world, player, getRiptideLevel(stack));
} else if (!world.isClient) {
stack.damage(1, player, (p) -> p.sendToolBreakStatus(user.getActiveHand()));
throwBident(stack, (ServerWorld) world, player);
Expand All @@ -92,7 +85,7 @@ public void onStoppedUsing(ItemStack stack, World world, LivingEntity user, int
}

public int getRiptideLevel(ItemStack stack) {
return Math.max(EnchantmentHelper.getRiptide(stack), getBuiltinRiptideLevel());
return EnchantmentHelper.getRiptide(stack);
}

protected void riptide(World world, PlayerEntity playerEntity, int riptideLevel) {
Expand Down Expand Up @@ -160,12 +153,8 @@ public float getThrowSpeed() {
return 2.5F;
}

public int getBuiltinRiptideLevel() {
return 0;
}

public boolean canStartRiptide(PlayerEntity player, ItemStack stack) {
return player.isTouchingWaterOrRain();
return getRiptideLevel(stack) > 0 && player.isTouchingWaterOrRain();
}

public boolean isThrownAsMirrorImage(ItemStack stack, ServerWorld world, PlayerEntity player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private static void enchantAndRemoveOthers(PlayerEntity player, ItemStack stack,
}
}

if (SpectrumEnchantmentHelper.removeEnchantments(stack, Enchantments.SILK_TOUCH, SpectrumEnchantments.RESONANCE, Enchantments.FORTUNE).getRight()) {
if (SpectrumEnchantmentHelper.removeEnchantments(stack, Enchantments.SILK_TOUCH, SpectrumEnchantments.RESONANCE, Enchantments.FORTUNE).getRight() > 0) {
SpectrumEnchantmentHelper.addOrExchangeEnchantment(stack, enchantment, level, true, true);
player.sendMessage(message, true);
} else if (player instanceof ServerPlayerEntity serverPlayerEntity) {
Expand Down
Loading

0 comments on commit 53f3832

Please sign in to comment.