Add REI Plugin
EnergonRelics/pipeline/head This commit looks good Details

This commit is contained in:
TheBrokenRail 2020-07-30 15:49:18 -04:00
parent 7bc126ba96
commit 7d224ea353
20 changed files with 331 additions and 40 deletions

View File

@ -28,7 +28,9 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
modImplementation "io.github.prospector:modmenu:${project.modmenu_version}"
//modImplementation "me.shedaniel:RoughlyEnoughItems:${project.roughlyenoughitems_version}"
modCompileOnly "me.shedaniel:RoughlyEnoughItems-api:${project.roughlyenoughitems_version}"
modRuntime "me.shedaniel:RoughlyEnoughItems:${project.roughlyenoughitems_version}"
modImplementation "me.shedaniel.cloth:config-2:${project.cloth_config_version}"
include "me.shedaniel.cloth:config-2:${project.cloth_config_version}"

View File

@ -18,4 +18,4 @@ org.gradle.jvmargs = -Xmx1G
cloth_config_version = 4.7.0-unstable
autoconfig_version = 3.2.0-unstable
libstructure_version = 1.4.1
roughlyenoughitems_version = 5.0.0-unstable
roughlyenoughitems_version = 5.0.1-unstable

View File

@ -1,13 +1,29 @@
package com.thebrokenrail.energonrelics.block.battery;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.block.entity.battery.BatteryCoreBlockEntity;
import com.thebrokenrail.energonrelics.block.util.SimpleBlockWithEntity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.block.MaterialColor;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import java.util.List;
import java.util.function.Function;
public class BatteryCoreBlock extends SimpleBlockWithEntity {
@ -19,4 +35,24 @@ public class BatteryCoreBlock extends SimpleBlockWithEntity {
protected Function<BlockEntityType<BlockEntity>, BlockEntity> getFactory() {
return BatteryCoreBlockEntity::new;
}
@Override
@Environment(EnvType.CLIENT)
public void appendTooltip(ItemStack stack, BlockView world, List<Text> tooltip, TooltipContext options) {
super.appendTooltip(stack, world, tooltip, options);
tooltip.add(new TranslatableText("text." + EnergonRelics.NAMESPACE + ".battery_core_tooltip", new LiteralText(String.valueOf(stack.getOrCreateTag().getCompound("BlockEntityTag").getInt("Energy")))).formatted(Formatting.GRAY));
}
@Override
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
super.onBreak(world, pos, state, player);
if (player.isCreative()) {
Block.dropStacks(state, world, pos, world.getBlockEntity(pos));
}
}
@Override
protected int getMaxCount() {
return 1;
}
}

View File

@ -79,7 +79,7 @@ public class IndustrialLaserBlockEntity extends FieldProjectorBlockEntity {
} else {
Vec3d vec = Vec3d.ofCenter(targetPos);
((ServerWorld) getWorld()).spawnParticles(ParticleTypes.SMOKE, vec.getX(), vec.getY(), vec.getZ(), 1, 0.31f, 0.31f, 0.31f, 0f);
((ServerWorld) getWorld()).spawnParticles(ParticleTypes.SMOKE, vec.getX(), vec.getY(), vec.getZ(), 2, 0.31f, 0.31f, 0.31f, 0f);
progress++;
}

View File

@ -14,7 +14,7 @@ interface InfuserAction {
void run(World world, BlockPos pos);
class ItemAction implements InfuserAction {
private final ItemStack stack;
final ItemStack stack;
ItemAction(ItemStack stack) {
this.stack = stack;
@ -41,7 +41,7 @@ interface InfuserAction {
class ParticleAction implements InfuserAction {
@Override
public void run(World world, BlockPos pos) {
((ServerWorld) world).spawnParticles(ParticleTypes.SMOKE, pos.getX() + 0.5d, pos.getY() + 0.5d, pos.getZ() + 0.5d, 28, 0.31f, 0.31f, 0.31f, 0f);
((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);
}
}
}

View File

@ -1,17 +1,23 @@
package com.thebrokenrail.energonrelics.block.entity.infuser;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.block.InfuserBlock;
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
import com.thebrokenrail.energonrelics.energy.core.EnergyReceiverBlockEntity;
import com.thebrokenrail.energonrelics.energy.core.util.Action;
import com.thebrokenrail.energonrelics.item.MultimeterItem;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.Item;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import java.util.Objects;
public class InfuserBlockEntity extends EnergyReceiverBlockEntity {
public class InfuserBlockEntity extends EnergyReceiverBlockEntity implements MultimeterItem.MultimeterExtra {
public InfuserBlockEntity(BlockEntityType<?> type) {
super(type);
}
@ -94,4 +100,9 @@ public class InfuserBlockEntity extends EnergyReceiverBlockEntity {
explosion.run(getWorld(), getPos());
}
}
@Override
public MutableText getExtra() {
return new TranslatableText("text." + EnergonRelics.NAMESPACE + ".infuser_progress", new LiteralText(String.valueOf(((float) progress / (float) HardcodedConfig.INFUSER_TIME) * 100f)).formatted(Formatting.WHITE));
}
}

View File

@ -1,14 +1,18 @@
package com.thebrokenrail.energonrelics.block.entity.infuser;
import com.thebrokenrail.energonrelics.util.WeightedList;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
class InfuserEntry {
import java.util.ArrayList;
import java.util.List;
public class InfuserEntry {
public final long cost;
public final double successChance;
public final InfuserAction[] success;
public final InfuserAction[] fail;
private final InfuserAction[] success;
private final InfuserAction[] fail;
InfuserEntry(long cost, double successChance, InfuserAction[] success, InfuserAction[] fail) {
this.cost = cost;
@ -34,4 +38,19 @@ class InfuserEntry {
weightedList.pick(world.random).run(world, pos);
}
public List<ItemStack> getOutputItems(boolean isFail) {
InfuserAction[] actionList = isFail ? fail : success;
List<ItemStack> list = new ArrayList<>();
for (InfuserAction action : actionList) {
if (action instanceof InfuserAction.ItemAction) {
list.add(((InfuserAction.ItemAction) action).stack);
}
}
return list;
}
public double getSingleChance(boolean isFail) {
return (1d / (double) success.length) * (isFail ? 1d - successChance : successChance);
}
}

View File

@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class InfuserRegistry {
private static final Map<Item, InfuserEntry> map = new HashMap<>();
@ -24,9 +25,13 @@ public class InfuserRegistry {
map.put(item, entry);
}
public static Set<Map.Entry<Item, InfuserEntry>> entrySet() {
return map.entrySet();
}
static String toString(InfuserEntry entry) {
Item item = null;
for (Map.Entry<Item, InfuserEntry> mapEntry : map.entrySet()) {
for (Map.Entry<Item, InfuserEntry> mapEntry : entrySet()) {
if (mapEntry.getValue() == entry) {
item = mapEntry.getKey();
break;
@ -46,19 +51,13 @@ public class InfuserRegistry {
}
static {
add(Items.SUGAR, new InfuserEntry(320, 0.7d, new InfuserAction[]{new InfuserAction.ItemAction(new ItemStack(Items.GLOWSTONE_DUST, 16))}, new InfuserAction[]{new InfuserAction.ItemAction(Items.SUGAR_CANE), new InfuserAction.ExplosionAction()}));
add(Items.SUGAR, new InfuserEntry(320, 0.4d, new InfuserAction[]{new InfuserAction.ItemAction(new ItemStack(Items.GLOWSTONE_DUST, 48))}, new InfuserAction[]{new InfuserAction.ItemAction(Items.SUGAR_CANE), new InfuserAction.ExplosionAction()}));
DyeColor[] colors = DyeColor.values();
Item[] dyes = new Item[colors.length];
for (int i = 0; i < colors.length; i++) {
dyes[i] = DyeItem.byColor(colors[i]);
}
addTransform(dyes, 107, 0.6d);
addTransform(getWool(), 168, 0.5d);
addTransform(getDyes(), 107, 0.4d);
addTransform(getWool(), 168, 0.3d);
add(Items.GOLDEN_APPLE, new InfuserEntry(510, 0.3d, new InfuserAction[]{new InfuserAction.ItemAction(Items.ENCHANTED_GOLDEN_APPLE)}, new InfuserAction[]{new InfuserAction.ExplosionAction()}));
add(Items.COAL, new InfuserEntry(340, 0.01d, new InfuserAction[]{new InfuserAction.ItemAction(Items.DIAMOND)}, new InfuserAction[]{new InfuserAction.ExplosionAction()}));
add(Items.COAL, new InfuserEntry(340, 0.2d, new InfuserAction[]{new InfuserAction.ItemAction(Items.DIAMOND)}, new InfuserAction[]{new InfuserAction.ExplosionAction()}));
}
private static void addTransform(Item[] items, long cost, double successChance) {
@ -67,7 +66,7 @@ public class InfuserRegistry {
int i = 0;
for (Item item2 : items) {
if (item != item2) {
success[i] = new InfuserAction.ItemAction(item2);
success[i] = new InfuserAction.ItemAction(new ItemStack(item2, 8));
i++;
}
}
@ -85,4 +84,13 @@ public class InfuserRegistry {
}
return wool.toArray(new Item[0]);
}
private static Item[] getDyes() {
DyeColor[] colors = DyeColor.values();
Item[] dyes = new Item[colors.length];
for (int i = 0; i < colors.length; i++) {
dyes[i] = DyeItem.byColor(colors[i]);
}
return dyes;
}
}

View File

@ -20,6 +20,7 @@ public class SimpleBlock extends Block {
if (addToItemGroup() || FabricLoader.getInstance().isDevelopmentEnvironment()) {
settings.group(EnergonRelics.ITEM_GROUP);
}
settings.maxCount(getMaxCount());
Registry.register(Registry.ITEM, new Identifier(EnergonRelics.NAMESPACE, name), new BlockItem(this, settings));
}
}
@ -31,4 +32,8 @@ public class SimpleBlock extends Block {
protected boolean registerItem() {
return true;
}
protected int getMaxCount() {
return 64;
}
}

View File

@ -0,0 +1,50 @@
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.InfuserRegistry;
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.api.RecipeHelper;
import me.shedaniel.rei.api.plugins.REIPluginV0;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import java.util.List;
import java.util.Map;
@Environment(EnvType.CLIENT)
public class EnergonRelicsPlugin implements REIPluginV0 {
public static final Identifier INFUSER = new Identifier(EnergonRelics.NAMESPACE, "plugin/infuser");
@Override
public Identifier getPluginIdentifier() {
return new Identifier(EnergonRelics.NAMESPACE, "plugin");
}
@Override
public void registerOthers(RecipeHelper recipeHelper) {
recipeHelper.registerWorkingStations(INFUSER, EntryStack.create(EnergonRelics.INFUSER_BLOCK.asItem()));
}
@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));
}
}
}
@Override
public void registerPluginCategories(RecipeHelper recipeHelper) {
recipeHelper.registerCategories(new InfuserCategory());
}
}

View File

@ -0,0 +1,56 @@
package com.thebrokenrail.energonrelics.client.rei;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.api.RecipeCategory;
import me.shedaniel.rei.api.widgets.Widgets;
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.TranslatableText;
import net.minecraft.util.Identifier;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
@Environment(EnvType.CLIENT)
public class InfuserCategory implements RecipeCategory<InfuserDisplay> {
@Override
public List<Widget> setupDisplay(InfuserDisplay display, Rectangle bounds) {
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 + 18)));
widgets.add(Widgets.createLabel(new Point(bounds.x + bounds.width - 5, bounds.y + 5), new TranslatableText("category.rei." + EnergonRelics.NAMESPACE + ".infuser.chance", new DecimalFormat("###.##").format(display.successChance * 100d))).noShadow().rightAligned().color(0xFF404040, 0xFFBBBBBB));
widgets.add(Widgets.createLabel(new Point(bounds.x + bounds.width - 5, bounds.y + 14), new TranslatableText("category.rei." + EnergonRelics.NAMESPACE + ".infuser.cost", display.cost)).noShadow().rightAligned().color(0xFF404040, 0xFFBBBBBB));
widgets.add(Widgets.createArrow(new Point(startPoint.x + 24, startPoint.y + 17)).animationDurationTicks(HardcodedConfig.INFUSER_TIME));
widgets.add(Widgets.createSlot(new Point(startPoint.x + 1, startPoint.y + 18)).entries(display.getInputEntries().get(0)).markInput());
widgets.add(Widgets.createSlot(new Point(startPoint.x + 61, startPoint.y + 18)).entries(display.getOutputEntries()).disableBackground().markOutput());
return widgets;
}
@Override
public int getDisplayHeight() {
return 58;
}
@Override
public Identifier getIdentifier() {
return EnergonRelicsPlugin.INFUSER;
}
@Override
public EntryStack getLogo() {
return EntryStack.create(EnergonRelics.INFUSER_BLOCK);
}
@Override
public String getCategoryName() {
return I18n.translate("category.rei." + EnergonRelics.NAMESPACE + ".infuser.name");
}
}

View File

@ -0,0 +1,53 @@
package com.thebrokenrail.energonrelics.client.rei;
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;
public final double successChance;
public final long cost;
public InfuserDisplay(ItemStack input, List<ItemStack> 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.successChance = successChance;
this.cost = cost;
}
@Override
public List<List<EntryStack>> getInputEntries() {
return Collections.singletonList(Collections.singletonList(input));
}
@Override
public List<EntryStack> getOutputEntries() {
return output;
}
@Override
public Identifier getRecipeCategory() {
return EnergonRelicsPlugin.INFUSER;
}
@Override
public List<List<EntryStack>> getRequiredEntries() {
return getInputEntries();
}
}

View File

@ -21,6 +21,10 @@ public class MultimeterItem extends Item {
super(new Settings().maxCount(1).group(EnergonRelics.ITEM_GROUP));
}
public interface MultimeterExtra {
MutableText getExtra();
}
private Text numberToText(long value) {
String str;
if (value >= Long.MAX_VALUE) {
@ -39,6 +43,7 @@ public class MultimeterItem extends Item {
BlockEntity entity = world.getBlockEntity(context.getBlockPos());
boolean success = false;
MutableText text = new LiteralText("");
Text separator = new TranslatableText("text." + EnergonRelics.NAMESPACE + ".multimeter_separator").formatted(Formatting.YELLOW);
if (entity instanceof EnergyGenerator) {
if (!world.isClient() && context.getPlayer() != null) {
text.append(new TranslatableText("text." + EnergonRelics.NAMESPACE + ".energy_available", numberToText(((EnergyGenerator) entity).getDisplayEnergy())).formatted(Formatting.YELLOW));
@ -48,12 +53,21 @@ public class MultimeterItem extends Item {
if (entity instanceof EnergyReceiverBlockEntity) {
if (!world.isClient() && context.getPlayer() != null) {
if (success) {
text.append(" ");
text.append(separator);
}
text.append(new TranslatableText("text." + EnergonRelics.NAMESPACE + ".energy_required", numberToText(((EnergyReceiverBlockEntity) entity).getTotalCost())).formatted(Formatting.YELLOW));
}
success = true;
}
if (entity instanceof MultimeterExtra) {
if (!world.isClient() && context.getPlayer() != null) {
if (success) {
text.append(separator);
}
text.append(((MultimeterExtra) entity).getExtra().formatted(Formatting.YELLOW));
}
success = true;
}
if (success) {
if (!world.isClient()) {
Objects.requireNonNull(context.getPlayer()).sendMessage(text, true);

View File

@ -46,5 +46,11 @@
"block.energonrelics.industrial_laser": "Industrial Laser",
"death.attack.energonrelics.industrial_laser": "%s was melted by an industrial laser",
"death.attack.energonrelics.industrial_laser.player": "%s was melted by an industrial laser whilst fighting %s",
"block.energonrelics.infuser": "Infuser"
"block.energonrelics.infuser": "Infuser",
"text.energonrelics.infuser_progress": "Infusion Progress: %s%%",
"text.energonrelics.battery_core_tooltip": "%s Energon",
"text.energonrelics.multimeter_separator": ", ",
"category.rei.energonrelics.infuser.chance": "%s%% Chance",
"category.rei.energonrelics.infuser.cost": "Costing %s Energon",
"category.rei.energonrelics.infuser.name": "Infuser"
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -6,7 +6,20 @@
"entries": [
{
"type": "minecraft:item",
"name": "energonrelics:battery_core"
"name": "energonrelics:battery_core",
"functions": [
{
"function": "minecraft:copy_nbt",
"source": "block_entity",
"ops": [
{
"source": "Energy",
"target": "BlockEntityTag.Energy",
"op": "replace"
}
]
}
]
}
],
"conditions": [

View File

@ -1,21 +1,13 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"#E#",
"EOE",
"#E#"
],
"key": {
"#": {
"item": "energonrelics:circuit_board"
"type": "minecraft:crafting_shapeless",
"ingredients": [
{
"item": "energonrelics:passive_battery_controller"
},
"E": {
"item": "energonrelics:thermal_casing"
},
"O": {
"item": "minecraft:orange_dye"
{
"item": "minecraft:nether_star"
}
},
],
"result": {
"item": "energonrelics:active_battery_controller",
"count": 1

View File

@ -17,7 +17,7 @@
}
},
"result": {
"item": "energonrelics:defensive_laser_core",
"item": "energonrelics:block_breaker",
"count": 1
}
}

View File

@ -0,0 +1,23 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"#I#",
"ILI",
"#I#"
],
"key": {
"#": {
"item": "energonrelics:circuit_board"
},
"I": {
"item": "minecraft:iron_ingot"
},
"L": {
"item": "minecraft:lever"
}
},
"result": {
"item": "energonrelics:switch",
"count": 2
}
}

View File

@ -24,6 +24,9 @@
],
"modmenu": [
"com.thebrokenrail.energonrelics.client.ModMenu"
],
"rei_plugins": [
"com.thebrokenrail.energonrelics.client.rei.EnergonRelicsPlugin"
]
},
"mixins": [