Skip to content

Commit

Permalink
misc fix&tool (#1627)
Browse files Browse the repository at this point in the history
  • Loading branch information
gateguardian523 authored Aug 7, 2024
1 parent de7a117 commit 44574f9
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"res": "gtceu:aluminium_frame"
},
"items": [
"#minecraft:climbable",
"#forge:frames"
"#forge:frames",
"#minecraft:climbable"
],
"page": "gtceu:materials/frame",
"position": [
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/com/gregtechceu/gtceu/api/data/DimensionMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,38 @@ public class DimensionMarker {
public static final int MAX_TIER = 99;

@Getter
public final int tier; // Not only used to represent dimension tier, but also for sorting
public final int tier; // not only used to represent dimension tier, but also for sorting

@Getter
@Nullable
private final String overrideName;
private final String overrideName; // there may be other uses, so we store it

private final SupplierMemoizer.MemoizedSupplier<ItemStack> markerSupplier;
private final SupplierMemoizer.MemoizedSupplier<ItemStack> iconSupplier;

public DimensionMarker(int tier, ResourceLocation resourceLocation, @Nullable String overrideName) {
public DimensionMarker(int tier, ResourceLocation itemKey, @Nullable String overrideName) {
this.tier = tier;
this.markerSupplier = SupplierMemoizer.memoize(() -> ForgeRegistries.ITEMS.getDelegate(resourceLocation)
this.overrideName = overrideName;
this.iconSupplier = SupplierMemoizer.memoize(() -> ForgeRegistries.ITEMS.getDelegate(itemKey)
.map(Holder::get)
.map(this::getStack)
.orElse(ItemStack.EMPTY));
this.overrideName = overrideName;
}

public DimensionMarker(int tier, Supplier<? extends ItemLike> supplier, @Nullable String overrideName) {
this.tier = tier;
this.markerSupplier = SupplierMemoizer.memoize(() -> getStack(supplier.get().asItem()));
this.overrideName = overrideName;
this.iconSupplier = SupplierMemoizer.memoize(() -> getStack(supplier.get().asItem()));
}

public ItemStack getMarker() {
return markerSupplier.get();
public ItemStack getIcon() {
return iconSupplier.get();
}

public void register(ResourceLocation id) {
public void register(ResourceLocation dimKey) {
if (tier < 0 || tier >= MAX_TIER) {
throw new IllegalArgumentException("Tier must be between 0 and " + (MAX_TIER - 1));
}
GTRegistries.DIMENSION_MARKERS.register(id, this);
GTRegistries.DIMENSION_MARKERS.register(dimKey, this);
}

private ItemStack getStack(Item item) {
Expand All @@ -76,12 +77,12 @@ public static class Builder extends BuilderBase<DimensionMarker> {
@Nullable
private String overrideName;

public Builder(ResourceLocation id) {
super(id);
public Builder(ResourceLocation dimKey) {
super(dimKey);
}

public Builder(ResourceLocation id, Object... args) {
this(id);
public Builder(ResourceLocation dimKey, Object... args) {
this(dimKey);
}

@HideFromJS
Expand Down
16 changes: 1 addition & 15 deletions src/main/java/com/gregtechceu/gtceu/api/item/IGTTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.TierSortingRegistry;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.LazyOptional;
Expand Down Expand Up @@ -911,20 +910,7 @@ T> LazyOptional<T> getCapability(@NotNull Capability<T> capability,

default boolean definition$isCorrectToolForDrops(ItemStack stack, BlockState state) {
if (stack.getItem() instanceof IGTTool gtTool) {
boolean isCorrectToolType = gtTool.getToolClasses(stack).stream()
.anyMatch(type -> type.harvestTags.stream().anyMatch(state::is));
if (!isCorrectToolType) {
return false;
}

final int totalLevel = gtTool.getTotalHarvestLevel(stack);
List<Tier> tiers = TierSortingRegistry.getSortedTiers().stream()
.filter(tier -> tier.getLevel() == totalLevel)
.toList();
Tier tier = !tiers.isEmpty() ? tiers.get(tiers.size() - 1) : null;

if (tier == null) return false;
return TierSortingRegistry.isCorrectTierForDrops(tier, state);
return isToolEffective(state, gtTool.getToolClasses(stack), gtTool.getTotalHarvestLevel(stack));
}
return stack.getItem().isCorrectToolForDrops(state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.animal.IronGolem;
import net.minecraft.world.entity.monster.Spider;
Expand Down Expand Up @@ -50,6 +51,7 @@ public class GTToolType {
.build();
public static final GTToolType PICKAXE = GTToolType.builder("pickaxe")
.toolTag(TagUtil.createItemTag("pickaxes", true))
.toolTag(ItemTags.CLUSTER_MAX_HARVESTABLES)
.harvestTag(TagUtil.createBlockTag("mineable/pickaxe", true))
.toolStats(b -> b.blockBreaking().attackDamage(1.0F).attackSpeed(-2.8F))
/* .behaviors(TorchPlaceBehavior.INSTANCE) */
Expand Down Expand Up @@ -219,6 +221,7 @@ public class GTToolType {
.toolTag(TagUtil.createItemTag("tools/drills", false))
.toolTag(TagUtil.createItemTag("pickaxes", true))
.toolTag(TagUtil.createItemTag("shovels", true))
.toolTag(ItemTags.CLUSTER_MAX_HARVESTABLES)
.harvestTag(TagUtil.createBlockTag("mineable/pickaxe", true))
.harvestTag(TagUtil.createBlockTag("mineable/shovel", true))
.toolStats(b -> b.blockBreaking().aoe(1, 1, 0)
Expand All @@ -234,6 +237,7 @@ public class GTToolType {
.toolTag(TagUtil.createItemTag("tools/drills", false))
.toolTag(TagUtil.createItemTag("pickaxes", true))
.toolTag(TagUtil.createItemTag("shovels", true))
.toolTag(ItemTags.CLUSTER_MAX_HARVESTABLES)
.harvestTag(TagUtil.createBlockTag("mineable/pickaxe", true))
.harvestTag(TagUtil.createBlockTag("mineable/shovel", true))
.toolStats(b -> b.blockBreaking().aoe(1, 1, 2)
Expand All @@ -249,6 +253,7 @@ public class GTToolType {
.toolTag(TagUtil.createItemTag("tools/drills", false))
.toolTag(TagUtil.createItemTag("pickaxes", true))
.toolTag(TagUtil.createItemTag("shovels", true))
.toolTag(ItemTags.CLUSTER_MAX_HARVESTABLES)
.harvestTag(TagUtil.createBlockTag("mineable/pickaxe", true))
.harvestTag(TagUtil.createBlockTag("mineable/shovel", true))
.toolStats(b -> b.blockBreaking().aoe(2, 2, 4)
Expand All @@ -264,6 +269,7 @@ public class GTToolType {
.toolTag(TagUtil.createItemTag("tools/drills", false))
.toolTag(TagUtil.createItemTag("pickaxes", true))
.toolTag(TagUtil.createItemTag("shovels", true))
.toolTag(ItemTags.CLUSTER_MAX_HARVESTABLES)
.harvestTag(TagUtil.createBlockTag("mineable/pickaxe", true))
.harvestTag(TagUtil.createBlockTag("mineable/shovel", true))
.toolStats(b -> b.blockBreaking().aoe(3, 3, 6)
Expand All @@ -279,6 +285,7 @@ public class GTToolType {
.toolTag(TagUtil.createItemTag("tools/drills", false))
.toolTag(TagUtil.createItemTag("pickaxes", true))
.toolTag(TagUtil.createItemTag("shovels", true))
.toolTag(ItemTags.CLUSTER_MAX_HARVESTABLES)
.harvestTag(TagUtil.createBlockTag("mineable/pickaxe", true))
.harvestTag(TagUtil.createBlockTag("mineable/shovel", true))
.toolStats(b -> b.blockBreaking().aoe(4, 4, 8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,10 @@ public static boolean isCorrectTierForDrops(BlockState state, int tier) {
}

private static Tier getTier(int harvestLevel) {
return TierSortingRegistry.getSortedTiers().stream()
.dropWhile(tier -> tier.getLevel() < harvestLevel || tier.getLevel() > harvestLevel).findAny()
.orElse(Tiers.WOOD);
List<Tier> tiers = TierSortingRegistry.getSortedTiers().stream()
.filter(tier -> tier.getLevel() == harvestLevel)
.toList();
return !tiers.isEmpty() ? tiers.get(tiers.size() - 1) : Tiers.WOOD;
}

public static boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ public Component getTooltips() {
public SlotWidget setupDimensionMarkers(int xOffset, int yOffset) {
DimensionMarker dimMarker = GTRegistries.DIMENSION_MARKERS.getOrDefault(this.dimension,
new DimensionMarker(DimensionMarker.MAX_TIER, () -> Blocks.BARRIER, this.dimension.toString()));
ItemStack item = dimMarker.getMarker();
ItemStack icon = dimMarker.getIcon();
ItemStackTransfer transfer = new ItemStackTransfer(1);
SlotWidget dimSlot = new SlotWidget(transfer, 0, xOffset, yOffset, false, false)
.setIngredientIO(IngredientIO.INPUT);
transfer.setStackInSlot(0, item);
transfer.setStackInSlot(0, icon);
if (ConfigHolder.INSTANCE.compat.showDimensionTier) {
dimSlot.setOverlay(
new TextTexture("T" + (dimMarker.tier >= DimensionMarker.MAX_TIER ? "?" : dimMarker.tier))
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/gregtechceu/gtceu/data/recipe/CustomTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ public class CustomTags {
public static final TagKey<Item> OpV_CIRCUITS = TagUtil.createModItemTag("circuits/opv");
public static final TagKey<Item> MAX_CIRCUITS = TagUtil.createModItemTag("circuits/max");

@SuppressWarnings("unchecked")
public static final TagKey<Item>[] CIRCUITS = new TagKey[] {
ULV_CIRCUITS,
LV_CIRCUITS,
MV_CIRCUITS,
HV_CIRCUITS,
EV_CIRCUITS,
IV_CIRCUITS,
LuV_CIRCUITS,
ZPM_CIRCUITS,
UV_CIRCUITS,
UHV_CIRCUITS,
UEV_CIRCUITS,
UIV_CIRCUITS,
UXV_CIRCUITS,
OpV_CIRCUITS,
MAX_CIRCUITS
};

public static final TagKey<Item> ULV_BATTERIES = TagUtil.createModItemTag("batteries/ulv");
public static final TagKey<Item> LV_BATTERIES = TagUtil.createModItemTag("batteries/lv");
public static final TagKey<Item> MV_BATTERIES = TagUtil.createModItemTag("batteries/mv");
Expand All @@ -57,6 +76,20 @@ public class CustomTags {
public static final TagKey<Item> UV_BATTERIES = TagUtil.createModItemTag("batteries/uv");
public static final TagKey<Item> UHV_BATTERIES = TagUtil.createModItemTag("batteries/uhv");

@SuppressWarnings("unchecked")
public static final TagKey<Item>[] BATTERIES = new TagKey[] {
ULV_BATTERIES,
LV_BATTERIES,
MV_BATTERIES,
HV_BATTERIES,
EV_BATTERIES,
IV_BATTERIES,
LuV_BATTERIES,
ZPM_BATTERIES,
UV_BATTERIES,
UHV_BATTERIES
};

public static final TagKey<Item> PPE_ARMOR = TagUtil.createModItemTag("ppe_armor");

// Platform-dependent tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ private void setupDimensionMarker(int yPosition) {
var transfer = new ItemStackTransfer(dimMarkers.length);
for (int i = 0; i < dimMarkers.length; i++) {
var dimMarker = dimMarkers[i];
var markerItem = dimMarker.getMarker();
var icon = dimMarker.getIcon();
int row = Math.floorDiv(i, rowSlots);
SlotWidget dimSlot = new SlotWidget(transfer, i,
5 + (16 + interval) * (i - row * rowSlots),
yPosition + 18 * row,
false, false).setIngredientIO(IngredientIO.CATALYST);
transfer.setStackInSlot(i, markerItem);
transfer.setStackInSlot(i, icon);
if (ConfigHolder.INSTANCE.compat.showDimensionTier) {
dimSlot.setOverlay(
new TextTexture("T" + (dimMarker.tier >= DimensionMarker.MAX_TIER ? "?" : dimMarker.tier))
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/gregtechceu/gtceu/utils/FormattingUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ public static String formatPercent(double number) {
return String.format("%,.2f", number);
}

/** To avoids (un)boxing. */
public static String formatNumbers(int number) {
return NUMBER_FORMAT.format(number);
}

public static String formatNumbers(long number) {
return NUMBER_FORMAT.format(number);
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/gregtechceu/gtceu/utils/GTTransferUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,26 @@ public static ItemStack insertItemAccountNotifiableList(IItemTransfer handler, i
return handler.insertItem(slot, stack, simulate);
}

public static ItemStack extractItemAccountNotifiableList(
IItemTransfer handler, int slot, int amount,
boolean simulate) {
if (handler instanceof ItemTransferList transferList) {
int index = 0;
for (var transfer : transferList.transfers) {
if (slot - index < transfer.getSlots()) {
if (transfer instanceof NotifiableItemStackHandler notifiable) {
return notifiable.extractItemInternal(slot - index, amount, simulate);
} else {
return transfer.extractItem(slot - index, amount, simulate);
}
}
index += transfer.getSlots();
}
return ItemStack.EMPTY;
}
return handler.extractItem(slot, amount, simulate);
}

/**
* Only inerts to empty slots. Perfect for not stackable items
*/
Expand Down

0 comments on commit 44574f9

Please sign in to comment.