Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Jan 13, 2024
1 parent e0cce5f commit f839ca9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//file:noinspection GroovyAccessibility
//file:noinspection GradlePackageVersionRange
plugins {
id "fabric-loom" version "1.4.+"
id "fabric-loom" version "1.5.+"
id "maven-publish"
id "me.modmuss50.mod-publish-plugin" version "0.3.5"
}
Expand Down
2 changes: 1 addition & 1 deletion changelog/1.2.11.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Create: Enchantment Industry 1.2.10
## Create: Enchantment Industry 1.2.11

### Update
- Fix items in the right most slot being dropped when clicked inside the Printing Guide menu
4 changes: 4 additions & 0 deletions changelog/1.2.12.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Create: Enchantment Industry 1.2.12

### Update
- Fix NPE with jade
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx2G
# Mod Info
maven_group = plus.dragons.createenchantmentindustry
archives_base_name = create_enchantment_industry
mod_version = 1.2.11
mod_version = 1.2.12

minecraft_version = 1.20.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,29 @@
import javax.annotation.Nullable;

@Mixin(AbstractFurnaceBlockEntity.class)
abstract public class AbstractFurnaceBlockEntityMixin<T> extends BaseContainerBlockEntity implements WorldlyContainer, RecipeHolder, StackedContentsCompatible, SidedStorageBlockEntity {
abstract public class AbstractFurnaceBlockEntityMixin extends BaseContainerBlockEntity implements WorldlyContainer, RecipeHolder, StackedContentsCompatible, SidedStorageBlockEntity {
protected AbstractFurnaceBlockEntityMixin(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
}

@Shadow
private Object2IntOpenHashMap<ResourceLocation> recipesUsed;
@Shadow @Final private Object2IntOpenHashMap<ResourceLocation> recipesUsed;

@Unique
protected long calculateExperienceStored() {
double total = 0.0;
for (var entry : recipesUsed.object2IntEntrySet()) {
total += getLevel().getRecipeManager().byKey(entry.getKey()).map(recipe -> {
return (double)((AbstractCookingRecipe) recipe).getExperience() * entry.getIntValue();
}).orElse(0.0);
total += getLevel().getRecipeManager().byKey(entry.getKey()).map(recipe -> (double)((AbstractCookingRecipe) recipe).getExperience() * entry.getIntValue()).orElse(0.0);
}
total *= UNIT_PER_MB;
EnchantmentIndustry.LOGGER.debug("Furnace XP amount: {}", total);
return (long)total;
}

@Inject(method = "setRecipeUsed", at = @At("TAIL"), cancellable = true)
@Inject(method = "setRecipeUsed", at = @At("TAIL"))
private void injectSetRecipeUsed(@Nullable Recipe<?> recipe, CallbackInfo ci) {
if (recipe != null) {
long amount = internalTank.getFluidAmount();
amount += (amount == 0) ? calculateExperienceStored() :
Math.floor(((AbstractCookingRecipe) recipe).getExperience() * UNIT_PER_MB);
(long) Math.floor(((AbstractCookingRecipe) recipe).getExperience() * UNIT_PER_MB);
internalTank.setFluid(new FluidStack(FluidVariant.of(CeiFluids.EXPERIENCE.getSource()), amount));
}
}
Expand All @@ -87,27 +83,23 @@ protected void onContentsChanged() {
return;
}

EnchantmentIndustry.LOGGER.debug("Furnace XP removing recipes for a total of {} out of {}", diff, total);

if (diff >= total) {
EnchantmentIndustry.LOGGER.debug("Furnace XP removing all recipes");
recipesUsed.clear();
return;
}

var recipeManager = getLevel().getRecipeManager();
var it = recipesUsed.object2IntEntrySet();
var entriesUsed = StreamSupport.stream(it.spliterator(), false)
var entriesUsed = it.stream()
.filter(e -> recipeManager.byKey(e.getKey()).isPresent())
.collect(Collectors.toList());
.toList();
for (var entry : entriesUsed) {
var usedRecipe = (AbstractCookingRecipe)recipeManager.byKey(entry.getKey()).get();
long experience = (long)(usedRecipe.getExperience() * UNIT_PER_MB);
int count = (int)Math.min((diff / experience), entry.getIntValue());
if (count > 0) {
diff -= experience;
recipesUsed.addTo(usedRecipe.getId(), -count);
EnchantmentIndustry.LOGGER.debug("Furnace XP removed {} recipe {} times", entry.getKey(), count);
}
}
}
Expand All @@ -118,9 +110,8 @@ protected void onContentsChanged() {

@Override
public @Nullable Storage<FluidVariant> getFluidStorage(Direction side) {
if (side.getAxis().isHorizontal()) {
return exposedExperienceTank;
}
return null;
if (side != null && side.getAxis().isHorizontal())
return exposedExperienceTank;
return null;
}
}

0 comments on commit f839ca9

Please sign in to comment.