This commit is contained in:
parent
9ec92ee4d9
commit
2ca8870775
@ -1,9 +1,12 @@
|
||||
package com.thebrokenrail.energonrelics.block.entity.infuser;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@ -13,6 +16,9 @@ import net.minecraft.world.explosion.Explosion;
|
||||
interface InfuserAction {
|
||||
void run(World world, BlockPos pos);
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
InfuserOutputItem display();
|
||||
|
||||
class ItemAction implements InfuserAction {
|
||||
final ItemStack stack;
|
||||
|
||||
@ -28,6 +34,12 @@ interface InfuserAction {
|
||||
public void run(World world, BlockPos pos) {
|
||||
Block.dropStack(world, pos, stack);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@Override
|
||||
public InfuserOutputItem display() {
|
||||
return new InfuserOutputItem(true, stack);
|
||||
}
|
||||
}
|
||||
|
||||
class ExplosionAction implements InfuserAction {
|
||||
@ -36,6 +48,12 @@ interface InfuserAction {
|
||||
world.setBlockState(pos, Blocks.AIR.getDefaultState());
|
||||
world.createExplosion(null, pos.getX() + 0.5d, pos.getY() + 0.5d, pos.getZ() + 0.5d, 3f, true, Explosion.DestructionType.DESTROY);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@Override
|
||||
public InfuserOutputItem display() {
|
||||
return new InfuserOutputItem(false, new ItemStack(Items.TNT));
|
||||
}
|
||||
}
|
||||
|
||||
class ParticleAction implements InfuserAction {
|
||||
@ -43,5 +61,11 @@ interface InfuserAction {
|
||||
public void run(World world, BlockPos pos) {
|
||||
((ServerWorld) world).spawnParticles(ParticleTypes.SMOKE, pos.getX() + 0.5d, pos.getY() + 0.5d, pos.getZ() + 0.5d, 38, 0.31f, 0.31f, 0.31f, 0f);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@Override
|
||||
public InfuserOutputItem display() {
|
||||
return new InfuserOutputItem(false, new ItemStack(Items.FIRE_CHARGE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
package com.thebrokenrail.energonrelics.block.entity.infuser;
|
||||
|
||||
import com.thebrokenrail.energonrelics.util.WeightedList;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@ -39,18 +40,18 @@ public class InfuserEntry {
|
||||
weightedList.pick(world.random).run(world, pos);
|
||||
}
|
||||
|
||||
public List<ItemStack> getOutputItems(boolean isFail) {
|
||||
@Environment(EnvType.CLIENT)
|
||||
public List<InfuserOutputItem> getOutputItems(boolean isFail) {
|
||||
InfuserAction[] actionList = isFail ? fail : success;
|
||||
List<ItemStack> list = new ArrayList<>();
|
||||
List<InfuserOutputItem> list = new ArrayList<>();
|
||||
for (InfuserAction action : actionList) {
|
||||
if (action instanceof InfuserAction.ItemAction) {
|
||||
list.add(((InfuserAction.ItemAction) action).stack);
|
||||
}
|
||||
list.add(action.display());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public double getSingleChance(boolean isFail) {
|
||||
return (1d / (double) success.length) * (isFail ? 1d - successChance : successChance);
|
||||
return (1d / (double) (isFail ? fail.length : success.length)) * (isFail ? 1d - successChance : successChance);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.thebrokenrail.energonrelics.block.entity.infuser;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class InfuserOutputItem {
|
||||
public final boolean outputsItem;
|
||||
public final ItemStack stack;
|
||||
|
||||
public InfuserOutputItem(boolean outputsItem, ItemStack item) {
|
||||
this.outputsItem = outputsItem;
|
||||
this.stack = item;
|
||||
}
|
||||
}
|
@ -61,6 +61,9 @@ public class InfuserRegistry {
|
||||
add(Items.COAL, new InfuserEntry(340, 0.2d, new InfuserAction[]{new InfuserAction.ItemAction(Items.DIAMOND)}, new InfuserAction[]{new InfuserAction.ExplosionAction()}));
|
||||
|
||||
add(EnergonRelics.VERIDIUM_INGOT_ITEM, new InfuserEntry(240, 0.25d, new InfuserAction[]{new InfuserAction.ItemAction(EnergonRelics.VERIDIUM_ORB_ITEM)}, new InfuserAction[]{new InfuserAction.ParticleAction(), new InfuserAction.ParticleAction(), new InfuserAction.ExplosionAction()}));
|
||||
|
||||
add(Items.GOLD_NUGGET, new InfuserEntry(260, 0.3d, new InfuserAction[]{new InfuserAction.ItemAction(Items.GOLD_INGOT)}, new InfuserAction[]{new InfuserAction.ItemAction(Items.IRON_NUGGET), new InfuserAction.ParticleAction()}));
|
||||
add(Items.IRON_NUGGET, new InfuserEntry(260, 0.3d, new InfuserAction[]{new InfuserAction.ItemAction(Items.IRON_INGOT)}, new InfuserAction[]{new InfuserAction.ParticleAction()}));
|
||||
}
|
||||
|
||||
private static void addTransform(Item[] items, long cost, double successChance) {
|
||||
|
@ -2,7 +2,9 @@ package com.thebrokenrail.energonrelics.client.rei;
|
||||
|
||||
import com.thebrokenrail.energonrelics.EnergonRelics;
|
||||
import com.thebrokenrail.energonrelics.block.entity.infuser.InfuserEntry;
|
||||
import com.thebrokenrail.energonrelics.block.entity.infuser.InfuserOutputItem;
|
||||
import com.thebrokenrail.energonrelics.block.entity.infuser.InfuserRegistry;
|
||||
import com.thebrokenrail.energonrelics.util.BooleanIterator;
|
||||
import me.shedaniel.rei.api.EntryStack;
|
||||
import me.shedaniel.rei.api.RecipeHelper;
|
||||
import me.shedaniel.rei.api.plugins.REIPluginV0;
|
||||
@ -32,14 +34,12 @@ public class EnergonRelicsPlugin implements REIPluginV0 {
|
||||
@Override
|
||||
public void registerRecipeDisplays(RecipeHelper recipeHelper) {
|
||||
for (Map.Entry<Item, InfuserEntry> entry : InfuserRegistry.entrySet()) {
|
||||
List<ItemStack> success = entry.getValue().getOutputItems(false);
|
||||
if (success.size() > 0) {
|
||||
recipeHelper.registerDisplay(new InfuserDisplay(new ItemStack(entry.getKey()), success, entry.getValue().getSingleChance(false), entry.getValue().cost));
|
||||
}
|
||||
List<ItemStack> fail = entry.getValue().getOutputItems(true);
|
||||
if (fail.size() > 0) {
|
||||
recipeHelper.registerDisplay(new InfuserDisplay(new ItemStack(entry.getKey()), fail, entry.getValue().getSingleChance(true), entry.getValue().cost));
|
||||
}
|
||||
BooleanIterator.run(isFail -> {
|
||||
List<InfuserOutputItem> list = entry.getValue().getOutputItems(isFail);
|
||||
for (InfuserOutputItem item : list) {
|
||||
recipeHelper.registerDisplay(new InfuserDisplay(new ItemStack(entry.getKey()), item, entry.getValue().getSingleChance(isFail), entry.getValue().cost));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,10 @@ import me.shedaniel.rei.gui.widget.Widget;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
@ -25,12 +27,21 @@ public class InfuserCategory implements RecipeCategory<InfuserDisplay> {
|
||||
Point startPoint = new Point(bounds.getCenterX() - 41, bounds.y + 10);
|
||||
List<Widget> widgets = new ArrayList<>();
|
||||
widgets.add(Widgets.createRecipeBase(bounds));
|
||||
widgets.add(Widgets.createResultSlotBackground(new Point(startPoint.x + 61, startPoint.y + 26)));
|
||||
widgets.add(Widgets.createLabel(new Point(bounds.x + bounds.width / 2, bounds.y + 9), new TranslatableText("category.rei." + EnergonRelics.NAMESPACE + ".infuser.chance", new DecimalFormat("###.##").format(display.successChance * 100d))).noShadow().centered().color(0xFF404040, 0xFFBBBBBB));
|
||||
widgets.add(Widgets.createLabel(new Point(bounds.x + bounds.width / 2, bounds.y + 18), new TranslatableText("category.rei." + EnergonRelics.NAMESPACE + ".infuser.cost", display.cost)).noShadow().centered().color(0xFF404040, 0xFFBBBBBB));
|
||||
widgets.add(Widgets.createArrow(new Point(startPoint.x + 24, startPoint.y + 25)).animationDurationTicks(HardcodedConfig.INFUSER_TIME));
|
||||
widgets.add(Widgets.createSlot(new Point(startPoint.x + 1, startPoint.y + 26)).entries(display.getInputEntries().get(0)).markInput());
|
||||
widgets.add(Widgets.createSlot(new Point(startPoint.x + 61, startPoint.y + 26)).entries(display.getOutputEntries()).disableBackground().markOutput());
|
||||
|
||||
int outputX = startPoint.x + 61;
|
||||
int outputY = startPoint.y + 26;
|
||||
if (display.outputsItem) {
|
||||
widgets.add(Widgets.createResultSlotBackground(new Point(startPoint.x + 61, startPoint.y + 26)));
|
||||
widgets.add(Widgets.createSlot(new Point(outputX, outputY)).entries(display.getOutputEntries()).disableBackground().markOutput());
|
||||
} else {
|
||||
Identifier outputID = Registry.ITEM.getId(display.getOutputEntries().get(0).getItem());
|
||||
Text text = new TranslatableText("category.rei." + EnergonRelics.NAMESPACE + ".infuser.display_item." + outputID.getNamespace() + "." + outputID.getPath());
|
||||
widgets.add(Widgets.createLabel(new Point(outputX - 7, outputY + 3), text).noShadow().leftAligned().color(0xFF404040, 0xFFBBBBBB));
|
||||
}
|
||||
return widgets;
|
||||
}
|
||||
|
||||
|
@ -1,32 +1,28 @@
|
||||
package com.thebrokenrail.energonrelics.client.rei;
|
||||
|
||||
import com.thebrokenrail.energonrelics.block.entity.infuser.InfuserOutputItem;
|
||||
import me.shedaniel.rei.api.EntryStack;
|
||||
import me.shedaniel.rei.api.RecipeDisplay;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class InfuserDisplay implements RecipeDisplay {
|
||||
private final EntryStack input;
|
||||
private final List<EntryStack> output;
|
||||
private final EntryStack output;
|
||||
public final boolean outputsItem;
|
||||
public final double successChance;
|
||||
public final long cost;
|
||||
|
||||
public InfuserDisplay(ItemStack input, List<ItemStack> output, double successChance, long cost) {
|
||||
public InfuserDisplay(ItemStack input, InfuserOutputItem output, double successChance, long cost) {
|
||||
this.input = EntryStack.create(input);
|
||||
List<EntryStack> newList = new ArrayList<>();
|
||||
for (ItemStack outputStack : output) {
|
||||
newList.add(EntryStack.create(outputStack));
|
||||
}
|
||||
this.output = newList;
|
||||
this.output = EntryStack.create(output.stack.copy());
|
||||
outputsItem = output.outputsItem;
|
||||
this.successChance = successChance;
|
||||
this.cost = cost;
|
||||
}
|
||||
@ -38,7 +34,7 @@ public class InfuserDisplay implements RecipeDisplay {
|
||||
|
||||
@Override
|
||||
public List<EntryStack> getOutputEntries() {
|
||||
return output;
|
||||
return Collections.singletonList(output);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,14 @@
|
||||
package com.thebrokenrail.energonrelics.util;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class BooleanIterator {
|
||||
public static void run(Consumer<Boolean> function) {
|
||||
function.accept(false);
|
||||
function.accept(true);
|
||||
}
|
||||
}
|
@ -57,5 +57,7 @@
|
||||
"block.energonrelics.energy_projector": "Energy Projector",
|
||||
"block.energonrelics.energy_beam": "Energy Beam",
|
||||
"block.energonrelics.energy_portal": "Energy Portal",
|
||||
"block.energonrelics.energized_obsidian": "Energized Obsidian"
|
||||
"block.energonrelics.energized_obsidian": "Energized Obsidian",
|
||||
"category.rei.energonrelics.infuser.display_item.minecraft.tnt": "Explosion",
|
||||
"category.rei.energonrelics.infuser.display_item.minecraft.fire_charge": "Nothing"
|
||||
}
|
Reference in New Issue
Block a user