Keep energy in items when crafting
This commit is contained in:
parent
d1b395f3e4
commit
bc47a03451
2 changed files with 59 additions and 0 deletions
|
@ -43,6 +43,7 @@ import techreborn.events.ModRegistry;
|
|||
import techreborn.init.*;
|
||||
import techreborn.packets.ClientboundPackets;
|
||||
import techreborn.packets.ServerboundPackets;
|
||||
import techreborn.utils.PoweredCraftingHandler;
|
||||
import techreborn.world.WorldGenerator;
|
||||
|
||||
public class TechReborn implements ModInitializer {
|
||||
|
@ -77,6 +78,7 @@ public class TechReborn implements ModInitializer {
|
|||
//Force loads the block entities at the right time
|
||||
TRBlockEntities.THERMAL_GEN.toString();
|
||||
TRDispenserBehavior.init();
|
||||
PoweredCraftingHandler.setup();
|
||||
|
||||
Torus.genSizeMap(TechRebornConfig.fusionControlComputerMaxCoilSize);
|
||||
|
||||
|
|
57
src/main/java/techreborn/utils/PoweredCraftingHandler.java
Normal file
57
src/main/java/techreborn/utils/PoweredCraftingHandler.java
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2020 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.utils;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import reborncore.api.events.ItemCraftCallback;
|
||||
import team.reborn.energy.Energy;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public final class PoweredCraftingHandler implements ItemCraftCallback {
|
||||
|
||||
private PoweredCraftingHandler() {
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
ItemCraftCallback.EVENT.register(new PoweredCraftingHandler());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraft(ItemStack stack, CraftingInventory craftingInventory, PlayerEntity playerEntity) {
|
||||
if (Energy.valid(stack)) {
|
||||
double totalEnergy = IntStream.range(0, craftingInventory.getInvSize())
|
||||
.mapToObj(craftingInventory::getInvStack)
|
||||
.filter(s -> !s.isEmpty())
|
||||
.filter(Energy::valid)
|
||||
.mapToDouble(s -> Energy.of(s).getEnergy())
|
||||
.sum();
|
||||
|
||||
Energy.of(stack).set(totalEnergy);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue