pick 97420a31d The big reformat of 2020

This commit is contained in:
yueh
2020-06-16 21:41:28 +02:00
parent 5304b3febe
commit 5225ea426b
2252 changed files with 95466 additions and 118582 deletions
@@ -18,21 +18,16 @@
package appeng.integration;
public interface IIntegrationModule {
public interface IIntegrationModule
{
default boolean isEnabled() {
return true;
}
default boolean isEnabled()
{
return true;
}
class Stub implements IIntegrationModule
{
@Override
public boolean isEnabled()
{
return false;
}
}
class Stub implements IIntegrationModule {
@Override
public boolean isEnabled() {
return false;
}
}
}
@@ -18,26 +18,20 @@
package appeng.integration.abstraction;
import appeng.integration.IIntegrationModule;
/**
* Abstracts access to the JEI API functionality.
*/
public interface IJEI extends IIntegrationModule
{
public interface IJEI extends IIntegrationModule {
default String getSearchText()
{
return "";
}
default String getSearchText() {
return "";
}
default void setSearchText( String searchText )
{
}
default void setSearchText(String searchText) {
}
class Stub extends IIntegrationModule.Stub implements IJEI
{
}
class Stub extends IIntegrationModule.Stub implements IJEI {
}
}
@@ -18,15 +18,15 @@
package appeng.integration.modules.jei;
import java.util.*;
import appeng.api.AEApi;
import appeng.api.config.CondenserOutput;
import appeng.api.definitions.IMaterials;
import appeng.api.implementations.items.IStorageComponent;
import appeng.core.Api;
import appeng.core.AppEng;
import appeng.tile.misc.TileCondenser;
import com.google.common.base.Splitter;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.gui.HoverChecker;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.gui.drawable.IDrawable;
@@ -36,178 +36,169 @@ import mezz.jei.api.gui.ingredient.IGuiItemStackGroup;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.gui.HoverChecker;
import java.util.*;
import appeng.api.AEApi;
import appeng.api.config.CondenserOutput;
import appeng.api.definitions.IMaterials;
import appeng.api.implementations.items.IStorageComponent;
import appeng.core.Api;
import appeng.core.AppEng;
import appeng.tile.misc.TileCondenser;
class CondenserCategory implements IRecipeCategory<CondenserOutput> {
class CondenserCategory implements IRecipeCategory<CondenserOutput>
{
public static final ResourceLocation UID = new ResourceLocation(AppEng.MOD_ID, "condenser");
public static final ResourceLocation UID = new ResourceLocation(AppEng.MOD_ID, "condenser");
private final String localizedName;
private final String localizedName;
private final IDrawable background;
private final IDrawable background;
private final IDrawable iconTrash;
private final IDrawable iconTrash;
private final IDrawableAnimated progress;
private final IDrawableAnimated progress;
private final IDrawable iconButton;
private final IDrawable iconButton;
private final IDrawable icon;
private final IDrawable icon;
private final HoverChecker buttonHoverChecker;
private final HoverChecker buttonHoverChecker;
private final Map<CondenserOutput, IDrawable> buttonIcons;
private final Map<CondenserOutput, IDrawable> buttonIcons;
public CondenserCategory(IGuiHelper guiHelper) {
this.localizedName = I18n.format("gui.appliedenergistics2.Condenser");
this.icon = guiHelper.createDrawableIngredient(Api.INSTANCE.definitions().blocks().condenser().stack(1));
public CondenserCategory( IGuiHelper guiHelper )
{
this.localizedName = I18n.format( "gui.appliedenergistics2.Condenser" );
this.icon = guiHelper.createDrawableIngredient(Api.INSTANCE.definitions().blocks().condenser().stack(1));
ResourceLocation location = new ResourceLocation(AppEng.MOD_ID, "textures/guis/condenser.png");
this.background = guiHelper.createDrawable(location, 50, 25, 94, 48);
ResourceLocation location = new ResourceLocation( AppEng.MOD_ID, "textures/guis/condenser.png" );
this.background = guiHelper.createDrawable( location, 50, 25, 94, 48 );
ResourceLocation statesLocation = new ResourceLocation(AppEng.MOD_ID, "textures/guis/states.png");
this.iconTrash = guiHelper.drawableBuilder(statesLocation, 241, 81, 14, 14).addPadding(28, 0, 2, 0).build();
this.iconButton = guiHelper.drawableBuilder(statesLocation, 240, 240, 16, 16).addPadding(28, 0, 78, 0).build();
ResourceLocation statesLocation = new ResourceLocation( AppEng.MOD_ID, "textures/guis/states.png" );
this.iconTrash = guiHelper.drawableBuilder( statesLocation, 241, 81, 14, 14 )
.addPadding(28, 0, 2, 0)
.build();
this.iconButton = guiHelper.drawableBuilder( statesLocation, 240, 240, 16, 16 )
.addPadding(28, 0, 78, 0)
.build();
IDrawableStatic progressDrawable = guiHelper.drawableBuilder(location, 178, 25, 6, 18).addPadding(0, 0, 70, 0)
.build();
this.progress = guiHelper.createAnimatedDrawable(progressDrawable, 40, IDrawableAnimated.StartDirection.BOTTOM,
false);
IDrawableStatic progressDrawable = guiHelper.drawableBuilder( location, 178, 25, 6, 18 )
.addPadding(0, 0, 70, 0)
.build();
this.progress = guiHelper.createAnimatedDrawable( progressDrawable, 40, IDrawableAnimated.StartDirection.BOTTOM, false );
this.buttonIcons = new EnumMap<>(CondenserOutput.class);
this.buttonIcons = new EnumMap<>(CondenserOutput.class);
this.buttonIcons.put(CondenserOutput.MATTER_BALLS,
guiHelper.drawableBuilder(statesLocation, 16, 112, 14, 14).addPadding(28, 0, 78, 0).build());
this.buttonIcons.put(CondenserOutput.SINGULARITY,
guiHelper.drawableBuilder(statesLocation, 32, 112, 14, 14).addPadding(28, 0, 78, 0).build());
this.buttonHoverChecker = new HoverChecker(28, 28 + 16, 78, 78 + 16, 0);
}
this.buttonIcons.put(CondenserOutput.MATTER_BALLS, guiHelper.drawableBuilder( statesLocation, 16, 112, 14, 14 ).addPadding(28, 0, 78, 0).build());
this.buttonIcons.put(CondenserOutput.SINGULARITY, guiHelper.drawableBuilder( statesLocation, 32, 112, 14, 14).addPadding(28, 0, 78, 0).build());
this.buttonHoverChecker = new HoverChecker( 28, 28 + 16, 78, 78 + 16, 0 );
}
private ItemStack getOutput(CondenserOutput recipe) {
switch (recipe) {
case MATTER_BALLS:
return Api.INSTANCE.definitions().materials().matterBall().stack(1);
case SINGULARITY:
return Api.INSTANCE.definitions().materials().singularity().stack(1);
default:
return ItemStack.EMPTY;
}
}
private ItemStack getOutput( CondenserOutput recipe )
{
switch( recipe )
{
case MATTER_BALLS:
return Api.INSTANCE.definitions().materials().matterBall().stack(1);
case SINGULARITY:
return Api.INSTANCE.definitions().materials().singularity().stack(1);
default:
return ItemStack.EMPTY;
}
}
@Override
public ResourceLocation getUid() {
return CondenserCategory.UID;
}
@Override
public ResourceLocation getUid()
{
return CondenserCategory.UID;
}
@Override
public Class<? extends CondenserOutput> getRecipeClass() {
return CondenserOutput.class;
}
@Override
public Class<? extends CondenserOutput> getRecipeClass() {
return CondenserOutput.class;
}
@Override
public String getTitle() {
return this.localizedName;
}
@Override
public String getTitle()
{
return this.localizedName;
}
@Override
public IDrawable getBackground() {
return this.background;
}
@Override
public IDrawable getBackground()
{
return this.background;
}
@Override
public IDrawable getIcon() {
return icon;
}
@Override
public IDrawable getIcon() {
return icon;
}
@Override
public void setIngredients(CondenserOutput recipe, IIngredients ingredients) {
ingredients.setOutput(VanillaTypes.ITEM, getOutput(recipe));
}
@Override
public void setIngredients(CondenserOutput recipe, IIngredients ingredients) {
ingredients.setOutput(VanillaTypes.ITEM, getOutput(recipe) );
}
@Override
public void draw(CondenserOutput recipe, double mouseX, double mouseY) {
this.progress.draw();
this.iconTrash.draw();
this.iconButton.draw();
@Override
public void draw(CondenserOutput recipe, double mouseX, double mouseY) {
this.progress.draw();
this.iconTrash.draw();
this.iconButton.draw();
IDrawable buttonIcon = this.buttonIcons.get(recipe);
if (buttonIcon != null) {
buttonIcon.draw();
}
}
IDrawable buttonIcon = this.buttonIcons.get(recipe);
if (buttonIcon != null) {
buttonIcon.draw();
}
}
@Override
public void setRecipe(IRecipeLayout recipeLayout, CondenserOutput output, IIngredients ingredients) {
IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
itemStacks.init(0, false, 54, 26);
@Override
public void setRecipe(IRecipeLayout recipeLayout, CondenserOutput output, IIngredients ingredients )
{
IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
itemStacks.init( 0, false, 54, 26 );
// Get all storage cells and cycle them through a fake input slot
itemStacks.init(1, true, 50, 0);
itemStacks.set(1, this.getViableStorageComponents(output));
// Get all storage cells and cycle them through a fake input slot
itemStacks.init( 1, true, 50, 0 );
itemStacks.set( 1, this.getViableStorageComponents( output ) );
// This only sets the output
itemStacks.set(ingredients);
}
// This only sets the output
itemStacks.set( ingredients );
}
private List<ItemStack> getViableStorageComponents(CondenserOutput condenserOutput) {
IMaterials materials = AEApi.instance().definitions().materials();
List<ItemStack> viableComponents = new ArrayList<>();
materials.cell1kPart().maybeStack(1)
.ifPresent(itemStack -> this.addViableComponent(condenserOutput, viableComponents, itemStack));
materials.cell4kPart().maybeStack(1)
.ifPresent(itemStack -> this.addViableComponent(condenserOutput, viableComponents, itemStack));
materials.cell16kPart().maybeStack(1)
.ifPresent(itemStack -> this.addViableComponent(condenserOutput, viableComponents, itemStack));
materials.cell64kPart().maybeStack(1)
.ifPresent(itemStack -> this.addViableComponent(condenserOutput, viableComponents, itemStack));
return viableComponents;
}
private List<ItemStack> getViableStorageComponents(CondenserOutput condenserOutput )
{
IMaterials materials = AEApi.instance().definitions().materials();
List<ItemStack> viableComponents = new ArrayList<>();
materials.cell1kPart().maybeStack( 1 ).ifPresent( itemStack -> this.addViableComponent( condenserOutput, viableComponents, itemStack ) );
materials.cell4kPart().maybeStack( 1 ).ifPresent( itemStack -> this.addViableComponent( condenserOutput, viableComponents, itemStack ) );
materials.cell16kPart().maybeStack( 1 ).ifPresent( itemStack -> this.addViableComponent( condenserOutput, viableComponents, itemStack ) );
materials.cell64kPart().maybeStack( 1 ).ifPresent( itemStack -> this.addViableComponent( condenserOutput, viableComponents, itemStack ) );
return viableComponents;
}
private void addViableComponent(CondenserOutput condenserOutput, List<ItemStack> viableComponents,
ItemStack itemStack) {
IStorageComponent comp = (IStorageComponent) itemStack.getItem();
int storage = comp.getBytes(itemStack) * TileCondenser.BYTE_MULTIPLIER;
if (storage >= condenserOutput.requiredPower) {
viableComponents.add(itemStack);
}
}
private void addViableComponent(CondenserOutput condenserOutput, List<ItemStack> viableComponents, ItemStack itemStack )
{
IStorageComponent comp = (IStorageComponent) itemStack.getItem();
int storage = comp.getBytes( itemStack ) * TileCondenser.BYTE_MULTIPLIER;
if( storage >= condenserOutput.requiredPower )
{
viableComponents.add( itemStack );
}
}
@Override
public List<String> getTooltipStrings(CondenserOutput output, double mouseX, double mouseY) {
@Override
public List<String> getTooltipStrings(CondenserOutput output, double mouseX, double mouseY) {
if (this.buttonHoverChecker.checkHover((int) mouseX, (int) mouseY)) {
String key;
if( this.buttonHoverChecker.checkHover( (int) mouseX, (int) mouseY ) )
{
String key;
switch (output) {
case MATTER_BALLS:
key = "gui.tooltips.appliedenergistics2.MatterBalls";
break;
case SINGULARITY:
key = "gui.tooltips.appliedenergistics2.Singularity";
break;
default:
return Collections.emptyList();
}
switch( output )
{
case MATTER_BALLS:
key = "gui.tooltips.appliedenergistics2.MatterBalls";
break;
case SINGULARITY:
key = "gui.tooltips.appliedenergistics2.Singularity";
break;
default:
return Collections.emptyList();
}
return Splitter.on( "\\n" ).splitToList( I18n.format( key, output.requiredPower ) );
}
return Collections.emptyList();
}
return Splitter.on("\\n").splitToList(I18n.format(key, output.requiredPower));
}
return Collections.emptyList();
}
}
@@ -18,11 +18,15 @@
package appeng.integration.modules.jei;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import appeng.core.Api;
import appeng.core.AppEng;
import appeng.recipes.handlers.GrinderOptionalResult;
import appeng.recipes.handlers.GrinderRecipe;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.gui.drawable.IDrawable;
@@ -30,88 +34,78 @@ import mezz.jei.api.gui.ingredient.IGuiItemStackGroup;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import appeng.core.Api;
import appeng.core.AppEng;
import appeng.recipes.handlers.GrinderOptionalResult;
import appeng.recipes.handlers.GrinderRecipe;
class GrinderRecipeCategory implements IRecipeCategory<GrinderRecipe> {
class GrinderRecipeCategory implements IRecipeCategory<GrinderRecipe>
{
public static final ResourceLocation UID = new ResourceLocation(AppEng.MOD_ID, "grinder");
public static final ResourceLocation UID = new ResourceLocation(AppEng.MOD_ID, "grinder");
private final String localizedName;
private final String localizedName;
private final IDrawable background;
private final IDrawable background;
private final IDrawable icon;
private final IDrawable icon;
public GrinderRecipeCategory(IGuiHelper guiHelper) {
this.localizedName = I18n.format("block.appliedenergistics2.grindstone");
public GrinderRecipeCategory( IGuiHelper guiHelper )
{
this.localizedName = I18n.format( "block.appliedenergistics2.grindstone" );
ResourceLocation location = new ResourceLocation(AppEng.MOD_ID, "textures/guis/grinder.png");
this.background = guiHelper.createDrawable(location, 11, 16, 154, 70);
ResourceLocation location = new ResourceLocation( AppEng.MOD_ID, "textures/guis/grinder.png" );
this.background = guiHelper.createDrawable( location, 11, 16, 154, 70 );
this.icon = guiHelper.createDrawableIngredient(Api.INSTANCE.definitions().blocks().grindstone().stack(1));
}
this.icon = guiHelper.createDrawableIngredient(Api.INSTANCE.definitions().blocks().grindstone().stack(1));
}
@Override
public ResourceLocation getUid() {
return GrinderRecipeCategory.UID;
}
@Override
public ResourceLocation getUid()
{
return GrinderRecipeCategory.UID;
}
@Override
public String getTitle() {
return this.localizedName;
}
@Override
public String getTitle()
{
return this.localizedName;
}
@Override
public IDrawable getBackground() {
return this.background;
}
@Override
public IDrawable getBackground()
{
return this.background;
}
@Override
public void setRecipe(IRecipeLayout recipeLayout, GrinderRecipe recipe, IIngredients ingredients) {
IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
@Override
public void setRecipe(IRecipeLayout recipeLayout, GrinderRecipe recipe, IIngredients ingredients )
{
IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
itemStacks.init(0, true, 0, 0);
itemStacks.init(1, false, 100, 46);
itemStacks.init(2, false, 118, 46);
itemStacks.init(3, false, 136, 46);
itemStacks.init( 0, true, 0, 0 );
itemStacks.init( 1, false, 100, 46 );
itemStacks.init( 2, false, 118, 46 );
itemStacks.init( 3, false, 136, 46 );
itemStacks.set(ingredients);
}
itemStacks.set( ingredients );
}
@Override
public Class<? extends GrinderRecipe> getRecipeClass() {
return GrinderRecipe.class;
}
@Override
public Class<? extends GrinderRecipe> getRecipeClass() {
return GrinderRecipe.class;
}
@Override
public IDrawable getIcon() {
return icon;
}
@Override
public IDrawable getIcon() {
return icon;
}
@Override
public void setIngredients(GrinderRecipe recipe, IIngredients ingredients) {
ingredients.setInputIngredients(Collections.singletonList(recipe.getIngredient()));
List<ItemStack> outputs = new ArrayList<>( 3 );
outputs.add( recipe.getRecipeOutput() );
for (GrinderOptionalResult optionalResult : recipe.getOptionalResults()) {
outputs.add(optionalResult.getResult());
}
ingredients.setOutputs( VanillaTypes.ITEM, outputs );
}
@Override
public void setIngredients(GrinderRecipe recipe, IIngredients ingredients) {
ingredients.setInputIngredients(Collections.singletonList(recipe.getIngredient()));
List<ItemStack> outputs = new ArrayList<>(3);
outputs.add(recipe.getRecipeOutput());
for (GrinderOptionalResult optionalResult : recipe.getOptionalResults()) {
outputs.add(optionalResult.getResult());
}
ingredients.setOutputs(VanillaTypes.ITEM, outputs);
}
// FIXME USE SPECIAL INGREDIENT TYPE
// FIXME @Override
@@ -18,10 +18,13 @@
package appeng.integration.modules.jei;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import appeng.core.Api;
import appeng.core.AppEng;
import appeng.recipes.handlers.InscriberRecipe;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.*;
import mezz.jei.api.gui.drawable.IDrawable;
@@ -31,95 +34,86 @@ import mezz.jei.api.gui.ingredient.IGuiItemStackGroup;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import java.util.ArrayList;
import java.util.List;
import appeng.core.Api;
import appeng.core.AppEng;
import appeng.recipes.handlers.InscriberRecipe;
class InscriberRecipeCategory implements IRecipeCategory<InscriberRecipe> {
class InscriberRecipeCategory implements IRecipeCategory<InscriberRecipe>
{
private static final int SLOT_INPUT_TOP = 0;
private static final int SLOT_INPUT_MIDDLE = 1;
private static final int SLOT_INPUT_BOTTOM = 2;
private static final int SLOT_OUTPUT = 3;
private static final int SLOT_INPUT_TOP = 0;
private static final int SLOT_INPUT_MIDDLE = 1;
private static final int SLOT_INPUT_BOTTOM = 2;
private static final int SLOT_OUTPUT = 3;
static final ResourceLocation UID = new ResourceLocation(AppEng.MOD_ID, "appliedenergistics2.inscriber");
static final ResourceLocation UID = new ResourceLocation(AppEng.MOD_ID, "appliedenergistics2.inscriber");
private final IDrawable background;
private final IDrawable background;
private final String localizedName;
private final String localizedName;
private final IDrawableAnimated progress;
private final IDrawableAnimated progress;
private final IDrawable icon;
private final IDrawable icon;
public InscriberRecipeCategory(IGuiHelper guiHelper) {
ResourceLocation location = new ResourceLocation(AppEng.MOD_ID, "textures/guis/inscriber.png");
this.background = guiHelper.createDrawable(location, 44, 15, 97, 64);
this.localizedName = I18n.format("block.appliedenergistics2.inscriber");
public InscriberRecipeCategory( IGuiHelper guiHelper )
{
ResourceLocation location = new ResourceLocation( AppEng.MOD_ID, "textures/guis/inscriber.png" );
this.background = guiHelper.createDrawable( location, 44, 15, 97, 64 );
this.localizedName = I18n.format( "block.appliedenergistics2.inscriber" );
IDrawableStatic progressDrawable = guiHelper.drawableBuilder(location, 135, 177, 6, 18).addPadding(24, 0, 91, 0)
.build();
this.progress = guiHelper.createAnimatedDrawable(progressDrawable, 40, IDrawableAnimated.StartDirection.BOTTOM,
false);
IDrawableStatic progressDrawable = guiHelper.drawableBuilder( location, 135, 177, 6, 18 )
.addPadding(24, 0, 91, 0)
.build();
this.progress = guiHelper.createAnimatedDrawable( progressDrawable, 40, IDrawableAnimated.StartDirection.BOTTOM, false );
this.icon = guiHelper.createDrawableIngredient(Api.INSTANCE.definitions().blocks().inscriber().stack(1));
}
this.icon = guiHelper.createDrawableIngredient(Api.INSTANCE.definitions().blocks().inscriber().stack(1));
}
@Override
public ResourceLocation getUid() {
return UID;
}
@Override
public ResourceLocation getUid()
{
return UID;
}
@Override
public String getTitle() {
return this.localizedName;
}
@Override
public String getTitle()
{
return this.localizedName;
}
@Override
public IDrawable getBackground() {
return this.background;
}
@Override
public IDrawable getBackground()
{
return this.background;
}
@Override
public void setRecipe(IRecipeLayout recipeLayout, InscriberRecipe recipeWrapper, IIngredients ingredients) {
IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
@Override
public void setRecipe(IRecipeLayout recipeLayout, InscriberRecipe recipeWrapper, IIngredients ingredients )
{
IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
itemStacks.init(SLOT_INPUT_TOP, true, 0, 0);
itemStacks.init(SLOT_INPUT_MIDDLE, true, 18, 23);
itemStacks.init(SLOT_INPUT_BOTTOM, true, 0, 46);
itemStacks.init(SLOT_OUTPUT, false, 68, 24);
itemStacks.init( SLOT_INPUT_TOP, true, 0, 0 );
itemStacks.init( SLOT_INPUT_MIDDLE, true, 18, 23 );
itemStacks.init( SLOT_INPUT_BOTTOM, true, 0, 46 );
itemStacks.init( SLOT_OUTPUT, false, 68, 24 );
itemStacks.set(ingredients);
}
itemStacks.set( ingredients );
}
@Override
public Class<? extends InscriberRecipe> getRecipeClass() {
return InscriberRecipe.class;
}
@Override
public Class<? extends InscriberRecipe> getRecipeClass() {
return InscriberRecipe.class;
}
@Override
public IDrawable getIcon() {
return this.icon;
}
@Override
public IDrawable getIcon() {
return this.icon;
}
@Override
public void setIngredients(InscriberRecipe recipe, IIngredients ingredients) {
ingredients.setInputIngredients(recipe.getIngredients());
ingredients.setOutput(VanillaTypes.ITEM, recipe.getOutput());
}
@Override
public void setIngredients(InscriberRecipe recipe, IIngredients ingredients) {
ingredients.setInputIngredients(recipe.getIngredients());
ingredients.setOutput( VanillaTypes.ITEM, recipe.getOutput() );
}
@Override
public void draw(InscriberRecipe recipe, double mouseX, double mouseY) {
this.progress.draw();
}
@Override
public void draw(InscriberRecipe recipe, double mouseX, double mouseY) {
this.progress.draw();
}
}
@@ -18,6 +18,22 @@
package appeng.integration.modules.jei;
import java.util.Optional;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.Minecraft;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.RecipeManager;
import net.minecraft.util.ResourceLocation;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.constants.VanillaRecipeCategoryUid;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.registration.*;
import mezz.jei.api.runtime.IJeiRuntime;
import appeng.api.AEApi;
import appeng.api.config.CondenserOutput;
@@ -33,62 +49,42 @@ import appeng.core.localization.GuiText;
import appeng.integration.abstraction.JEIFacade;
import appeng.recipes.handlers.GrinderRecipe;
import appeng.recipes.handlers.InscriberRecipe;
import com.google.common.collect.ImmutableList;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.constants.VanillaRecipeCategoryUid;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.registration.*;
import mezz.jei.api.runtime.IJeiRuntime;
import net.minecraft.client.Minecraft;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.RecipeManager;
import net.minecraft.util.ResourceLocation;
import java.util.Optional;
@JeiPlugin
public class JEIPlugin implements IModPlugin
{
private static final ResourceLocation ID = new ResourceLocation(AppEng.MOD_ID, "core");
public class JEIPlugin implements IModPlugin {
private static final ResourceLocation ID = new ResourceLocation(AppEng.MOD_ID, "core");
@Override
public ResourceLocation getPluginUid() {
return ID;
}
@Override
public ResourceLocation getPluginUid() {
return ID;
}
@Override
public void registerItemSubtypes( ISubtypeRegistration subtypeRegistry )
{
final Optional<Item> maybeFacade = AEApi.instance().definitions().items().facade().maybeItem();
maybeFacade.ifPresent( subtypeRegistry::useNbtForSubtypes );
}
@Override
public void registerItemSubtypes(ISubtypeRegistration subtypeRegistry) {
final Optional<Item> maybeFacade = AEApi.instance().definitions().items().facade().maybeItem();
maybeFacade.ifPresent(subtypeRegistry::useNbtForSubtypes);
}
@Override
public void registerCategories( IRecipeCategoryRegistration registry )
{
registry.addRecipeCategories( new GrinderRecipeCategory( registry.getJeiHelpers().getGuiHelper() ),
new CondenserCategory( registry.getJeiHelpers().getGuiHelper() ),
new InscriberRecipeCategory( registry.getJeiHelpers().getGuiHelper() ) );
}
@Override
public void registerCategories(IRecipeCategoryRegistration registry) {
registry.addRecipeCategories(new GrinderRecipeCategory(registry.getJeiHelpers().getGuiHelper()),
new CondenserCategory(registry.getJeiHelpers().getGuiHelper()),
new InscriberRecipeCategory(registry.getJeiHelpers().getGuiHelper()));
}
@Override
public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) {
// Allow recipe transfer from JEI to crafting and pattern terminal
registration
.addRecipeTransferHandler( new RecipeTransferHandler<>( ContainerCraftingTerm.class ),
VanillaRecipeCategoryUid.CRAFTING );
registration
.addRecipeTransferHandler( new RecipeTransferHandler<>( ContainerPatternTerm.class ),
VanillaRecipeCategoryUid.CRAFTING );
}
@Override
public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) {
// Allow recipe transfer from JEI to crafting and pattern terminal
registration.addRecipeTransferHandler(new RecipeTransferHandler<>(ContainerCraftingTerm.class),
VanillaRecipeCategoryUid.CRAFTING);
registration.addRecipeTransferHandler(new RecipeTransferHandler<>(ContainerPatternTerm.class),
VanillaRecipeCategoryUid.CRAFTING);
}
@Override
public void registerRecipes(IRecipeRegistration registration) {
@Override
public void registerRecipes(IRecipeRegistration registration) {
IDefinitions definitions = AEApi.instance().definitions();
IDefinitions definitions = AEApi.instance().definitions();
// FIXME Optional<Item> itemFacade = definitions.items().facade().maybeItem();
// FIXME Optional<ItemStack> cableAnchor = definitions.parts().cableAnchor().maybeStack( 1 );
@@ -97,77 +93,75 @@ public class JEIPlugin implements IModPlugin
// FIXME registration.addRecipeRegistryPlugin( new FacadeRegistryPlugin( (ItemFacade) itemFacade.get(), cableAnchor.get() ) );
// FIXME }
RecipeManager recipeManager = Minecraft.getInstance().world.getRecipeManager();
registration.addRecipes(recipeManager.getRecipes(GrinderRecipe.TYPE).values(), GrinderRecipeCategory.UID);
registration.addRecipes(recipeManager.getRecipes(InscriberRecipe.TYPE).values(), InscriberRecipeCategory.UID );
registration.addRecipes(ImmutableList.of(CondenserOutput.MATTER_BALLS, CondenserOutput.SINGULARITY), CondenserCategory.UID);
RecipeManager recipeManager = Minecraft.getInstance().world.getRecipeManager();
registration.addRecipes(recipeManager.getRecipes(GrinderRecipe.TYPE).values(), GrinderRecipeCategory.UID);
registration.addRecipes(recipeManager.getRecipes(InscriberRecipe.TYPE).values(), InscriberRecipeCategory.UID);
registration.addRecipes(ImmutableList.of(CondenserOutput.MATTER_BALLS, CondenserOutput.SINGULARITY),
CondenserCategory.UID);
registerDescriptions(definitions, registration);
}
registerDescriptions(definitions, registration);
}
@Override
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
IDefinitions definitions = AEApi.instance().definitions();
@Override
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
IDefinitions definitions = AEApi.instance().definitions();
ItemStack grindstone = definitions.blocks().grindstone().stack(1);
registration.addRecipeCatalyst( grindstone, GrinderRecipeCategory.UID );
ItemStack grindstone = definitions.blocks().grindstone().stack(1);
registration.addRecipeCatalyst(grindstone, GrinderRecipeCategory.UID);
ItemStack condenser = definitions.blocks().condenser().stack(1);
registration.addRecipeCatalyst(condenser, CondenserCategory.UID);
ItemStack condenser = definitions.blocks().condenser().stack(1);
registration.addRecipeCatalyst(condenser, CondenserCategory.UID);
ItemStack inscriber = definitions.blocks().inscriber().stack(1);
registration.addRecipeCatalyst( inscriber, InscriberRecipeCategory.UID );
}
ItemStack inscriber = definitions.blocks().inscriber().stack(1);
registration.addRecipeCatalyst(inscriber, InscriberRecipeCategory.UID);
}
private void registerDescriptions(IDefinitions definitions, IRecipeRegistration registry )
{
IMaterials materials = definitions.materials();
private void registerDescriptions(IDefinitions definitions, IRecipeRegistration registry) {
IMaterials materials = definitions.materials();
final String[] message;
if( AEConfig.instance().isFeatureEnabled( AEFeature.CERTUS_QUARTZ_WORLD_GEN ) )
{
message = new String[]{GuiText.ChargedQuartz.getTranslationKey(), "", GuiText.ChargedQuartzFind.getTranslationKey()};
}
else
{
message = new String[]{GuiText.ChargedQuartzFind.getTranslationKey()};
}
this.addDescription( registry, materials.certusQuartzCrystalCharged(), message );
final String[] message;
if (AEConfig.instance().isFeatureEnabled(AEFeature.CERTUS_QUARTZ_WORLD_GEN)) {
message = new String[] { GuiText.ChargedQuartz.getTranslationKey(), "",
GuiText.ChargedQuartzFind.getTranslationKey() };
} else {
message = new String[] { GuiText.ChargedQuartzFind.getTranslationKey() };
}
this.addDescription(registry, materials.certusQuartzCrystalCharged(), message);
if( AEConfig.instance().isFeatureEnabled( AEFeature.METEORITE_WORLD_GEN ) )
{
this.addDescription( registry, materials.logicProcessorPress(), GuiText.inWorldCraftingPresses.getTranslationKey() );
this.addDescription( registry, materials.calcProcessorPress(), GuiText.inWorldCraftingPresses.getTranslationKey() );
this.addDescription( registry, materials.engProcessorPress(), GuiText.inWorldCraftingPresses.getTranslationKey() );
}
if (AEConfig.instance().isFeatureEnabled(AEFeature.METEORITE_WORLD_GEN)) {
this.addDescription(registry, materials.logicProcessorPress(),
GuiText.inWorldCraftingPresses.getTranslationKey());
this.addDescription(registry, materials.calcProcessorPress(),
GuiText.inWorldCraftingPresses.getTranslationKey());
this.addDescription(registry, materials.engProcessorPress(),
GuiText.inWorldCraftingPresses.getTranslationKey());
}
if( AEConfig.instance().isFeatureEnabled( AEFeature.IN_WORLD_FLUIX ) )
{
this.addDescription( registry, materials.fluixCrystal(), GuiText.inWorldFluix.getTranslationKey() );
}
if (AEConfig.instance().isFeatureEnabled(AEFeature.IN_WORLD_FLUIX)) {
this.addDescription(registry, materials.fluixCrystal(), GuiText.inWorldFluix.getTranslationKey());
}
if( AEConfig.instance().isFeatureEnabled( AEFeature.IN_WORLD_SINGULARITY ) )
{
this.addDescription( registry, materials.qESingularity(), GuiText.inWorldSingularity.getTranslationKey() );
}
if (AEConfig.instance().isFeatureEnabled(AEFeature.IN_WORLD_SINGULARITY)) {
this.addDescription(registry, materials.qESingularity(), GuiText.inWorldSingularity.getTranslationKey());
}
if( AEConfig.instance().isFeatureEnabled( AEFeature.IN_WORLD_PURIFICATION ) )
{
this.addDescription( registry, materials.purifiedCertusQuartzCrystal(), GuiText.inWorldPurificationCertus.getTranslationKey() );
this.addDescription( registry, materials.purifiedNetherQuartzCrystal(), GuiText.inWorldPurificationNether.getTranslationKey() );
this.addDescription( registry, materials.purifiedFluixCrystal(), GuiText.inWorldPurificationFluix.getTranslationKey() );
}
if (AEConfig.instance().isFeatureEnabled(AEFeature.IN_WORLD_PURIFICATION)) {
this.addDescription(registry, materials.purifiedCertusQuartzCrystal(),
GuiText.inWorldPurificationCertus.getTranslationKey());
this.addDescription(registry, materials.purifiedNetherQuartzCrystal(),
GuiText.inWorldPurificationNether.getTranslationKey());
this.addDescription(registry, materials.purifiedFluixCrystal(),
GuiText.inWorldPurificationFluix.getTranslationKey());
}
}
}
private void addDescription(IRecipeRegistration registry, IItemDefinition itemDefinition, String... message )
{
registry.addIngredientInfo( itemDefinition.stack(1), VanillaTypes.ITEM, message );
}
private void addDescription(IRecipeRegistration registry, IItemDefinition itemDefinition, String... message) {
registry.addIngredientInfo(itemDefinition.stack(1), VanillaTypes.ITEM, message);
}
@Override
public void onRuntimeAvailable( IJeiRuntime jeiRuntime )
{
JEIFacade.setInstance(new JeiRuntimeAdapter(jeiRuntime));
}
@Override
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {
JEIFacade.setInstance(new JeiRuntimeAdapter(jeiRuntime));
}
}
@@ -18,36 +18,32 @@
package appeng.integration.modules.jei;
import appeng.integration.abstraction.IJEI;
import com.google.common.base.Strings;
import mezz.jei.api.runtime.IJeiRuntime;
class JeiRuntimeAdapter implements IJEI
{
import appeng.integration.abstraction.IJEI;
private final IJeiRuntime runtime;
class JeiRuntimeAdapter implements IJEI {
JeiRuntimeAdapter( IJeiRuntime jeiRuntime )
{
this.runtime = jeiRuntime;
}
private final IJeiRuntime runtime;
@Override
public boolean isEnabled()
{
return true;
}
JeiRuntimeAdapter(IJeiRuntime jeiRuntime) {
this.runtime = jeiRuntime;
}
@Override
public String getSearchText()
{
return Strings.nullToEmpty( this.runtime.getIngredientFilter().getFilterText() );
}
@Override
public boolean isEnabled() {
return true;
}
@Override
public void setSearchText( String searchText )
{
this.runtime.getIngredientFilter().setFilterText( Strings.nullToEmpty( searchText ) );
}
@Override
public String getSearchText() {
return Strings.nullToEmpty(this.runtime.getIngredientFilter().getFilterText());
}
@Override
public void setSearchText(String searchText) {
this.runtime.getIngredientFilter().setFilterText(Strings.nullToEmpty(searchText));
}
}
@@ -18,17 +18,12 @@
package appeng.integration.modules.jei;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import appeng.container.slot.SlotCraftingMatrix;
import appeng.container.slot.SlotFakeCraftingMatrix;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketJEIRecipe;
import appeng.util.Platform;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.gui.ingredient.IGuiIngredient;
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.Slot;
@@ -36,96 +31,89 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.ListNBT;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.gui.ingredient.IGuiIngredient;
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
import appeng.container.slot.SlotCraftingMatrix;
import appeng.container.slot.SlotFakeCraftingMatrix;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketJEIRecipe;
import appeng.util.Platform;
class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandler<T>
{
class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandler<T> {
private final Class<T> containerClass;
private final Class<T> containerClass;
RecipeTransferHandler( Class<T> containerClass )
{
this.containerClass = containerClass;
}
RecipeTransferHandler(Class<T> containerClass) {
this.containerClass = containerClass;
}
@Override
public Class<T> getContainerClass()
{
return this.containerClass;
}
@Override
public Class<T> getContainerClass() {
return this.containerClass;
}
@Nullable
@Override
public IRecipeTransferError transferRecipe(T container, IRecipeLayout recipeLayout, PlayerEntity player, boolean maxTransfer, boolean doTransfer) {
if( !doTransfer )
{
return null;
}
@Nullable
@Override
public IRecipeTransferError transferRecipe(T container, IRecipeLayout recipeLayout, PlayerEntity player,
boolean maxTransfer, boolean doTransfer) {
if (!doTransfer) {
return null;
}
Map<Integer, ? extends IGuiIngredient<ItemStack>> ingredients = recipeLayout.getItemStacks().getGuiIngredients();
Map<Integer, ? extends IGuiIngredient<ItemStack>> ingredients = recipeLayout.getItemStacks()
.getGuiIngredients();
final CompoundNBT recipe = new CompoundNBT();
final CompoundNBT recipe = new CompoundNBT();
int slotIndex = 0;
for( Map.Entry<Integer, ? extends IGuiIngredient<ItemStack>> ingredientEntry : ingredients.entrySet() )
{
IGuiIngredient<ItemStack> ingredient = ingredientEntry.getValue();
if( !ingredient.isInput() )
{
continue;
}
int slotIndex = 0;
for (Map.Entry<Integer, ? extends IGuiIngredient<ItemStack>> ingredientEntry : ingredients.entrySet()) {
IGuiIngredient<ItemStack> ingredient = ingredientEntry.getValue();
if (!ingredient.isInput()) {
continue;
}
for( final Slot slot : container.inventorySlots )
{
if( slot instanceof SlotCraftingMatrix || slot instanceof SlotFakeCraftingMatrix)
{
if( slot.getSlotIndex() == slotIndex )
{
final ListNBT tags = new ListNBT();
final List<ItemStack> list = new ArrayList<>();
final ItemStack displayed = ingredient.getDisplayedIngredient();
for (final Slot slot : container.inventorySlots) {
if (slot instanceof SlotCraftingMatrix || slot instanceof SlotFakeCraftingMatrix) {
if (slot.getSlotIndex() == slotIndex) {
final ListNBT tags = new ListNBT();
final List<ItemStack> list = new ArrayList<>();
final ItemStack displayed = ingredient.getDisplayedIngredient();
// prefer currently displayed item
if( displayed != null && !displayed.isEmpty() )
{
list.add( displayed );
}
// prefer currently displayed item
if (displayed != null && !displayed.isEmpty()) {
list.add(displayed);
}
// prefer pure crystals.
for( ItemStack stack : ingredient.getAllIngredients() )
{
if( Platform.isRecipePrioritized( stack ) )
{
list.add( 0, stack );
}
else
{
list.add( stack );
}
}
// prefer pure crystals.
for (ItemStack stack : ingredient.getAllIngredients()) {
if (Platform.isRecipePrioritized(stack)) {
list.add(0, stack);
} else {
list.add(stack);
}
}
for( final ItemStack is : list )
{
final CompoundNBT tag = new CompoundNBT();
is.write( tag );
tags.add( tag );
}
for (final ItemStack is : list) {
final CompoundNBT tag = new CompoundNBT();
is.write(tag);
tags.add(tag);
}
recipe.put( "#" + slot.getSlotIndex(), tags );
break;
}
}
}
recipe.put("#" + slot.getSlotIndex(), tags);
break;
}
}
}
slotIndex++;
}
slotIndex++;
}
NetworkHandler.instance().sendToServer( new PacketJEIRecipe( recipe ) );
NetworkHandler.instance().sendToServer(new PacketJEIRecipe(recipe));
return null;
}
return null;
}
}
@@ -18,11 +18,8 @@
package appeng.integration.modules.waila;
import java.util.List;
import mcp.mobius.waila.api.IComponentProvider;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import mcp.mobius.waila.api.IServerDataProvider;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
@@ -30,8 +27,10 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World;
import java.util.List;
import mcp.mobius.waila.api.IComponentProvider;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import mcp.mobius.waila.api.IServerDataProvider;
/**
* Base implementation for {@link mcp.mobius.waila.api.IComponentProvider}
@@ -40,33 +39,32 @@ import java.util.List;
* @version rv2
* @since rv2
*/
public abstract class BaseWailaDataProvider implements IComponentProvider, IServerDataProvider<TileEntity>
{
public abstract class BaseWailaDataProvider implements IComponentProvider, IServerDataProvider<TileEntity> {
@Override
public ItemStack getStack( final IDataAccessor accessor, final IPluginConfig config )
{
return ItemStack.EMPTY;
}
@Override
public ItemStack getStack(final IDataAccessor accessor, final IPluginConfig config) {
return ItemStack.EMPTY;
}
@Override
public void appendServerData(CompoundNBT compoundNBT, ServerPlayerEntity serverPlayerEntity, World world, TileEntity tileEntity) {
@Override
public void appendServerData(CompoundNBT compoundNBT, ServerPlayerEntity serverPlayerEntity, World world,
TileEntity tileEntity) {
}
}
@Override
public void appendHead(List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config) {
@Override
public void appendHead(List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config) {
}
}
@Override
public void appendBody(List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config) {
@Override
public void appendBody(List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config) {
}
}
@Override
public void appendTail(List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config) {
@Override
public void appendTail(List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config) {
}
}
}
@@ -18,14 +18,11 @@
package appeng.integration.modules.waila;
import java.util.List;
import java.util.Optional;
import appeng.api.parts.IPart;
import appeng.integration.modules.waila.part.*;
import com.google.common.collect.Lists;
import mcp.mobius.waila.api.IComponentProvider;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import mcp.mobius.waila.api.IServerDataProvider;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
@@ -34,9 +31,13 @@ import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World;
import java.util.List;
import java.util.Optional;
import mcp.mobius.waila.api.IComponentProvider;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import mcp.mobius.waila.api.IServerDataProvider;
import appeng.api.parts.IPart;
import appeng.integration.modules.waila.part.*;
/**
* Delegation provider for parts through {@link IPartWailaDataProvider}
@@ -45,135 +46,119 @@ import java.util.Optional;
* @version rv2
* @since rv2
*/
public final class PartWailaDataProvider implements IComponentProvider, IServerDataProvider<TileEntity>
{
/**
* Contains all providers
*/
private final List<IPartWailaDataProvider> providers;
public final class PartWailaDataProvider implements IComponentProvider, IServerDataProvider<TileEntity> {
/**
* Contains all providers
*/
private final List<IPartWailaDataProvider> providers;
/**
* Can access parts through view-hits
*/
private final PartAccessor accessor = new PartAccessor();
/**
* Can access parts through view-hits
*/
private final PartAccessor accessor = new PartAccessor();
/**
* Traces views hit on blocks
*/
private final Tracer tracer = new Tracer();
/**
* Traces views hit on blocks
*/
private final Tracer tracer = new Tracer();
/**
* Initializes the provider list with all wanted providers
*/
public PartWailaDataProvider()
{
final IPartWailaDataProvider channel = new ChannelWailaDataProvider();
final IPartWailaDataProvider storageMonitor = new StorageMonitorWailaDataProvider();
final IPartWailaDataProvider powerState = new PowerStateWailaDataProvider();
final IPartWailaDataProvider p2pState = new P2PStateWailaDataProvider();
final IPartWailaDataProvider partStack = new PartStackWailaDataProvider();
/**
* Initializes the provider list with all wanted providers
*/
public PartWailaDataProvider() {
final IPartWailaDataProvider channel = new ChannelWailaDataProvider();
final IPartWailaDataProvider storageMonitor = new StorageMonitorWailaDataProvider();
final IPartWailaDataProvider powerState = new PowerStateWailaDataProvider();
final IPartWailaDataProvider p2pState = new P2PStateWailaDataProvider();
final IPartWailaDataProvider partStack = new PartStackWailaDataProvider();
this.providers = Lists.newArrayList( channel, storageMonitor, powerState, partStack, p2pState );
}
this.providers = Lists.newArrayList(channel, storageMonitor, powerState, partStack, p2pState);
}
@Override
public ItemStack getStack( final IDataAccessor accessor, final IPluginConfig config )
{
final TileEntity te = accessor.getTileEntity();
final RayTraceResult mop = accessor.getHitResult();
@Override
public ItemStack getStack(final IDataAccessor accessor, final IPluginConfig config) {
final TileEntity te = accessor.getTileEntity();
final RayTraceResult mop = accessor.getHitResult();
final Optional<IPart> maybePart = this.accessor.getMaybePart( te, mop );
final Optional<IPart> maybePart = this.accessor.getMaybePart(te, mop);
if( maybePart.isPresent() )
{
final IPart part = maybePart.get();
if (maybePart.isPresent()) {
final IPart part = maybePart.get();
ItemStack wailaStack = ItemStack.EMPTY;
ItemStack wailaStack = ItemStack.EMPTY;
for( final IPartWailaDataProvider provider : this.providers )
{
wailaStack = provider.getStack( part, config, wailaStack );
}
return wailaStack;
}
for (final IPartWailaDataProvider provider : this.providers) {
wailaStack = provider.getStack(part, config, wailaStack);
}
return wailaStack;
}
return ItemStack.EMPTY;
}
return ItemStack.EMPTY;
}
@Override
public void appendHead( List<ITextComponent> currentToolTip, final IDataAccessor accessor, final IPluginConfig config )
{
final TileEntity te = accessor.getTileEntity();
final RayTraceResult mop = accessor.getHitResult();
@Override
public void appendHead(List<ITextComponent> currentToolTip, final IDataAccessor accessor,
final IPluginConfig config) {
final TileEntity te = accessor.getTileEntity();
final RayTraceResult mop = accessor.getHitResult();
final Optional<IPart> maybePart = this.accessor.getMaybePart( te, mop );
final Optional<IPart> maybePart = this.accessor.getMaybePart(te, mop);
if( maybePart.isPresent() )
{
final IPart part = maybePart.get();
if (maybePart.isPresent()) {
final IPart part = maybePart.get();
for( final IPartWailaDataProvider provider : this.providers )
{
provider.appendHead( part, currentToolTip, accessor, config );
}
}
}
for (final IPartWailaDataProvider provider : this.providers) {
provider.appendHead(part, currentToolTip, accessor, config);
}
}
}
@Override
public void appendBody(List<ITextComponent> tooltip, final IDataAccessor accessor, final IPluginConfig config )
{
final TileEntity te = accessor.getTileEntity();
final RayTraceResult mop = accessor.getHitResult();
@Override
public void appendBody(List<ITextComponent> tooltip, final IDataAccessor accessor, final IPluginConfig config) {
final TileEntity te = accessor.getTileEntity();
final RayTraceResult mop = accessor.getHitResult();
final Optional<IPart> maybePart = this.accessor.getMaybePart( te, mop );
final Optional<IPart> maybePart = this.accessor.getMaybePart(te, mop);
if( maybePart.isPresent() )
{
final IPart part = maybePart.get();
if (maybePart.isPresent()) {
final IPart part = maybePart.get();
for( final IPartWailaDataProvider provider : this.providers )
{
provider.appendBody( part, tooltip, accessor, config );
}
}
}
for (final IPartWailaDataProvider provider : this.providers) {
provider.appendBody(part, tooltip, accessor, config);
}
}
}
@Override
public void appendTail( List<ITextComponent> tooltip, final IDataAccessor accessor, final IPluginConfig config )
{
final TileEntity te = accessor.getTileEntity();
final RayTraceResult mop = accessor.getHitResult();
@Override
public void appendTail(List<ITextComponent> tooltip, final IDataAccessor accessor, final IPluginConfig config) {
final TileEntity te = accessor.getTileEntity();
final RayTraceResult mop = accessor.getHitResult();
final Optional<IPart> maybePart = this.accessor.getMaybePart( te, mop );
final Optional<IPart> maybePart = this.accessor.getMaybePart(te, mop);
if( maybePart.isPresent() )
{
final IPart part = maybePart.get();
if (maybePart.isPresent()) {
final IPart part = maybePart.get();
for( final IPartWailaDataProvider provider : this.providers )
{
provider.appendTail( part, tooltip, accessor, config );
}
}
}
for (final IPartWailaDataProvider provider : this.providers) {
provider.appendTail(part, tooltip, accessor, config);
}
}
}
@Override
public void appendServerData(CompoundNBT tag, ServerPlayerEntity player, World world, TileEntity te) {
final RayTraceResult mop = this.tracer.retraceBlock( world, player, te.getPos() );
@Override
public void appendServerData(CompoundNBT tag, ServerPlayerEntity player, World world, TileEntity te) {
final RayTraceResult mop = this.tracer.retraceBlock(world, player, te.getPos());
if( mop != null )
{
final Optional<IPart> maybePart = this.accessor.getMaybePart( te, mop );
if (mop != null) {
final Optional<IPart> maybePart = this.accessor.getMaybePart(te, mop);
if( maybePart.isPresent() )
{
final IPart part = maybePart.get();
if (maybePart.isPresent()) {
final IPart part = maybePart.get();
for( final IPartWailaDataProvider provider : this.providers )
{
provider.appendServerData( player, part, te, tag, world, te.getPos() );
}
}
}
}
for (final IPartWailaDataProvider provider : this.providers) {
provider.appendServerData(player, part, te, tag, world, te.getPos());
}
}
}
}
}
@@ -18,16 +18,10 @@
package appeng.integration.modules.waila;
import java.util.List;
import appeng.integration.modules.waila.tile.ChargerWailaDataProvider;
import appeng.integration.modules.waila.tile.CraftingMonitorWailaDataProvider;
import appeng.integration.modules.waila.tile.PowerStateWailaDataProvider;
import appeng.integration.modules.waila.tile.PowerStorageWailaDataProvider;
import com.google.common.collect.Lists;
import mcp.mobius.waila.api.IComponentProvider;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import mcp.mobius.waila.api.IServerDataProvider;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
@@ -35,75 +29,76 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World;
import java.util.List;
import mcp.mobius.waila.api.IComponentProvider;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import mcp.mobius.waila.api.IServerDataProvider;
import appeng.integration.modules.waila.tile.ChargerWailaDataProvider;
import appeng.integration.modules.waila.tile.CraftingMonitorWailaDataProvider;
import appeng.integration.modules.waila.tile.PowerStateWailaDataProvider;
import appeng.integration.modules.waila.tile.PowerStorageWailaDataProvider;
/**
* Delegation provider for tiles through {@link mcp.mobius.waila.api.IComponentProvider}
* Delegation provider for tiles through
* {@link mcp.mobius.waila.api.IComponentProvider}
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public final class TileWailaDataProvider implements IComponentProvider, IServerDataProvider<TileEntity>
{
/**
* Contains all providers
*/
private final List<BaseWailaDataProvider> providers;
public final class TileWailaDataProvider implements IComponentProvider, IServerDataProvider<TileEntity> {
/**
* Contains all providers
*/
private final List<BaseWailaDataProvider> providers;
/**
* Initializes the provider list with all wanted providers
*/
public TileWailaDataProvider()
{
final BaseWailaDataProvider charger = new ChargerWailaDataProvider();
final BaseWailaDataProvider energyCell = new PowerStorageWailaDataProvider();
final BaseWailaDataProvider craftingBlock = new PowerStateWailaDataProvider();
final BaseWailaDataProvider craftingMonitor = new CraftingMonitorWailaDataProvider();
/**
* Initializes the provider list with all wanted providers
*/
public TileWailaDataProvider() {
final BaseWailaDataProvider charger = new ChargerWailaDataProvider();
final BaseWailaDataProvider energyCell = new PowerStorageWailaDataProvider();
final BaseWailaDataProvider craftingBlock = new PowerStateWailaDataProvider();
final BaseWailaDataProvider craftingMonitor = new CraftingMonitorWailaDataProvider();
this.providers = Lists.newArrayList( charger, energyCell, craftingBlock, craftingMonitor );
}
this.providers = Lists.newArrayList(charger, energyCell, craftingBlock, craftingMonitor);
}
@Override
public ItemStack getStack( final IDataAccessor accessor, final IPluginConfig config )
{
return ItemStack.EMPTY;
}
@Override
public ItemStack getStack(final IDataAccessor accessor, final IPluginConfig config) {
return ItemStack.EMPTY;
}
@Override
public void appendHead(List<ITextComponent> currentToolTip, final IDataAccessor accessor, final IPluginConfig config )
{
for( final BaseWailaDataProvider provider : this.providers )
{
provider.appendHead(currentToolTip, accessor, config);
}
}
@Override
public void appendHead(List<ITextComponent> currentToolTip, final IDataAccessor accessor,
final IPluginConfig config) {
for (final BaseWailaDataProvider provider : this.providers) {
provider.appendHead(currentToolTip, accessor, config);
}
}
@Override
public void appendBody( List<ITextComponent> currentToolTip, final IDataAccessor accessor, final IPluginConfig config )
{
for( final BaseWailaDataProvider provider : this.providers )
{
provider.appendBody(currentToolTip, accessor, config);
}
}
@Override
public void appendBody(List<ITextComponent> currentToolTip, final IDataAccessor accessor,
final IPluginConfig config) {
for (final BaseWailaDataProvider provider : this.providers) {
provider.appendBody(currentToolTip, accessor, config);
}
}
@Override
public void appendTail( List<ITextComponent> currentToolTip, final IDataAccessor accessor, final IPluginConfig config )
{
for( final BaseWailaDataProvider provider : this.providers )
{
provider.appendTail(currentToolTip, accessor, config);
}
}
@Override
public void appendTail(List<ITextComponent> currentToolTip, final IDataAccessor accessor,
final IPluginConfig config) {
for (final BaseWailaDataProvider provider : this.providers) {
provider.appendTail(currentToolTip, accessor, config);
}
}
@Override
public void appendServerData(CompoundNBT tag, ServerPlayerEntity player, World world, TileEntity te) {
@Override
public void appendServerData(CompoundNBT tag, ServerPlayerEntity player, World world, TileEntity te) {
for( final BaseWailaDataProvider provider : this.providers )
{
provider.appendServerData(tag, player, world, te);
}
}
for (final BaseWailaDataProvider provider : this.providers) {
provider.appendServerData(tag, player, world, te);
}
}
}
@@ -18,32 +18,31 @@
package appeng.integration.modules.waila;
import java.util.List;
import appeng.entity.EntityGrowingCrystal;
import appeng.items.misc.ItemCrystalSeed;
import mcp.mobius.waila.api.*;
import appeng.tile.AEBaseTile;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import java.util.List;
import mcp.mobius.waila.api.*;
import appeng.entity.EntityGrowingCrystal;
import appeng.items.misc.ItemCrystalSeed;
import appeng.tile.AEBaseTile;
@WailaPlugin
public class WailaModule implements IWailaPlugin
{
public class WailaModule implements IWailaPlugin {
public void register( final IRegistrar registrar )
{
final PartWailaDataProvider partHost = new PartWailaDataProvider();
public void register(final IRegistrar registrar) {
final PartWailaDataProvider partHost = new PartWailaDataProvider();
registrar.registerStackProvider( partHost, AEBaseTile.class );
registrar.registerComponentProvider( partHost, TooltipPosition.BODY, AEBaseTile.class );
registrar.registerBlockDataProvider( partHost, AEBaseTile.class );
registrar.registerStackProvider(partHost, AEBaseTile.class);
registrar.registerComponentProvider(partHost, TooltipPosition.BODY, AEBaseTile.class);
registrar.registerBlockDataProvider(partHost, AEBaseTile.class);
final TileWailaDataProvider tile = new TileWailaDataProvider();
registrar.registerComponentProvider( tile, TooltipPosition.BODY, AEBaseTile.class );
registrar.registerBlockDataProvider( tile, AEBaseTile.class );
}
final TileWailaDataProvider tile = new TileWailaDataProvider();
registrar.registerComponentProvider(tile, TooltipPosition.BODY, AEBaseTile.class);
registrar.registerBlockDataProvider(tile, AEBaseTile.class);
}
}
@@ -18,10 +18,8 @@
package appeng.integration.modules.waila.part;
import java.util.List;
import appeng.api.parts.IPart;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
@@ -30,40 +28,42 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World;
import java.util.List;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import appeng.api.parts.IPart;
/**
* Default implementation of {@link appeng.integration.modules.waila.part.IPartWailaDataProvider}
* Default implementation of
* {@link appeng.integration.modules.waila.part.IPartWailaDataProvider}
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public abstract class BasePartWailaDataProvider implements IPartWailaDataProvider
{
@Override
public ItemStack getStack( final IPart part, final IPluginConfig config, final ItemStack partStack )
{
return ItemStack.EMPTY;
}
public abstract class BasePartWailaDataProvider implements IPartWailaDataProvider {
@Override
public ItemStack getStack(final IPart part, final IPluginConfig config, final ItemStack partStack) {
return ItemStack.EMPTY;
}
@Override
public void appendHead(final IPart part, final List<ITextComponent> tooltip, final IDataAccessor accessor, final IPluginConfig config )
{
}
@Override
public void appendHead(final IPart part, final List<ITextComponent> tooltip, final IDataAccessor accessor,
final IPluginConfig config) {
}
@Override
public void appendBody(final IPart part, final List<ITextComponent> tooltip, final IDataAccessor accessor, final IPluginConfig config )
{
}
@Override
public void appendBody(final IPart part, final List<ITextComponent> tooltip, final IDataAccessor accessor,
final IPluginConfig config) {
}
@Override
public void appendTail(final IPart part, final List<ITextComponent> tooltip, final IDataAccessor accessor, final IPluginConfig config )
{
}
@Override
public void appendTail(final IPart part, final List<ITextComponent> tooltip, final IDataAccessor accessor,
final IPluginConfig config) {
}
@Override
public void appendServerData(ServerPlayerEntity player, IPart part, TileEntity te, CompoundNBT tag, World world, BlockPos pos) {
}
@Override
public void appendServerData(ServerPlayerEntity player, IPart part, TileEntity te, CompoundNBT tag, World world,
BlockPos pos) {
}
}
@@ -18,15 +18,8 @@
package appeng.integration.modules.waila.part;
import java.util.List;
import appeng.api.parts.IPart;
import appeng.core.localization.WailaText;
import appeng.parts.networking.PartCableSmart;
import appeng.parts.networking.PartDenseCableSmart;
import it.unimi.dsi.fastutil.objects.Object2ByteMap;
import it.unimi.dsi.fastutil.objects.Object2ByteOpenHashMap;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntity;
@@ -34,8 +27,15 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World;
import java.util.List;
import it.unimi.dsi.fastutil.objects.Object2ByteMap;
import it.unimi.dsi.fastutil.objects.Object2ByteOpenHashMap;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import appeng.api.parts.IPart;
import appeng.core.localization.WailaText;
import appeng.parts.networking.PartCableSmart;
import appeng.parts.networking.PartDenseCableSmart;
/**
* Channel-information provider for WAILA
@@ -44,110 +44,102 @@ import java.util.List;
* @version rv2
* @since rv2
*/
public final class ChannelWailaDataProvider extends BasePartWailaDataProvider
{
/**
* Channel key used for the transferred {@link net.minecraft.nbt.CompoundNBT}
*/
private static final String ID_USED_CHANNELS = "usedChannels";
public final class ChannelWailaDataProvider extends BasePartWailaDataProvider {
/**
* Channel key used for the transferred {@link net.minecraft.nbt.CompoundNBT}
*/
private static final String ID_USED_CHANNELS = "usedChannels";
/**
* Used cache for channels if the channel was not transmitted through the server.
* <p/>
* This is useful, when a player just started to look at a tile and thus just requested the new information from the
* server.
* <p/>
* The cache will be updated from the server.
*/
private final Object2ByteMap<IPart> cache = new Object2ByteOpenHashMap<>();
/**
* Used cache for channels if the channel was not transmitted through the
* server.
* <p/>
* This is useful, when a player just started to look at a tile and thus just
* requested the new information from the server.
* <p/>
* The cache will be updated from the server.
*/
private final Object2ByteMap<IPart> cache = new Object2ByteOpenHashMap<>();
/**
* Adds the used and max channel to the tool tip
*
* @param part being looked at part
* @param tooltip current tool tip
* @param accessor wrapper for various world information
* @param config config to react to various settings
*/
@Override
public void appendBody(final IPart part, final List<ITextComponent> tooltip, final IDataAccessor accessor, final IPluginConfig config )
{
if( part instanceof PartCableSmart || part instanceof PartDenseCableSmart )
{
final CompoundNBT tag = accessor.getServerData();
/**
* Adds the used and max channel to the tool tip
*
* @param part being looked at part
* @param tooltip current tool tip
* @param accessor wrapper for various world information
* @param config config to react to various settings
*/
@Override
public void appendBody(final IPart part, final List<ITextComponent> tooltip, final IDataAccessor accessor,
final IPluginConfig config) {
if (part instanceof PartCableSmart || part instanceof PartDenseCableSmart) {
final CompoundNBT tag = accessor.getServerData();
final byte usedChannels = this.getUsedChannels( part, tag, this.cache );
final byte usedChannels = this.getUsedChannels(part, tag, this.cache);
if( usedChannels >= 0 )
{
final byte maxChannels = (byte) ( ( part instanceof PartDenseCableSmart ) ? 32 : 8 );
if (usedChannels >= 0) {
final byte maxChannels = (byte) ((part instanceof PartDenseCableSmart) ? 32 : 8);
final ITextComponent formattedToolTip = WailaText.Channels.textComponent(usedChannels, maxChannels);
tooltip.add( formattedToolTip );
}
}
}
final ITextComponent formattedToolTip = WailaText.Channels.textComponent(usedChannels, maxChannels);
tooltip.add(formattedToolTip);
}
}
}
/**
* Determines the source of the channel.
* <p/>
* If the client received information of the channels on the server, they are used, else if the cache contains a
* previous stored value, this will be used. Default value is 0.
*
* @param part part to be looked at
* @param tag tag maybe containing the channel information
* @param cache cache with previous knowledge
*
* @return used channels on the cable
*/
private byte getUsedChannels( final IPart part, final CompoundNBT tag, final Object2ByteMap<IPart> cache )
{
final byte usedChannels;
/**
* Determines the source of the channel.
* <p/>
* If the client received information of the channels on the server, they are
* used, else if the cache contains a previous stored value, this will be used.
* Default value is 0.
*
* @param part part to be looked at
* @param tag tag maybe containing the channel information
* @param cache cache with previous knowledge
*
* @return used channels on the cable
*/
private byte getUsedChannels(final IPart part, final CompoundNBT tag, final Object2ByteMap<IPart> cache) {
final byte usedChannels;
if( tag.contains( ID_USED_CHANNELS ) )
{
usedChannels = tag.getByte( ID_USED_CHANNELS );
this.cache.put( part, usedChannels );
}
else if( this.cache.containsKey( part ) )
{
usedChannels = this.cache.get( part );
}
else
{
usedChannels = -1;
}
if (tag.contains(ID_USED_CHANNELS)) {
usedChannels = tag.getByte(ID_USED_CHANNELS);
this.cache.put(part, usedChannels);
} else if (this.cache.containsKey(part)) {
usedChannels = this.cache.get(part);
} else {
usedChannels = -1;
}
return usedChannels;
}
return usedChannels;
}
/**
* Called on server to transfer information from server to client.
* <p/>
* If the part is a cable, it writes the channel information in the {@code #tag} using the {@code ID_USED_CHANNELS}
* key.
*
* @param player player looking at the part
* @param part part being looked at
* @param te host of the part
* @param tag transferred tag which is send to the client
* @param world world of the part
* @param pos pos of the part
*/
@Override
public void appendServerData(ServerPlayerEntity player, IPart part, TileEntity te, CompoundNBT tag, World world, BlockPos pos) {
if( part instanceof PartCableSmart || part instanceof PartDenseCableSmart )
{
final CompoundNBT tempTag = new CompoundNBT();
/**
* Called on server to transfer information from server to client.
* <p/>
* If the part is a cable, it writes the channel information in the {@code #tag}
* using the {@code ID_USED_CHANNELS} key.
*
* @param player player looking at the part
* @param part part being looked at
* @param te host of the part
* @param tag transferred tag which is send to the client
* @param world world of the part
* @param pos pos of the part
*/
@Override
public void appendServerData(ServerPlayerEntity player, IPart part, TileEntity te, CompoundNBT tag, World world,
BlockPos pos) {
if (part instanceof PartCableSmart || part instanceof PartDenseCableSmart) {
final CompoundNBT tempTag = new CompoundNBT();
part.writeToNBT( tempTag );
part.writeToNBT(tempTag);
if( tempTag.contains( ID_USED_CHANNELS ) )
{
final byte usedChannels = tempTag.getByte( ID_USED_CHANNELS );
if (tempTag.contains(ID_USED_CHANNELS)) {
final byte usedChannels = tempTag.getByte(ID_USED_CHANNELS);
tag.putByte( ID_USED_CHANNELS, usedChannels );
}
}
}
tag.putByte(ID_USED_CHANNELS, usedChannels);
}
}
}
}
@@ -18,10 +18,8 @@
package appeng.integration.modules.waila.part;
import java.util.List;
import appeng.api.parts.IPart;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
@@ -30,26 +28,29 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World;
import java.util.List;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import appeng.api.parts.IPart;
/**
* An abstraction layer of the {@link appeng.integration.modules.waila.part.IPartWailaDataProvider} for
* An abstraction layer of the
* {@link appeng.integration.modules.waila.part.IPartWailaDataProvider} for
* {@link appeng.api.parts.IPart}.
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public interface IPartWailaDataProvider
{
ItemStack getStack( IPart part, IPluginConfig config, ItemStack partStack );
public interface IPartWailaDataProvider {
ItemStack getStack(IPart part, IPluginConfig config, ItemStack partStack);
void appendHead(IPart part, List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config );
void appendHead(IPart part, List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config);
void appendBody(IPart part, List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config );
void appendBody(IPart part, List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config);
void appendTail(IPart part, List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config );
void appendTail(IPart part, List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config);
void appendServerData(ServerPlayerEntity player, IPart part, TileEntity te, CompoundNBT tag, World world, BlockPos pos );
void appendServerData(ServerPlayerEntity player, IPart part, TileEntity te, CompoundNBT tag, World world,
BlockPos pos);
}
@@ -18,15 +18,10 @@
package appeng.integration.modules.waila.part;
import java.util.List;
import appeng.api.parts.IPart;
import appeng.core.localization.WailaText;
import appeng.me.GridAccessException;
import appeng.parts.p2p.PartP2PTunnel;
import appeng.util.Platform;
import com.google.common.collect.Iterators;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntity;
@@ -35,132 +30,116 @@ import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import java.util.List;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import appeng.api.parts.IPart;
import appeng.core.localization.WailaText;
import appeng.me.GridAccessException;
import appeng.parts.p2p.PartP2PTunnel;
import appeng.util.Platform;
/**
* Provides information about a P2P tunnel to WAILA.
*/
public final class P2PStateWailaDataProvider extends BasePartWailaDataProvider
{
public final class P2PStateWailaDataProvider extends BasePartWailaDataProvider {
private static final int STATE_UNLINKED = 0;
private static final int STATE_OUTPUT = 1;
private static final int STATE_INPUT = 2;
public static final String TAG_P2P_STATE = "p2p_state";
public static final String TAG_P2P_FREQUENCY = "p2p_frequency";
private static final int STATE_UNLINKED = 0;
private static final int STATE_OUTPUT = 1;
private static final int STATE_INPUT = 2;
public static final String TAG_P2P_STATE = "p2p_state";
public static final String TAG_P2P_FREQUENCY = "p2p_frequency";
/**
* Adds state to the tooltip
*
* @param part part with state
* @param tooltip to be added to tooltip
* @param accessor wrapper for various information
* @param config config settings
*/
@Override
public void appendBody(final IPart part, final List<ITextComponent> tooltip, final IDataAccessor accessor, final IPluginConfig config )
{
if( part instanceof PartP2PTunnel )
{
CompoundNBT nbtData = accessor.getServerData();
if( nbtData.contains( TAG_P2P_STATE ) )
{
int[] stateArr = nbtData.getIntArray( TAG_P2P_STATE );
if( stateArr.length == 2 )
{
int state = stateArr[0];
int outputs = stateArr[1];
/**
* Adds state to the tooltip
*
* @param part part with state
* @param tooltip to be added to tooltip
* @param accessor wrapper for various information
* @param config config settings
*/
@Override
public void appendBody(final IPart part, final List<ITextComponent> tooltip, final IDataAccessor accessor,
final IPluginConfig config) {
if (part instanceof PartP2PTunnel) {
CompoundNBT nbtData = accessor.getServerData();
if (nbtData.contains(TAG_P2P_STATE)) {
int[] stateArr = nbtData.getIntArray(TAG_P2P_STATE);
if (stateArr.length == 2) {
int state = stateArr[0];
int outputs = stateArr[1];
switch( state )
{
case STATE_UNLINKED:
tooltip.add( WailaText.P2PUnlinked.textComponent() );
break;
case STATE_OUTPUT:
tooltip.add( WailaText.P2POutput.textComponent() );
break;
case STATE_INPUT:
tooltip.add( getOutputText( outputs ) );
break;
}
}
switch (state) {
case STATE_UNLINKED:
tooltip.add(WailaText.P2PUnlinked.textComponent());
break;
case STATE_OUTPUT:
tooltip.add(WailaText.P2POutput.textComponent());
break;
case STATE_INPUT:
tooltip.add(getOutputText(outputs));
break;
}
}
final short freq = nbtData.getShort( TAG_P2P_FREQUENCY );
final String freqTooltip = Platform.p2p().toHexString( freq );
tooltip.add( new TranslationTextComponent( "gui.tooltips.appliedenergistics2.P2PFrequency", freqTooltip ) );
}
}
}
final short freq = nbtData.getShort(TAG_P2P_FREQUENCY);
final String freqTooltip = Platform.p2p().toHexString(freq);
tooltip.add(new TranslationTextComponent("gui.tooltips.appliedenergistics2.P2PFrequency", freqTooltip));
}
}
}
@Override
public void appendServerData(ServerPlayerEntity player, IPart part, TileEntity te, CompoundNBT tag, World world, BlockPos pos) {
if( part instanceof PartP2PTunnel )
{
final PartP2PTunnel<?> tunnel = (PartP2PTunnel<?>) part;
@Override
public void appendServerData(ServerPlayerEntity player, IPart part, TileEntity te, CompoundNBT tag, World world,
BlockPos pos) {
if (part instanceof PartP2PTunnel) {
final PartP2PTunnel<?> tunnel = (PartP2PTunnel<?>) part;
if( !tunnel.isPowered() )
{
return;
}
if (!tunnel.isPowered()) {
return;
}
// Frquency
final short frequency = tunnel.getFrequency();
tag.putShort( TAG_P2P_FREQUENCY, frequency );
// Frquency
final short frequency = tunnel.getFrequency();
tag.putShort(TAG_P2P_FREQUENCY, frequency);
// The default state
int state = STATE_UNLINKED;
int outputCount = 0;
// The default state
int state = STATE_UNLINKED;
int outputCount = 0;
if( !tunnel.isOutput() )
{
outputCount = getOutputCount( tunnel );
if( outputCount > 0 )
{
// Only set it to INPUT if we know there are any outputs
state = STATE_INPUT;
}
}
else
{
PartP2PTunnel<?> input = tunnel.getInput();
if( input != null )
{
state = STATE_OUTPUT;
}
}
if (!tunnel.isOutput()) {
outputCount = getOutputCount(tunnel);
if (outputCount > 0) {
// Only set it to INPUT if we know there are any outputs
state = STATE_INPUT;
}
} else {
PartP2PTunnel<?> input = tunnel.getInput();
if (input != null) {
state = STATE_OUTPUT;
}
}
tag.putIntArray( TAG_P2P_STATE, new int[] {
state,
outputCount
} );
tag.putIntArray(TAG_P2P_STATE, new int[] { state, outputCount });
}
}
}
}
private static int getOutputCount( PartP2PTunnel<?> tunnel )
{
try
{
return Iterators.size( tunnel.getOutputs().iterator() );
}
catch( GridAccessException e )
{
// Well... unknown size it is!
return 0;
}
}
private static int getOutputCount(PartP2PTunnel<?> tunnel) {
try {
return Iterators.size(tunnel.getOutputs().iterator());
} catch (GridAccessException e) {
// Well... unknown size it is!
return 0;
}
}
private static ITextComponent getOutputText( int outputs )
{
if( outputs <= 1 )
{
return WailaText.P2PInputOneOutput.textComponent();
}
else
{
return WailaText.P2PInputManyOutputs.textComponent(outputs);
}
}
private static ITextComponent getOutputText(int outputs) {
if (outputs <= 1) {
return WailaText.P2PInputOneOutput.textComponent();
} else {
return WailaText.P2PInputManyOutputs.textComponent(outputs);
}
}
}
@@ -18,7 +18,6 @@
package appeng.integration.modules.waila.part;
import java.util.Optional;
import net.minecraft.tileentity.TileEntity;
@@ -31,7 +30,6 @@ import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.api.parts.SelectedPart;
/**
* Accessor to access specific parts for WAILA
*
@@ -39,34 +37,30 @@ import appeng.api.parts.SelectedPart;
* @version rv2
* @since rv2
*/
public final class PartAccessor
{
/**
* Hits a {@link IPartHost} with {@link BlockPos}.
* <p/>
* You can derive the looked at {@link IPart} by doing that. If a facade is being looked at, it is
* defined as being absent.
*
* @param te being looked at {@link TileEntity}
* @param rtr type of ray-trace
*
* @return maybe the looked at {@link IPart}
*/
public Optional<IPart> getMaybePart( final TileEntity te, final RayTraceResult rtr )
{
if( te instanceof IPartHost && rtr instanceof BlockRayTraceResult)
{
BlockPos pos = ((BlockRayTraceResult) rtr).getPos();
final Vec3d position = rtr.getHitVec().add( -pos.getX(), -pos.getY(), -pos.getZ() );
final IPartHost host = (IPartHost) te;
final SelectedPart sp = host.selectPart( position );
public final class PartAccessor {
/**
* Hits a {@link IPartHost} with {@link BlockPos}.
* <p/>
* You can derive the looked at {@link IPart} by doing that. If a facade is
* being looked at, it is defined as being absent.
*
* @param te being looked at {@link TileEntity}
* @param rtr type of ray-trace
*
* @return maybe the looked at {@link IPart}
*/
public Optional<IPart> getMaybePart(final TileEntity te, final RayTraceResult rtr) {
if (te instanceof IPartHost && rtr instanceof BlockRayTraceResult) {
BlockPos pos = ((BlockRayTraceResult) rtr).getPos();
final Vec3d position = rtr.getHitVec().add(-pos.getX(), -pos.getY(), -pos.getZ());
final IPartHost host = (IPartHost) te;
final SelectedPart sp = host.selectPart(position);
if( sp.part != null )
{
return Optional.of( sp.part );
}
}
if (sp.part != null) {
return Optional.of(sp.part);
}
}
return Optional.empty();
}
return Optional.empty();
}
}
@@ -18,7 +18,6 @@
package appeng.integration.modules.waila.part;
import net.minecraft.item.ItemStack;
import mcp.mobius.waila.api.IPluginConfig;
@@ -26,7 +25,6 @@ import mcp.mobius.waila.api.IPluginConfig;
import appeng.api.parts.IPart;
import appeng.api.parts.PartItemStack;
/**
* Part ItemStack provider for WAILA
*
@@ -34,14 +32,12 @@ import appeng.api.parts.PartItemStack;
* @version rv2
* @since rv2
*/
public class PartStackWailaDataProvider extends BasePartWailaDataProvider
{
public class PartStackWailaDataProvider extends BasePartWailaDataProvider {
@Override
public ItemStack getStack( final IPart part, final IPluginConfig config, ItemStack partStack )
{
partStack = part.getItemStack( PartItemStack.PICK );
return partStack;
}
@Override
public ItemStack getStack(final IPart part, final IPluginConfig config, ItemStack partStack) {
partStack = part.getItemStack(PartItemStack.PICK);
return partStack;
}
}
@@ -18,17 +18,16 @@
package appeng.integration.modules.waila.part;
import java.util.List;
import mcp.mobius.waila.api.IPluginConfig;
import net.minecraft.util.text.ITextComponent;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import appeng.api.implementations.IPowerChannelState;
import appeng.api.parts.IPart;
import appeng.core.localization.WailaText;
import net.minecraft.util.text.ITextComponent;
/**
* Power state provider for WAILA
@@ -37,48 +36,41 @@ import net.minecraft.util.text.ITextComponent;
* @version rv2
* @since rv2
*/
public final class PowerStateWailaDataProvider extends BasePartWailaDataProvider
{
/**
* Adds state to the tooltip
*
* @param part part with state
* @param tooltip to be added to tooltip
* @param accessor wrapper for various information
* @param config config settings
*/
@Override
public void appendBody(final IPart part, final List<ITextComponent> tooltip, final IDataAccessor accessor, final IPluginConfig config )
{
if( part instanceof IPowerChannelState )
{
final IPowerChannelState state = (IPowerChannelState) part;
public final class PowerStateWailaDataProvider extends BasePartWailaDataProvider {
/**
* Adds state to the tooltip
*
* @param part part with state
* @param tooltip to be added to tooltip
* @param accessor wrapper for various information
* @param config config settings
*/
@Override
public void appendBody(final IPart part, final List<ITextComponent> tooltip, final IDataAccessor accessor,
final IPluginConfig config) {
if (part instanceof IPowerChannelState) {
final IPowerChannelState state = (IPowerChannelState) part;
tooltip.add( this.getToolTip( state.isActive(), state.isPowered() ) );
}
}
tooltip.add(this.getToolTip(state.isActive(), state.isPowered()));
}
}
/**
* Gets the corresponding tool tip for different values of {@code #isActive} and {@code #isPowered}
*
* @param isActive if part is active
* @param isPowered if part is powered
*
* @return tooltip of the state
*/
private ITextComponent getToolTip( final boolean isActive, final boolean isPowered )
{
if( isActive && isPowered )
{
return WailaText.DeviceOnline.textComponent();
}
else if( isPowered )
{
return WailaText.DeviceMissingChannel.textComponent();
}
else
{
return WailaText.DeviceOffline.textComponent();
}
}
/**
* Gets the corresponding tool tip for different values of {@code #isActive} and
* {@code #isPowered}
*
* @param isActive if part is active
* @param isPowered if part is powered
*
* @return tooltip of the state
*/
private ITextComponent getToolTip(final boolean isActive, final boolean isPowered) {
if (isActive && isPowered) {
return WailaText.DeviceOnline.textComponent();
} else if (isPowered) {
return WailaText.DeviceMissingChannel.textComponent();
} else {
return WailaText.DeviceOffline.textComponent();
}
}
}
@@ -18,11 +18,12 @@
package appeng.integration.modules.waila.part;
import java.util.List;
import mcp.mobius.waila.api.IPluginConfig;
import net.minecraft.util.text.ITextComponent;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import appeng.api.implementations.parts.IPartStorageMonitor;
import appeng.api.parts.IPart;
@@ -30,8 +31,6 @@ import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.core.localization.WailaText;
import net.minecraft.util.text.ITextComponent;
/**
* Storage monitor provider for WAILA
@@ -40,40 +39,37 @@ import net.minecraft.util.text.ITextComponent;
* @version rv2
* @since rv2
*/
public final class StorageMonitorWailaDataProvider extends BasePartWailaDataProvider
{
/**
* Displays the stack if present and if the monitor is locked.
* Can handle fluids and items.
*
* @param part maybe storage monitor
* @param tooltip to be written to tooltip
* @param accessor information wrapper
* @param config config option
*/
@Override
public void appendBody(final IPart part, final List<ITextComponent> tooltip, final IDataAccessor accessor, final IPluginConfig config )
{
if( part instanceof IPartStorageMonitor )
{
final IPartStorageMonitor monitor = (IPartStorageMonitor) part;
public final class StorageMonitorWailaDataProvider extends BasePartWailaDataProvider {
/**
* Displays the stack if present and if the monitor is locked. Can handle fluids
* and items.
*
* @param part maybe storage monitor
* @param tooltip to be written to tooltip
* @param accessor information wrapper
* @param config config option
*/
@Override
public void appendBody(final IPart part, final List<ITextComponent> tooltip, final IDataAccessor accessor,
final IPluginConfig config) {
if (part instanceof IPartStorageMonitor) {
final IPartStorageMonitor monitor = (IPartStorageMonitor) part;
final IAEStack<?> displayed = monitor.getDisplayed();
final boolean isLocked = monitor.isLocked();
final IAEStack<?> displayed = monitor.getDisplayed();
final boolean isLocked = monitor.isLocked();
// TODO: generalize
if( displayed instanceof IAEItemStack )
{
final IAEItemStack ais = (IAEItemStack) displayed;
tooltip.add( WailaText.Showing.textComponent().appendText(": ").appendSibling(ais.asItemStackRepresentation().getDisplayName()) );
}
else if( displayed instanceof IAEFluidStack )
{
final IAEFluidStack ais = (IAEFluidStack) displayed;
tooltip.add( WailaText.Showing.textComponent().appendText(": ").appendSibling(ais.getFluid().getAttributes().getDisplayName( ais.getFluidStack() )) );
}
// TODO: generalize
if (displayed instanceof IAEItemStack) {
final IAEItemStack ais = (IAEItemStack) displayed;
tooltip.add(WailaText.Showing.textComponent().appendText(": ")
.appendSibling(ais.asItemStackRepresentation().getDisplayName()));
} else if (displayed instanceof IAEFluidStack) {
final IAEFluidStack ais = (IAEFluidStack) displayed;
tooltip.add(WailaText.Showing.textComponent().appendText(": ")
.appendSibling(ais.getFluid().getAttributes().getDisplayName(ais.getFluidStack())));
}
tooltip.add( ( isLocked ) ? WailaText.Locked.textComponent() : WailaText.Unlocked.textComponent() );
}
}
tooltip.add((isLocked) ? WailaText.Locked.textComponent() : WailaText.Unlocked.textComponent());
}
}
}
@@ -18,7 +18,6 @@
package appeng.integration.modules.waila.part;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
@@ -27,7 +26,6 @@ import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
/**
* Tracer for players hitting blocks
*
@@ -35,66 +33,57 @@ import net.minecraft.world.World;
* @version rv2
* @since rv2
*/
public final class Tracer
{
/**
* Trace view of players to blocks.
* Ignore all which are out of reach.
*
* @param world word of block
* @param player player viewing block
* @param pos pos of block
*
* @return trace movement. Can be null
*/
public RayTraceResult retraceBlock(final World world, final PlayerEntity player, BlockPos pos )
{
BlockState blockState = world.getBlockState( pos );
public final class Tracer {
/**
* Trace view of players to blocks. Ignore all which are out of reach.
*
* @param world word of block
* @param player player viewing block
* @param pos pos of block
*
* @return trace movement. Can be null
*/
public RayTraceResult retraceBlock(final World world, final PlayerEntity player, BlockPos pos) {
BlockState blockState = world.getBlockState(pos);
final Vec3d headVec = this.getCorrectedHeadVec( player );
final Vec3d lookVec = player.getLook( 1.0F );
final double reach = this.getBlockReachDistance_server( player );
final Vec3d endVec = headVec.add( lookVec.x * reach, lookVec.y * reach, lookVec.z * reach );
final Vec3d headVec = this.getCorrectedHeadVec(player);
final Vec3d lookVec = player.getLook(1.0F);
final double reach = this.getBlockReachDistance_server(player);
final Vec3d endVec = headVec.add(lookVec.x * reach, lookVec.y * reach, lookVec.z * reach);
return blockState.getCollisionShape(world, pos).rayTrace( headVec, endVec, pos );
}
return blockState.getCollisionShape(world, pos).rayTrace(headVec, endVec, pos);
}
/**
* Gets the view point of a player
*
* @param player player with head
*
* @return view point of player
*/
private Vec3d getCorrectedHeadVec( final PlayerEntity player )
{
double x = player.getPosX();
double y = player.getPosY();
double z = player.getPosZ();
/**
* Gets the view point of a player
*
* @param player player with head
*
* @return view point of player
*/
private Vec3d getCorrectedHeadVec(final PlayerEntity player) {
double x = player.getPosX();
double y = player.getPosY();
double z = player.getPosZ();
if( player.world.isRemote )
{
// compatibility with eye height changing mods
y += player.getEyeHeight() - player.getEyeHeight();
}
else
{
y += player.getEyeHeight();
if( player instanceof ServerPlayerEntity && player.isSneaking() )
{
y -= 0.08;
}
}
return new Vec3d( x, y, z );
}
if (player.world.isRemote) {
// compatibility with eye height changing mods
y += player.getEyeHeight() - player.getEyeHeight();
} else {
y += player.getEyeHeight();
if (player instanceof ServerPlayerEntity && player.isSneaking()) {
y -= 0.08;
}
}
return new Vec3d(x, y, z);
}
/**
* @param player multi-player player
*
* @return block reach distance of player
*/
private double getBlockReachDistance_server( final PlayerEntity player )
{
return player.getAttribute(net.minecraft.entity.player.PlayerEntity.REACH_DISTANCE).getValue();
}
/**
* @param player multi-player player
*
* @return block reach distance of player
*/
private double getBlockReachDistance_server(final PlayerEntity player) {
return player.getAttribute(net.minecraft.entity.player.PlayerEntity.REACH_DISTANCE).getValue();
}
}
@@ -18,7 +18,6 @@
package appeng.integration.modules.waila.tile;
import java.util.List;
import javax.annotation.Nonnull;
@@ -31,14 +30,13 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.items.IItemHandler;
import mcp.mobius.waila.api.IPluginConfig;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import appeng.core.localization.WailaText;
import appeng.integration.modules.waila.BaseWailaDataProvider;
import appeng.tile.misc.TileCharger;
/**
* Charger provider for WAILA
*
@@ -46,31 +44,28 @@ import appeng.tile.misc.TileCharger;
* @version rv2
* @since rv2
*/
public final class ChargerWailaDataProvider extends BaseWailaDataProvider
{
public final class ChargerWailaDataProvider extends BaseWailaDataProvider {
@Override
public void appendBody(List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config) {
@Override
public void appendBody(List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config) {
final TileEntity te = accessor.getTileEntity();
if( te instanceof TileCharger )
{
final TileCharger charger = (TileCharger) te;
final IItemHandler chargerInventory = charger.getInternalInventory();
final ItemStack chargingItem = chargerInventory.getStackInSlot( 0 );
final TileEntity te = accessor.getTileEntity();
if (te instanceof TileCharger) {
final TileCharger charger = (TileCharger) te;
final IItemHandler chargerInventory = charger.getInternalInventory();
final ItemStack chargingItem = chargerInventory.getStackInSlot(0);
if( !chargingItem.isEmpty() )
{
final ITextComponent currentInventory = chargingItem.getDisplayName();
final PlayerEntity player = accessor.getPlayer();
if (!chargingItem.isEmpty()) {
final ITextComponent currentInventory = chargingItem.getDisplayName();
final PlayerEntity player = accessor.getPlayer();
tooltip.add( WailaText.Contains.textComponent().appendText(": ")
.appendSibling(currentInventory) );
ITooltipFlag.TooltipFlags tooltipFlag = Minecraft
.getInstance().gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL;
chargingItem.getItem().addInformation( chargingItem, player.world, tooltip, tooltipFlag );
}
}
tooltip.add(WailaText.Contains.textComponent().appendText(": ").appendSibling(currentInventory));
ITooltipFlag.TooltipFlags tooltipFlag = Minecraft.getInstance().gameSettings.advancedItemTooltips
? ITooltipFlag.TooltipFlags.ADVANCED
: ITooltipFlag.TooltipFlags.NORMAL;
chargingItem.getItem().addInformation(chargingItem, player.world, tooltip, tooltipFlag);
}
}
}
}
}
@@ -18,21 +18,19 @@
package appeng.integration.modules.waila.tile;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.text.ITextComponent;
import mcp.mobius.waila.api.IPluginConfig;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.localization.WailaText;
import appeng.integration.modules.waila.BaseWailaDataProvider;
import appeng.tile.crafting.TileCraftingMonitorTile;
import net.minecraft.util.text.ITextComponent;
/**
* Crafting-monitor provider for WAILA
@@ -41,23 +39,20 @@ import net.minecraft.util.text.ITextComponent;
* @version rv2
* @since rv2
*/
public final class CraftingMonitorWailaDataProvider extends BaseWailaDataProvider
{
public final class CraftingMonitorWailaDataProvider extends BaseWailaDataProvider {
@Override
public void appendBody(List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config) {
final TileEntity te = accessor.getTileEntity();
if( te instanceof TileCraftingMonitorTile )
{
final TileCraftingMonitorTile monitor = (TileCraftingMonitorTile) te;
final IAEItemStack displayStack = monitor.getJobProgress();
@Override
public void appendBody(List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config) {
final TileEntity te = accessor.getTileEntity();
if (te instanceof TileCraftingMonitorTile) {
final TileCraftingMonitorTile monitor = (TileCraftingMonitorTile) te;
final IAEItemStack displayStack = monitor.getJobProgress();
if( displayStack != null )
{
final ITextComponent currentCrafting = displayStack.asItemStackRepresentation().getDisplayName();
if (displayStack != null) {
final ITextComponent currentCrafting = displayStack.asItemStackRepresentation().getDisplayName();
tooltip.add( WailaText.Crafting.textComponent().appendText(": ").appendSibling(currentCrafting) );
}
}
}
tooltip.add(WailaText.Crafting.textComponent().appendText(": ").appendSibling(currentCrafting));
}
}
}
}
@@ -18,20 +18,18 @@
package appeng.integration.modules.waila.tile;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.text.ITextComponent;
import mcp.mobius.waila.api.IPluginConfig;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import appeng.api.implementations.IPowerChannelState;
import appeng.core.localization.WailaText;
import appeng.integration.modules.waila.BaseWailaDataProvider;
import net.minecraft.util.text.ITextComponent;
/**
* Power state provider for WAILA
@@ -40,33 +38,26 @@ import net.minecraft.util.text.ITextComponent;
* @version rv2
* @since rv2
*/
public final class PowerStateWailaDataProvider extends BaseWailaDataProvider
{
public final class PowerStateWailaDataProvider extends BaseWailaDataProvider {
@Override
public void appendBody(List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config) {
final TileEntity te = accessor.getTileEntity();
@Override
public void appendBody(List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config) {
final TileEntity te = accessor.getTileEntity();
if( te instanceof IPowerChannelState )
{
final IPowerChannelState state = (IPowerChannelState) te;
if (te instanceof IPowerChannelState) {
final IPowerChannelState state = (IPowerChannelState) te;
final boolean isActive = state.isActive();
final boolean isPowered = state.isPowered();
final boolean isActive = state.isActive();
final boolean isPowered = state.isPowered();
if( isActive && isPowered )
{
tooltip.add( WailaText.DeviceOnline.textComponent() );
}
else if( isPowered )
{
tooltip.add( WailaText.DeviceMissingChannel.textComponent() );
}
else
{
tooltip.add( WailaText.DeviceOffline.textComponent() );
}
}
if (isActive && isPowered) {
tooltip.add(WailaText.DeviceOnline.textComponent());
} else if (isPowered) {
tooltip.add(WailaText.DeviceMissingChannel.textComponent());
} else {
tooltip.add(WailaText.DeviceOffline.textComponent());
}
}
}
}
}
@@ -18,23 +18,23 @@
package appeng.integration.modules.waila.tile;
import java.util.List;
import appeng.api.networking.energy.IAEPowerStorage;
import appeng.core.localization.WailaText;
import appeng.integration.modules.waila.BaseWailaDataProvider;
import appeng.util.Platform;
import it.unimi.dsi.fastutil.objects.Object2LongMap;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World;
import java.util.List;
import it.unimi.dsi.fastutil.objects.Object2LongMap;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import mcp.mobius.waila.api.IDataAccessor;
import mcp.mobius.waila.api.IPluginConfig;
import appeng.api.networking.energy.IAEPowerStorage;
import appeng.core.localization.WailaText;
import appeng.integration.modules.waila.BaseWailaDataProvider;
import appeng.util.Platform;
/**
* Power storage provider for WAILA
@@ -43,109 +43,100 @@ import java.util.List;
* @version rv2
* @since rv2
*/
public final class PowerStorageWailaDataProvider extends BaseWailaDataProvider
{
/**
* Power key used for the transferred {@link net.minecraft.nbt.CompoundNBT}
*/
private static final String ID_CURRENT_POWER = "currentPower";
public final class PowerStorageWailaDataProvider extends BaseWailaDataProvider {
/**
* Power key used for the transferred {@link net.minecraft.nbt.CompoundNBT}
*/
private static final String ID_CURRENT_POWER = "currentPower";
/**
* Used cache for power if the power was not transmitted through the server.
* <p/>
* This is useful, when a player just started to look at a tile and thus just requested the new information from the
* server.
* <p/>
* The cache will be updated from the server.
*/
private final Object2LongMap<TileEntity> cache = new Object2LongOpenHashMap<>();
/**
* Used cache for power if the power was not transmitted through the server.
* <p/>
* This is useful, when a player just started to look at a tile and thus just
* requested the new information from the server.
* <p/>
* The cache will be updated from the server.
*/
private final Object2LongMap<TileEntity> cache = new Object2LongOpenHashMap<>();
@Override
public void appendBody(List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config) {
// Removes RF tooltip on WAILA 1.5.9+
// FIXME ( (ITaggedList<String, String>) tooltip ).removeEntries( "RFEnergyStorage" );
@Override
public void appendBody(List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config) {
// Removes RF tooltip on WAILA 1.5.9+
// FIXME ( (ITaggedList<String, String>) tooltip ).removeEntries(
// "RFEnergyStorage" );
final TileEntity te = accessor.getTileEntity();
if( te instanceof IAEPowerStorage )
{
final IAEPowerStorage storage = (IAEPowerStorage) te;
final TileEntity te = accessor.getTileEntity();
if (te instanceof IAEPowerStorage) {
final IAEPowerStorage storage = (IAEPowerStorage) te;
final double maxPower = storage.getAEMaxPower();
if( maxPower > 0 )
{
final CompoundNBT tag = accessor.getServerData();
final double maxPower = storage.getAEMaxPower();
if (maxPower > 0) {
final CompoundNBT tag = accessor.getServerData();
final long internalCurrentPower = this.getInternalCurrentPower( tag, te );
final long internalCurrentPower = this.getInternalCurrentPower(tag, te);
if( internalCurrentPower >= 0 )
{
final long internalMaxPower = (long) ( 100 * maxPower );
if (internalCurrentPower >= 0) {
final long internalMaxPower = (long) (100 * maxPower);
final String formatCurrentPower = Platform.formatPowerLong( internalCurrentPower, false );
final String formatMaxPower = Platform.formatPowerLong( internalMaxPower, false );
final String formatCurrentPower = Platform.formatPowerLong(internalCurrentPower, false);
final String formatMaxPower = Platform.formatPowerLong(internalMaxPower, false);
tooltip.add( WailaText.Contains.textComponent().appendText(": " + formatCurrentPower + " / " + formatMaxPower));
}
}
}
}
tooltip.add(WailaText.Contains.textComponent()
.appendText(": " + formatCurrentPower + " / " + formatMaxPower));
}
}
}
}
/**
* Called on server to transfer information from server to client.
* <p/>
* If the {@link net.minecraft.tileentity.TileEntity} is a {@link appeng.api.networking.energy.IAEPowerStorage}, it
* writes the power information to the {@code #tag} using the {@code #ID_CURRENT_POWER} key.
*
* @param serverPlayerEntity player looking at the power storage
* @param te power storage
* @param tag transferred tag which is send to the client
* @param world world of the power storage
*/
@Override
public void appendServerData(CompoundNBT tag, ServerPlayerEntity serverPlayerEntity, World world, TileEntity te)
{
if( te instanceof IAEPowerStorage )
{
final IAEPowerStorage storage = (IAEPowerStorage) te;
/**
* Called on server to transfer information from server to client.
* <p/>
* If the {@link net.minecraft.tileentity.TileEntity} is a
* {@link appeng.api.networking.energy.IAEPowerStorage}, it writes the power
* information to the {@code #tag} using the {@code #ID_CURRENT_POWER} key.
*
* @param serverPlayerEntity player looking at the power storage
* @param te power storage
* @param tag transferred tag which is send to the client
* @param world world of the power storage
*/
@Override
public void appendServerData(CompoundNBT tag, ServerPlayerEntity serverPlayerEntity, World world, TileEntity te) {
if (te instanceof IAEPowerStorage) {
final IAEPowerStorage storage = (IAEPowerStorage) te;
if( storage.getAEMaxPower() > 0 )
{
final long internalCurrentPower = (long) ( 100 * storage.getAECurrentPower() );
if (storage.getAEMaxPower() > 0) {
final long internalCurrentPower = (long) (100 * storage.getAECurrentPower());
tag.putLong( ID_CURRENT_POWER, internalCurrentPower );
}
}
}
tag.putLong(ID_CURRENT_POWER, internalCurrentPower);
}
}
}
/**
* Determines the current power.
* <p/>
* If the client received power information on the server, they are used, else if the cache contains a previous
* stored value, this will be used. Default value is 0.
*
* @param te te to be looked at
* @param tag tag maybe containing the channel information
*
* @return used channels on the cable
*/
private long getInternalCurrentPower( final CompoundNBT tag, final TileEntity te )
{
final long internalCurrentPower;
/**
* Determines the current power.
* <p/>
* If the client received power information on the server, they are used, else
* if the cache contains a previous stored value, this will be used. Default
* value is 0.
*
* @param te te to be looked at
* @param tag tag maybe containing the channel information
*
* @return used channels on the cable
*/
private long getInternalCurrentPower(final CompoundNBT tag, final TileEntity te) {
final long internalCurrentPower;
if( tag.contains( ID_CURRENT_POWER ) )
{
internalCurrentPower = tag.getLong( ID_CURRENT_POWER );
this.cache.put( te, internalCurrentPower );
}
else if( this.cache.containsKey( te ) )
{
internalCurrentPower = this.cache.get( te );
}
else
{
internalCurrentPower = -1;
}
if (tag.contains(ID_CURRENT_POWER)) {
internalCurrentPower = tag.getLong(ID_CURRENT_POWER);
this.cache.put(te, internalCurrentPower);
} else if (this.cache.containsKey(te)) {
internalCurrentPower = this.cache.get(te);
} else {
internalCurrentPower = -1;
}
return internalCurrentPower;
}
return internalCurrentPower;
}
}