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 @@ -223,12 +223,11 @@ public BlockState rotate(BlockState pState, Rotation pRotation) {

@Override
public List<ItemStack> getDrops(BlockState state, LootParams.Builder builder) {
BlockEntity tileEntity = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
var drops = super.getDrops(state, builder);
if (tileEntity instanceof MetaMachine machine) {
if (machine instanceof IMachineModifyDrops machineModifyDrops) {
machineModifyDrops.onDrops(drops);
}

BlockEntity be = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
if (be instanceof MetaMachine machine) {
machine.modifyDrops(drops);
if (machine instanceof IDropSaveMachine dropSaveMachine && dropSaveMachine.saveBreak()) {
for (ItemStack drop : drops) {
if (drop.getItem() instanceof MetaMachineItem item && item.getBlock() == this) {
Expand All @@ -248,7 +247,7 @@ public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState
if (!pState.is(pNewState.getBlock())) { // new block
MetaMachine machine = MetaMachine.getMachine(pLevel, pPos);
if (machine != null) {
machine.onRemoved();
machine.onMachineDestroyed();
}

pLevel.updateNeighbourForOutputSignal(pPos, this);
Expand Down Expand Up @@ -328,19 +327,32 @@ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player
//////////////////////////////////////

public boolean canConnectRedstone(BlockGetter level, BlockPos pos, Direction side) {
return MetaMachine.getMachine(level, pos).canConnectRedstone(side);
var machine = MetaMachine.getMachine(level, pos);
if (machine == null) return false;
return machine.canConnectRedstone(side);
}

@Override
@SuppressWarnings("deprecation") // This is fine to override, just not to be called.
public int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direction direction) {
return MetaMachine.getMachine(level, pos).getOutputSignal(direction);
var machine = MetaMachine.getMachine(level, pos);
if (machine == null) return 0;
return machine.getOutputSignal(direction);
}

@Override
public int getDirectSignal(BlockState state, BlockGetter level, BlockPos pos, Direction direction) {
var machine = MetaMachine.getMachine(level, pos);
if (machine == null) return 0;
return machine.getOutputDirectSignal(direction);
}

@Override
@SuppressWarnings("deprecation") // This is fine to override, just not to be called.
public int getAnalogOutputSignal(BlockState state, Level level, BlockPos pos) {
return MetaMachine.getMachine(level, pos).getAnalogOutputSignal();
var machine = MetaMachine.getMachine(level, pos);
if (machine == null) return 0;
return machine.getAnalogOutputSignal();
}

/////////
Expand Down

This file was deleted.

12 changes: 1 addition & 11 deletions src/main/java/com/gregtechceu/gtceu/api/capability/IMiner.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
package com.gregtechceu.gtceu.api.capability;

import com.gregtechceu.gtceu.api.machine.feature.IMachineLife;
import com.gregtechceu.gtceu.api.machine.feature.IRecipeLogicMachine;
import com.gregtechceu.gtceu.common.machine.trait.miner.MinerLogic;

public interface IMiner extends IRecipeLogicMachine, IMachineLife {

@Override
MinerLogic getRecipeLogic();

@Override
default void onMachineRemoved() {
getRecipeLogic().onRemove();
}
public interface IMiner extends IRecipeLogicMachine {

boolean drainInput(boolean simulate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public static MaterialEntry getMaterialEntry(ItemLike itemLike) {
MaterialEntry materialEntry1 = getMaterialEntry(itemTag);
// check that it's not the empty marker and that it's not a parent tag
if (!materialEntry1.isEmpty() &&
Arrays.stream(materialEntry1.tagPrefix().getItemParentTags()).noneMatch(itemTag::equals)) {
materialEntry1.tagPrefix().getItemParentTags().stream().noneMatch(itemTag::equals)) {
return materialEntry1;
}
}
Expand All @@ -210,7 +210,7 @@ public static MaterialEntry getMaterialEntry(TagKey<Item> tag) {
Set<TagKey<Item>> allItemTags = BuiltInRegistries.ITEM.getTagNames().collect(Collectors.toSet());
for (TagPrefix prefix : TagPrefix.values()) {
for (Material material : GTCEuAPI.materialManager.getRegisteredMaterials()) {
Arrays.stream(prefix.getItemTags(material))
prefix.getItemTags(material).stream()
.filter(allItemTags::contains)
.forEach(tagKey -> {
// remove the tag so that the next iteration is faster.
Expand Down Expand Up @@ -291,19 +291,19 @@ public static Block getBlock(TagPrefix orePrefix, Material material) {
@Nullable
public static TagKey<Block> getBlockTag(TagPrefix orePrefix, @NotNull Material material) {
var tags = orePrefix.getBlockTags(material);
if (tags.length > 0) {
return tags[0];
if (tags.isEmpty()) {
return null;
}
return null;
return tags.get(0);
}

@Nullable
public static TagKey<Item> getTag(TagPrefix orePrefix, @NotNull Material material) {
var tags = orePrefix.getItemTags(material);
if (tags.length > 0) {
return tags[0];
if (tags.isEmpty()) {
return null;
}
return null;
return tags.get(0);
}

public static List<Pair<ItemStack, ItemMaterialInfo>> getAllItemInfos() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static void reinitializeMaterialData() {
// Load new data
TagsHandler.initExtraUnificationEntries();
for (TagPrefix prefix : TagPrefix.values()) {
prefix.getIgnored().forEach((mat, items) -> registerMaterialEntries(Arrays.asList(items), prefix, mat));
prefix.getIgnored().forEach((mat, items) -> registerMaterialEntries(items, prefix, mat));
}
GTMaterialItems.toUnify
.forEach((materialEntry, supplier) -> registerMaterialEntry(supplier, materialEntry));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public String toString() {
return material.getResourceLocation().toString();
}
var tags = tagPrefix.getItemTags(material);
if (tags.length == 0) {
if (tags.isEmpty()) {
return tagPrefix.name + "/" + material.getName();
}
return tags[0].location().toString();
return tags.get(0).location().toString();
}

public static @Nullable MaterialEntry of(Object o) {
Expand Down
93 changes: 56 additions & 37 deletions src/main/java/com/gregtechceu/gtceu/api/data/tag/TagPrefix.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import lombok.experimental.Accessors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;

import java.util.*;
import java.util.function.*;
Expand Down Expand Up @@ -1034,7 +1035,7 @@ public record BlockProperties(Supplier<Supplier<RenderType>> renderType,
@Setter
private BiConsumer<Material, List<Component>> tooltip;

private final Map<Material, Supplier<? extends ItemLike>[]> ignoredMaterials = new HashMap<>();
private final Map<Material, @Unmodifiable Collection<Supplier<? extends ItemLike>>> ignoredMaterials = new HashMap<>();
private final Object2FloatMap<Material> materialAmounts = new Object2FloatOpenHashMap<>();

@Getter
Expand Down Expand Up @@ -1173,43 +1174,51 @@ public static TagPrefix getPrefix(String prefixName, @Nullable TagPrefix replace
return PREFIXES.getOrDefault(prefixName, replacement);
}

@SuppressWarnings("unchecked")
public TagKey<Item>[] getItemParentTags() {
return tags.stream().filter(TagType::isParentTag).map(type -> type.getTag(this, GTMaterials.NULL))
.toArray(TagKey[]::new);
public @Unmodifiable List<TagKey<Item>> getItemParentTags() {
return tags.stream()
.filter(TagType::isParentTag)
.map(type -> type.getTag(this, GTMaterials.NULL))
.filter(Objects::nonNull)
.toList();
}

@SuppressWarnings("unchecked")
public TagKey<Item>[] getItemTags(@NotNull Material mat) {
return tags.stream().filter(type -> !type.isParentTag()).map(type -> type.getTag(this, mat))
public @Unmodifiable List<TagKey<Item>> getItemTags(@NotNull Material mat) {
return tags.stream()
.filter(type -> !type.isParentTag())
.map(type -> type.getTag(this, mat))
.filter(Objects::nonNull)
.toArray(TagKey[]::new);
.toList();
}

@SuppressWarnings("unchecked")
public TagKey<Item>[] getAllItemTags(@NotNull Material mat) {
return tags.stream().map(type -> type.getTag(this, mat)).filter(Objects::nonNull).toArray(TagKey[]::new);
public @Unmodifiable List<TagKey<Item>> getAllItemTags(@NotNull Material mat) {
return tags.stream()
.map(type -> type.getTag(this, mat))
.filter(Objects::nonNull)
.toList();
}

@SuppressWarnings("unchecked")
public TagKey<Block>[] getBlockTags(@NotNull Material mat) {
return tags.stream().filter(type -> !type.isParentTag()).map(type -> type.getTag(this, mat))
.map(itemTagKey -> TagKey.create(Registries.BLOCK, itemTagKey.location())).toArray(TagKey[]::new);
public @Unmodifiable List<TagKey<Block>> getBlockTags(@NotNull Material mat) {
return tags.stream()
.filter(type -> !type.isParentTag())
.map(type -> type.getTag(this, mat))
.filter(Objects::nonNull)
.map(itemTagKey -> TagKey.create(Registries.BLOCK, itemTagKey.location()))
.toList();
}

@SuppressWarnings("unchecked")
public TagKey<Block>[] getAllBlockTags(@NotNull Material mat) {
public @Unmodifiable List<TagKey<Block>> getAllBlockTags(@NotNull Material mat) {
return tags.stream().map(type -> type.getTag(this, mat))
.map(itemTagKey -> TagKey.create(Registries.BLOCK, itemTagKey.location())).toArray(TagKey[]::new);
.filter(Objects::nonNull)
.map(itemTagKey -> TagKey.create(Registries.BLOCK, itemTagKey.location()))
.toList();
}

public boolean hasItemTable() {
return itemTable != null;
}

@SuppressWarnings("unchecked")
public Supplier<ItemLike> getItemFromTable(Material material) {
return (Supplier<ItemLike>) itemTable.get().get(this, material);
public Supplier<? extends ItemLike> getItemFromTable(Material material) {
return itemTable.get().get(this, material);
}

public boolean doGenerateItem() {
Expand Down Expand Up @@ -1267,41 +1276,51 @@ public boolean isIgnored(Material material) {

@SafeVarargs
public final void setIgnored(Material material, Supplier<? extends ItemLike>... items) {
setIgnored(material, Arrays.asList(items));
}

public final void setIgnored(Material material, Collection<Supplier<? extends ItemLike>> items) {
ignoredMaterials.put(material, items);
if (items.length > 0) {
ItemMaterialData.registerMaterialEntries(Arrays.asList(items), this, material);
if (!items.isEmpty()) {
ItemMaterialData.registerMaterialEntries(items, this, material);
}
}

@SuppressWarnings("unchecked")
public void setIgnored(Material material, ItemLike... items) {
// go through setIgnoredBlock to wrap if this is a block prefix
Collection<Supplier<? extends ItemLike>> collection = new ArrayList<>(items.length);
if (this.doGenerateBlock()) {
this.setIgnoredBlock(material,
Arrays.stream(items).filter(Block.class::isInstance).map(Block.class::cast).toArray(Block[]::new));
for (var item : items) {
if (item instanceof Block b) {
collection.add(GTMemoizer.memoizeBlockSupplier(() -> b));
}
}
} else {
this.setIgnored(material,
Arrays.stream(items).map(item -> (Supplier<ItemLike>) () -> item).toArray(Supplier[]::new));
for (var item : items) {
collection.add(() -> item);
}
}
setIgnored(material, collection);
}

@SuppressWarnings("unchecked")
public void setIgnoredBlock(Material material, Block... items) {
this.setIgnored(material, Arrays.stream(items).map(block -> GTMemoizer.memoizeBlockSupplier(() -> block))
.toArray(Supplier[]::new));
public void setIgnoredBlock(Material material, Block... blocks) {
Collection<Supplier<? extends ItemLike>> collection = new ArrayList<>(blocks.length);
for (var block : blocks) {
collection.add(GTMemoizer.memoizeBlockSupplier(() -> block));
}
setIgnored(material, collection);
}

@SuppressWarnings("unchecked")
public void setIgnored(Material material) {
this.ignoredMaterials.put(material, new Supplier[0]);
this.ignoredMaterials.put(material, List.of());
}

public void removeIgnored(Material material) {
ignoredMaterials.remove(material);
}

public Map<Material, Supplier<? extends ItemLike>[]> getIgnored() {
return new HashMap<>(ignoredMaterials);
public @Unmodifiable Map<Material, @Unmodifiable Collection<Supplier<? extends ItemLike>>> getIgnored() {
return Map.copyOf(ignoredMaterials);
}

public boolean isAmountModified(Material material) {
Expand Down
Loading