Skip to content

Commit

Permalink
Merge branch 'dev/1.20.1' into chore/code-health
Browse files Browse the repository at this point in the history
  • Loading branch information
Rover656 committed Sep 22, 2023
2 parents 5891209 + 8e7527f commit aa7be51
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 32 deletions.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ repositories { RepositoryHandler handler ->
exclusiveRepo(handler, 'https://maven.tterrag.com/', 'com.tterrag.registrate', 'com.jozufozu.flywheel')
exclusiveRepo(handler, 'https://modmaven.dev/', 'mezz.jei', 'mcjty.theoneprobe', 'appeng')
exclusiveRepo(handler, 'https://cursemaven.com', 'curse.maven')
exclusiveRepo(handler, 'https://maven.blamejared.com', 'vazkii.patchouli', 'net.darkhax.bookshelf', 'net.darkhax.enchdesc')
exclusiveRepo(handler, 'https://maven.blamejared.com', 'vazkii.patchouli', 'net.darkhax.bookshelf', 'net.darkhax.enchdesc', 'com.almostreliable.mods')
exclusiveRepo(handler, 'https://dogforce-games.com/maven', 'dev.gigaherz.graph')
exclusiveRepo(handler, 'https://api.modrinth.com/maven', 'maven.modrinth')

Expand Down Expand Up @@ -264,6 +264,9 @@ dependencies {
//Flywheel
compileOnly fg.deobf("com.jozufozu.flywheel:flywheel-forge-1.20.1:0.6.9-5") // REMOVE When crash is fixed

// Almost Unified
compileOnly fg.deobf("com.almostreliable.mods:almostunified-forge:${minecraft_version}-${almostunified_version}")

// Patchouli
// compileOnly fg.deobf("vazkii.patchouli:Patchouli:${patchouli_version}:api")
// runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:${patchouli_version}")
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ mekanism_cf_id=3922056
jade_cf_id=4614153
ench_desc_version=17.0.3
bookshelf_version=20.0.2
almostunified_version=0.6.0

# ===========================
# Combined Project Properties
Expand Down
12 changes: 11 additions & 1 deletion src/api/java/com/enderio/api/integration/Integration.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.SmeltingRecipe;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.data.event.GatherDataEvent;
import net.minecraftforge.eventbus.api.IEventBus;
Expand Down Expand Up @@ -79,4 +80,13 @@ default Optional<BlockState> getFacadeOf(ItemStack stack) {
default boolean canBlockTeleport(Player player) {
return false;
}
}

/**
* Usage intended for kubejs io, tell us if you need it for something else
* @param recipe The smelting recipe that is tried to be used in the AlloySmelter.
* @return true if this recipe can be used
*/
default boolean acceptSmeltingRecipe(SmeltingRecipe recipe) {
return true;
}
}
13 changes: 13 additions & 0 deletions src/core/java/com/enderio/core/EnderCore.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
package com.enderio.core;

import com.enderio.core.common.integration.Integrations;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLConstructModEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import static com.enderio.core.EnderCore.MODID;

// Little helper for logging and resource locations.
// This is because core has no access to base.
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class EnderCore {
// Stored here just to make sure its the same.
// This definition is used *everywhere* else.
public static final String MODID = "enderio";

public static final Logger LOGGER = LogManager.getLogger(MODID + ":core");

@SubscribeEvent
public static void onConstruct(FMLConstructModEvent event) {
System.out.println("================ Core construct ==================");
Integrations.register();
}

public static ResourceLocation loc(String name) {
return new ResourceLocation(MODID, name);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.enderio.core.common.integration;

import com.almostreliable.unified.api.AlmostUnifiedLookup;
import com.enderio.api.integration.Integration;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import org.jetbrains.annotations.Nullable;

public class AlmostUnifiedIntegration implements Integration {
@Nullable
public Item getPreferredItemForTag(TagKey<Item> tagKey) {
return AlmostUnifiedLookup.INSTANCE.getPreferredItemForTag(tagKey);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.enderio.core.common.integration;

import com.enderio.api.integration.IntegrationManager;
import com.enderio.api.integration.IntegrationWrapper;

public class Integrations {

public static final IntegrationWrapper<AlmostUnifiedIntegration> almostUnifiedIntegration = IntegrationManager.wrapper("almostunified", AlmostUnifiedIntegration::new);

public static void register() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@javax.annotation.ParametersAreNonnullByDefault
@net.minecraft.MethodsReturnNonnullByDefault
@com.tterrag.registrate.util.nullness.FieldsAreNonnullByDefault

package com.enderio.core.common.integration;
8 changes: 8 additions & 0 deletions src/core/java/com/enderio/core/common/util/TagUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.enderio.core.common.util;

import com.enderio.core.EnderCore;
import com.enderio.core.common.integration.Integrations;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraftforge.registries.ForgeRegistries;
Expand All @@ -13,11 +14,18 @@ public class TagUtil {
* Get an optional item from a tag.
* An optional item means the item may not actually be present, and if it isn't it is handled gracefully.
* It will search tags in the following order:
* - If Almost Unified is present, it will get the priority item from the tag.
* - Pulls an enderio item first, if present
* - Then goes down the tag looking in the order of modid precedence (from EnderIO config).
* - If we found nothing in our specified lists, we will pick the first present item.
*/
public static Optional<Item> getOptionalItem(TagKey<Item> tagKey) {
if (Integrations.almostUnifiedIntegration.isPresent()) {
Item preferredItem = Integrations.almostUnifiedIntegration.expectPresent().getPreferredItemForTag(tagKey);
if (preferredItem != null)
return Optional.of(preferredItem);
}

ITag<Item> tag = ForgeRegistries.ITEMS.tags().getTag(tagKey);

// Search for an EnderIO item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.enderio.EnderIO;
import com.enderio.api.capacitor.CapacitorModifier;
import com.enderio.api.capacitor.QuadraticScalable;
import com.enderio.api.integration.IntegrationManager;
import com.enderio.api.io.energy.EnergyIOMode;
import com.enderio.core.common.blockentity.EnderBlockEntity;
import com.enderio.core.common.network.slot.EnumNetworkDataSlot;
Expand Down Expand Up @@ -325,9 +326,8 @@ protected Optional<AlloySmeltingRecipe> findRecipe() {
for (int i = 0; i < AlloySmelterBlockEntity.INPUTS.size(); i++) {
var recipe = level.getRecipeManager()
.getRecipeFor(RecipeType.SMELTING, new ContainerSubWrapper(getContainer(), i), level);
if (recipe.isPresent()) {
if (recipe.isPresent() && IntegrationManager.allMatch(integration -> integration.acceptSmeltingRecipe(recipe.get())))
return Optional.of(new VanillaAlloySmeltingRecipe(recipe.get()));
}
}
}
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,18 @@ public IDrawable getIcon() {

@Override
public void setRecipe(IRecipeLayoutBuilder builder, SoulBindingRecipe recipe, IFocusGroup focuses) {
List<ItemStack> vials;
List<ItemStack> vials = new ArrayList<>();
Optional<IFocus<ItemStack>> output = focuses.getItemStackFocuses(OUTPUT).findFirst();
Optional<IFocus<ItemStack>> input = focuses.getItemStackFocuses(INPUT).filter(f -> f.getTypedValue().getItemStack().get().is(EIOItems.FILLED_SOUL_VIAL.asItem())).findFirst();

if (output.isPresent()) {
var item = new ItemStack(EIOItems.FILLED_SOUL_VIAL);
output.get().getTypedValue().getItemStack().get().getCapability(EIOCapabilities.ENTITY_STORAGE).ifPresent(cap -> {
SoulVialItem.setEntityType(item, cap.getStoredEntityData().getEntityType().get());
});

vials = List.of(item);
} else if (input.isPresent()) {
vials = List.of(input.get().getTypedValue().getIngredient());
if (input.isPresent()) {
vials.add(input.get().getTypedValue().getIngredient());
} else if (recipe.getEntityType() != null) {
var item = new ItemStack(EIOItems.FILLED_SOUL_VIAL);
SoulVialItem.setEntityType(item, recipe.getEntityType());

vials = List.of(item);
vials.add(item);
} else if (recipe.getMobCategory() != null) {
vials = new ArrayList<>();

var allEntitiesOfCategory = ForgeRegistries.ENTITY_TYPES.getValues().stream()
.filter(e -> e.getCategory().equals(recipe.getMobCategory()))
Expand All @@ -102,21 +94,37 @@ public void setRecipe(IRecipeLayoutBuilder builder, SoulBindingRecipe recipe, IF
}

} else if (recipe.getSouldata() != null){
vials = new ArrayList<>();
SoulDataReloadListener<? extends ISoulData> soulDataReloadListener = SoulDataReloadListener.fromString(recipe.getSouldata());

var allEntitiesOfSoulData = ForgeRegistries.ENTITY_TYPES.getKeys().stream()
.filter(r -> soulDataReloadListener.map.containsKey(r))
.toList();

for (ResourceLocation entity : allEntitiesOfSoulData) {
if (output.isPresent()) {
var item = new ItemStack(EIOItems.FILLED_SOUL_VIAL);
SoulVialItem.setEntityType(item, entity);
vials.add(item);
output.get().getTypedValue().getItemStack().get().getCapability(EIOCapabilities.ENTITY_STORAGE).ifPresent(cap -> {
SoulVialItem.setEntityType(item, cap.getStoredEntityData().getEntityType().get());
vials.add(item);
});
} else {
SoulDataReloadListener<? extends ISoulData> soulDataReloadListener = SoulDataReloadListener.fromString(recipe.getSouldata());

var allEntitiesOfSoulData = ForgeRegistries.ENTITY_TYPES.getKeys().stream()
.filter(r -> soulDataReloadListener.map.containsKey(r))
.toList();

for (ResourceLocation entity : allEntitiesOfSoulData) {
var item = new ItemStack(EIOItems.FILLED_SOUL_VIAL);
SoulVialItem.setEntityType(item, entity);
vials.add(item);
}
}


} else {
vials = SoulVialItem.getAllFilled();
if (output.isPresent()) {
var item = new ItemStack(EIOItems.FILLED_SOUL_VIAL);
output.get().getTypedValue().getItemStack().get().getCapability(EIOCapabilities.ENTITY_STORAGE).ifPresent(cap -> {
SoulVialItem.setEntityType(item, cap.getStoredEntityData().getEntityType().get());
vials.add(item);
});
} else {
vials.addAll(SoulVialItem.getAllFilled());
}
}

builder.addSlot(INPUT, 3, 4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@
import net.minecraftforge.fml.common.Mod;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

@SuppressWarnings("unused")
@Mod.EventBusSubscriber(modid = EnderIO.MODID)
public class FireCraftingHandler {
private static final Random RANDOM = new Random();
private static final Map<FireIndex, Long> FIRE_TRACKER = new HashMap<>();
private static final ConcurrentMap<FireIndex, Long> FIRE_TRACKER = new ConcurrentHashMap<>();

private static List<FireCraftingRecipe> cachedRecipes;
private static boolean recipesCached = false;
Expand Down Expand Up @@ -104,8 +105,7 @@ public static void on(BlockEvent.NeighborNotifyEvent event) {
}

public static void spawnInfinityDrops(ServerLevel level, BlockPos pos, ResourceLocation lootTable, int maxItemDrops) {
LootParams lootparams = (new LootParams.Builder(level)).withParameter(LootContextParams.ORIGIN, pos.getCenter()).create(
LootContextParamSets.COMMAND);
LootParams lootparams = (new LootParams.Builder(level)).withParameter(LootContextParams.ORIGIN, pos.getCenter()).create(LootContextParamSets.COMMAND);

LootTable table = level.getServer().getLootData().getElement(LootDataType.TABLE, lootTable);

Expand All @@ -124,7 +124,7 @@ public static void spawnInfinityDrops(ServerLevel level, BlockPos pos, ResourceL
itemEntity.setDefaultPickUpDelay();

// Make it survive the fire for a bit
itemEntity.hurt(itemEntity.damageSources().inFire(), -100);
itemEntity.hurt(itemEntity.damageSources().inFire(), -100);

// Actually set it on fire
itemEntity.setRemainingFireTicks(10);
Expand Down

0 comments on commit aa7be51

Please sign in to comment.