Skip to content

Commit

Permalink
Merge branch 'DaFuqs:1.20.1-main' into manor-loot
Browse files Browse the repository at this point in the history
  • Loading branch information
f-raZ0R authored Oct 22, 2024
2 parents 11a7eeb + 5bd8e29 commit 34a807d
Show file tree
Hide file tree
Showing 17 changed files with 308 additions and 198 deletions.
29 changes: 16 additions & 13 deletions src/main/java/de/dafuqs/spectrum/api/block/FilterConfigurable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.dafuqs.spectrum.inventories.slots.ShadowSlot;
import de.dafuqs.spectrum.networking.SpectrumC2SPacketSender;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.*;
Expand All @@ -17,11 +18,12 @@

import java.util.*;

@SuppressWarnings("UnstableApiUsage")
public interface FilterConfigurable {

List<ItemStack> getItemFilters();
List<ItemVariant> getItemFilters();

void setFilterItem(int slot, ItemStack item);
void setFilterItem(int slot, ItemVariant item);

default int getFilterRows() {
return 1;
Expand All @@ -35,16 +37,16 @@ default int getDrawnSlots() {
return getItemFilters().size();
}

static void writeFilterNbt(NbtCompound tag, List<ItemStack> filterItems) {
static void writeFilterNbt(NbtCompound tag, List<ItemVariant> filterItems) {
for (int i = 0; i < filterItems.size(); i++) {
tag.put("FilterStack" + i, filterItems.get(i).writeNbt(new NbtCompound()));
tag.put("FilterStack" + i, filterItems.get(i).toNbt());
}
}

static void readFilterNbt(NbtCompound tag, List<ItemStack> filterItems) {
static void readFilterNbt(NbtCompound tag, List<ItemVariant> filterItems) {
for (int i = 0; i < filterItems.size(); i++) {
if (tag.contains("FilterStack" + i)) {
filterItems.set(i, ItemStack.fromNbt(tag.getCompound("FilterStack" + i)));
filterItems.set(i, ItemVariant.fromNbt(tag.getCompound("FilterStack" + i)));
}
}
}
Expand Down Expand Up @@ -74,15 +76,15 @@ static Inventory getFilterInventoryFromPacketHandler(int syncId, @NotNull Player
return getFilterInventoryFromPacketClicker(packetByteBuf, clicker);
}

static Inventory getFilterInventoryFromItemsClicker(List<ItemStack> items, ShadowSlotClicker clicker) {
static Inventory getFilterInventoryFromItemsClicker(List<ItemVariant> items, ShadowSlotClicker clicker) {
Inventory inventory = new FilterInventory(clicker, items.size());
for (int i = 0; i < items.size(); i++) {
inventory.setStack(i, items.get(i));
inventory.setStack(i, items.get(i).toStack());
}
return inventory;
}

static Inventory getFilterInventoryFromItemsHandler(int syncId, @NotNull PlayerInventory playerInventory, List<ItemStack> items, @NotNull ScreenHandler thisHandler) {
static Inventory getFilterInventoryFromItemsHandler(int syncId, @NotNull PlayerInventory playerInventory, List<ItemVariant> items, @NotNull ScreenHandler thisHandler) {
final var clicker = new ShadowSlotClicker.FromHandler(thisHandler, playerInventory.player, syncId);
return getFilterInventoryFromItemsClicker(items, clicker);
}
Expand Down Expand Up @@ -146,18 +148,19 @@ static void writeScreenOpeningData(PacketByteBuf buf, FilterConfigurable configu
writeScreenOpeningData(buf, configurable.getItemFilters(), configurable.getFilterRows(), configurable.getSlotsPerRow(), configurable.getDrawnSlots());
}

static void writeScreenOpeningData(PacketByteBuf buf, List<ItemStack> filterItems, int rows, int slotsPerRow, int drawnSlots) {
static void writeScreenOpeningData(PacketByteBuf buf, List<ItemVariant> filterItems, int rows, int slotsPerRow, int drawnSlots) {
buf.writeInt(filterItems.size());
for (ItemStack filterItem : filterItems) {
buf.writeItemStack(filterItem);
for (ItemVariant filterItem : filterItems) {
// The difference between just using filterItem.toNbt() is that ItemVariant nbt uses "item" while ItemStack uses "id"
buf.writeItemStack(filterItem.toStack());
}
buf.writeInt(rows);
buf.writeInt(slotsPerRow);
buf.writeInt(drawnSlots);
}

default boolean hasEmptyFilter() {
return getItemFilters().stream().allMatch(ItemStack::isEmpty);
return getItemFilters().stream().allMatch(ItemVariant::isBlank);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import de.dafuqs.spectrum.particle.*;
import de.dafuqs.spectrum.registries.*;
import net.fabricmc.fabric.api.screenhandler.v1.*;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.minecraft.block.*;
import net.minecraft.entity.*;
import net.minecraft.entity.player.*;
Expand All @@ -34,14 +35,15 @@
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("UnstableApiUsage")
public class BlackHoleChestBlockEntity extends SpectrumChestBlockEntity implements ExtendedScreenHandlerFactory, SidedInventory, EventQueue.Callback<Object> {

public static final int INVENTORY_SIZE = 28;
public static final int ITEM_FILTER_SLOT_COUNT = 5;
public static final int EXPERIENCE_STORAGE_PROVIDER_ITEM_SLOT = 27;
private static final int RANGE = 12;
private final ItemAndExperienceEventQueue itemAndExperienceEventQueue;
private final List<ItemStack> filterItems;
private final List<ItemVariant> filterItems;
private State state;
private boolean isOpen, isFull, hasXPStorage;
float storageTarget, storagePos, lastStorageTarget, capTarget, capPos, lastCapTarget, orbTarget, orbPos, lastOrbTarget, yawTarget, orbYaw, lastYawTarget;
Expand All @@ -51,7 +53,7 @@ public class BlackHoleChestBlockEntity extends SpectrumChestBlockEntity implemen
public BlackHoleChestBlockEntity(BlockPos blockPos, BlockState blockState) {
super(SpectrumBlockEntities.BLACK_HOLE_CHEST, blockPos, blockState);
this.itemAndExperienceEventQueue = new ItemAndExperienceEventQueue(new BlockPositionSource(this.pos), RANGE, this);
this.filterItems = DefaultedList.ofSize(ITEM_FILTER_SLOT_COUNT, ItemStack.EMPTY);
this.filterItems = DefaultedList.ofSize(ITEM_FILTER_SLOT_COUNT, ItemVariant.blank());
}

public static void tick(@NotNull World world, BlockPos pos, BlockState state, BlackHoleChestBlockEntity chest) {
Expand Down Expand Up @@ -308,11 +310,11 @@ public void writeScreenOpeningData(ServerPlayerEntity player, PacketByteBuf buf)
FilterConfigurable.writeScreenOpeningData(buf, filterItems, 1, ITEM_FILTER_SLOT_COUNT, ITEM_FILTER_SLOT_COUNT);
}

public List<ItemStack> getItemFilters() {
public List<ItemVariant> getItemFilters() {
return this.filterItems;
}

public void setFilterItem(int slot, ItemStack item) {
public void setFilterItem(int slot, ItemVariant item) {
this.filterItems.set(slot, item);
this.markDirty();
}
Expand All @@ -324,7 +326,7 @@ public boolean acceptsItemStack(ItemStack itemStack) {

boolean allAir = true;
for (int i = 0; i < ITEM_FILTER_SLOT_COUNT; i++) {
ItemStack filterItem = this.filterItems.get(i);
ItemVariant filterItem = this.filterItems.get(i);
if (filterItem.getItem().equals(itemStack.getItem())) {
return true;
} else if (!filterItem.getItem().equals(Items.AIR)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.dafuqs.spectrum.helpers.*;
import de.dafuqs.spectrum.particle.*;
import de.dafuqs.spectrum.registries.*;
import de.dafuqs.spectrum.sound.*;
import net.fabricmc.api.*;
import net.minecraft.block.*;
import net.minecraft.client.*;
Expand Down Expand Up @@ -54,7 +55,21 @@ public void onBlockBreakStart(BlockState state, World world, BlockPos pos, Playe
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
super.randomDisplayTick(state, world, pos, random);

if (this.isVisibleTo(MinecraftClient.getInstance().player) && world.getRandom().nextFloat() < 0.02) {
if (this.isVisibleTo(MinecraftClient.getInstance().player)) {

var center = pos.toCenterPos();
if (!BlockAuraSoundInstance.isNearPreexistingAura(center)) {
var emitters = BlockAuraSoundInstance.scanForBlocks(SpectrumBlockTags.AZURITE_ORES, world, pos.toCenterPos());

if (emitters.size() >= 32) {
BlockAuraSoundInstance.tryCreateNewInstance(SpectrumBlockTags.AZURITE_ORES, SpectrumSoundEvents.CRYSTAL_AURA, 100, emitters);
}
}


if (world.getRandom().nextFloat() >= 0.02)
return;

ParticleHelper.playTriangulatedParticle(world, SpectrumParticleTypes.AZURE_AURA, 8, false, new Vec3d(32, 8, 32), -12, true, Vec3d.of(pos), new Vec3d(0, 0.04D + random.nextDouble() * 0.06, 0));
ParticleHelper.playTriangulatedParticle(world, SpectrumParticleTypes.AZURE_AURA, 12, true, new Vec3d(32, 8, 32), -12, true, Vec3d.of(pos), new Vec3d(0, 0.04D + random.nextDouble() * 0.06, 0));
ParticleHelper.playTriangulatedParticle(world, SpectrumParticleTypes.AZURE_MOTE_SMALL, 19, false, new Vec3d(24, 8, 24), -8, false, Vec3d.of(pos), Vec3d.ZERO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ public class PastelNodeBlockEntity extends BlockEntity implements FilterConfigur
protected BlockApiCache<Storage<ItemVariant>, Direction> connectedStorageCache = null;
protected Direction cachedDirection = null;

private final List<ItemStack> filterItems;
private final List<ItemVariant> filterItems;
float rotationTarget, crystalRotation, lastRotationTarget, heightTarget, crystalHeight, lastHeightTarget, alphaTarget, ringAlpha, lastAlphaTarget;
long creationStamp = -1, interpTicks, interpLength = -1, spinTicks;
private State state;

public PastelNodeBlockEntity(BlockPos blockPos, BlockState blockState) {
super(SpectrumBlockEntities.PASTEL_NODE, blockPos, blockState);
this.filterItems = DefaultedList.ofSize(MAX_FILTER_SLOTS, ItemStack.EMPTY);
this.filterItems = DefaultedList.ofSize(MAX_FILTER_SLOTS, ItemVariant.blank());
this.outerRing = Optional.empty();
this.innerRing = Optional.empty();
this.redstoneRing = Optional.empty();
Expand Down Expand Up @@ -245,7 +245,7 @@ public void updateUpgrades() {

if (filterSlotRows < oldFilterSlotCount) {
for (int i = getDrawnSlots(); i < filterItems.size(); i++) {
filterItems.set(i, ItemStack.EMPTY);
filterItems.set(i, ItemVariant.blank());
}
}

Expand Down Expand Up @@ -486,12 +486,12 @@ public void updateInClientWorld() {
}

@Override
public List<ItemStack> getItemFilters() {
public List<ItemVariant> getItemFilters() {
return this.filterItems;
}

@Override
public void setFilterItem(int slot, ItemStack item) {
public void setFilterItem(int slot, ItemVariant item) {
this.filterItems.set(slot, item);
}

Expand All @@ -513,21 +513,22 @@ public Predicate<ItemVariant> getTransferFilterTo(PastelNodeBlockEntity other) {
private boolean filter(ItemVariant variant) {
return filterItems
.stream()
.anyMatch(stack -> {
if (LoreHelper.hasLore(stack)) {
.anyMatch(filterItem -> {
ItemStack filterStack = filterItem.toStack();
if (LoreHelper.hasLore(filterStack)) {
if (variant.getNbt() == null)
return false;

for (Text text : LoreHelper.getLoreList(stack)) {
if (!testNBTPredicates(text.getString(), stack, variant))
for (Text text : LoreHelper.getLoreList(filterStack)) {
if (!testNBTPredicates(text.getString(), filterStack, variant))
return false;
}
}

if (!stack.hasCustomName() || !stack.isIn(SpectrumItemTags.TAG_FILTERING_ITEMS))
return stack.getItem() == variant.getItem();
if (!filterStack.hasCustomName() || !filterStack.isIn(SpectrumItemTags.TAG_FILTERING_ITEMS))
return filterStack.getItem() == variant.getItem();

var name = StringUtils.trim(stack.getName().getString());
var name = StringUtils.trim(filterStack.getName().getString());

// This is to allow nbt filtering without item / tag filtering.
if (StringUtils.equalsAnyIgnoreCase(name, "*", "any", "all", "everything", "c:*", "c:any", "c:all", "c:everything"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ public static void tick(World world, BlockPos blockPos, BlockState blockState, P
}
}

public static boolean hasRoomInOutputInventoryFor(@NotNull PotionWorkshopBlockEntity potionWorkshopBlockEntity, int outputStacks) {
public static boolean hasRoomInOutputInventoryFor(@NotNull PotionWorkshopBlockEntity potionWorkshopBlockEntity, int count) {
for (int slotID : potionWorkshopBlockEntity.getAvailableSlots(Direction.DOWN)) {
if (potionWorkshopBlockEntity.getStack(slotID).isEmpty()) {
outputStacks--;
if (outputStacks == 0) {
count--;
if (count == 0) {
return true;
}
}
Expand All @@ -175,7 +175,7 @@ public static boolean hasRoomInOutputInventoryFor(@NotNull PotionWorkshopBlockEn
PotionWorkshopBrewingRecipe newPotionWorkshopBrewingRecipe = world.getRecipeManager().getFirstMatch(SpectrumRecipeTypes.POTION_WORKSHOP_BREWING, potionWorkshopBlockEntity, world).orElse(null);
if (newPotionWorkshopBrewingRecipe != null) {
if (newPotionWorkshopBrewingRecipe.canPlayerCraft(potionWorkshopBlockEntity.getOwnerIfOnline())) {
// we check for reagents here instead of the recipe itself because of performance
// we check for reagents here instead of the recipe itself for performance reasons
if (isBrewingRecipeApplicable(newPotionWorkshopBrewingRecipe, potionWorkshopBlockEntity.getStack(BASE_INPUT_SLOT_ID), potionWorkshopBlockEntity)) {
return newPotionWorkshopBrewingRecipe;
}
Expand Down Expand Up @@ -296,16 +296,25 @@ private static void fillPotionFillable(PotionWorkshopBlockEntity potionWorkshopB
// process reagents
PotionMod potionMod = getPotionModFromReagents(potionWorkshopBlockEntity);

brewingRecipe.fillPotionFillable(potionFillableStack, potionMod, potionWorkshopBlockEntity.lastBrewedRecipe, potionWorkshopBlockEntity.world.random);

// consume ingredients
decrementIngredientSlots(potionWorkshopBlockEntity);
decrementReagentSlots(potionWorkshopBlockEntity);

int maxBrewedPotionsAmount = Support.getIntFromDecimalWithChance(brewingRecipe.getModifiedYield(potionMod), potionWorkshopBlockEntity.world.random);
if (maxBrewedPotionsAmount < 1) {
ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) potionWorkshopBlockEntity.getOwnerIfOnline();
if (serverPlayerEntity != null) {
SpectrumAdvancementCriteria.POTION_WORKSHOP_BREWING.trigger(serverPlayerEntity, potionFillableStack, 0);
}
return;
}

brewingRecipe.fillPotionFillable(potionFillableStack, potionMod, potionWorkshopBlockEntity.lastBrewedRecipe, potionWorkshopBlockEntity.world.random);
potionWorkshopBlockEntity.inventory.set(BASE_INPUT_SLOT_ID, ItemStack.EMPTY);
InventoryHelper.addToInventory(potionWorkshopBlockEntity.inventory, potionFillableStack, FIRST_INVENTORY_SLOT, FIRST_INVENTORY_SLOT + INVENTORY_SLOT_COUNT);

// trigger advancements for all brewed potions
ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) potionWorkshopBlockEntity.getOwnerIfOnline();
InventoryHelper.addToInventory(potionWorkshopBlockEntity.inventory, potionFillableStack, FIRST_INVENTORY_SLOT, FIRST_INVENTORY_SLOT + INVENTORY_SLOT_COUNT);
if (serverPlayerEntity != null) {
SpectrumAdvancementCriteria.POTION_WORKSHOP_BREWING.trigger(serverPlayerEntity, potionFillableStack, 1);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/dafuqs/spectrum/helpers/LoreHelper.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package de.dafuqs.spectrum.helpers;

import com.google.gson.*;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.minecraft.item.*;
import net.minecraft.nbt.*;
import net.minecraft.text.*;
import org.jetbrains.annotations.*;

import java.util.*;

@SuppressWarnings("UnstableApiUsage")
public class LoreHelper {

public static @NotNull List<Text> getLoreTextArrayFromString(@NotNull String string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.dafuqs.spectrum.blocks.chests.*;
import de.dafuqs.spectrum.inventories.slots.*;
import de.dafuqs.spectrum.registries.*;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.minecraft.block.entity.*;
import net.minecraft.entity.player.*;
import net.minecraft.inventory.*;
Expand All @@ -17,6 +18,7 @@

import java.util.function.Function;

@SuppressWarnings("UnstableApiUsage")
public class BlackHoleChestScreenHandler extends ScreenHandler {

protected static final int ROWS = 3;
Expand Down Expand Up @@ -139,7 +141,7 @@ public BlackHoleChestFilterSlot(Inventory inventory, int index, int x, int y) {
@Override
public boolean onClicked(ItemStack heldStack, ClickType type, PlayerEntity player) {
if (blackHoleChestBlockEntity != null) {
blackHoleChestBlockEntity.setFilterItem(getIndex(), heldStack.copyWithCount(1));
blackHoleChestBlockEntity.setFilterItem(getIndex(), ItemVariant.of(heldStack));
}
return super.onClicked(heldStack, type, player);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.dafuqs.spectrum.api.block.*;
import de.dafuqs.spectrum.inventories.slots.*;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.minecraft.entity.player.*;
import net.minecraft.inventory.*;
import net.minecraft.item.*;
Expand All @@ -13,6 +14,7 @@

import java.util.function.Function;

@SuppressWarnings("UnstableApiUsage")
public class FilteringScreenHandler extends ScreenHandler {

protected final World world;
Expand Down Expand Up @@ -111,7 +113,7 @@ public FilterSlot(Inventory inventory, int index, int x, int y) {
@Override
public boolean onClicked(ItemStack heldStack, ClickType type, PlayerEntity player) {
if (!world.isClient && filterConfigurable != null) {
filterConfigurable.setFilterItem(getIndex(), heldStack.copyWithCount(1));
filterConfigurable.setFilterItem(getIndex(), ItemVariant.of(heldStack));
}
return super.onClicked(heldStack, type, player);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/de/dafuqs/spectrum/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ private float getToughness() {
if (entity.getWorld().isClient())
return;

if (entity.isSpectator() || entity instanceof PlayerEntity player && player.getAbilities().creativeMode)
return;

var damage = Float.MAX_VALUE;
if (SleepStatusEffect.isImmuneish(entity)) {
if (entity instanceof PlayerEntity player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,15 @@ public static void register() {
Entity cameraEntity = client.getCameraEntity();
if (world == null || cameraEntity == null) {
BiomeAttenuatingSoundInstance.clear();
BlockAuraSoundInstance.clear();
return;
}

RegistryEntry<Biome> biome = world.getBiome(client.getCameraEntity().getBlockPos());

HowlingSpireEffects.clientTick(world, cameraEntity, biome);
DarknessEffects.clientTick(world, (LivingEntity) cameraEntity, biome);
AzuriteAuraSoundInstance.update(world, cameraEntity);
BlockAuraSoundInstance.update(world);
});
}

Expand Down
Loading

0 comments on commit 34a807d

Please sign in to comment.