Added Laser Relay in/out config

This commit is contained in:
Ellpeck 2016-12-05 15:09:37 +01:00
parent 1de62f5dc7
commit 5776ac2fa0
7 changed files with 202 additions and 50 deletions

View file

@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.mod.items.ItemLaserWrench;
import de.ellpeck.actuallyadditions.mod.tile.*;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
@ -158,25 +159,22 @@ public class BlockLaserRelay extends BlockContainerBase implements IHudDisplay{
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){
ItemStack stack = player.getHeldItem(hand);
TileEntityLaserRelay tile = (TileEntityLaserRelay)world.getTileEntity(pos);
if(tile instanceof TileEntityLaserRelayItem){
TileEntityLaserRelayItem relay = (TileEntityLaserRelayItem)tile;
TileEntity tile = world.getTileEntity(pos);
if(tile instanceof TileEntityLaserRelay){
TileEntityLaserRelay relay = (TileEntityLaserRelay)tile;
if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemCompass){
if(player.isSneaking()){
relay.priority--;
}
else{
relay.priority++;
}
if(!world.isRemote){
relay.onCompassAction(player);
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(relay.getPos(), relay.getWorld());
if(network != null){
network.changeAmount++;
}
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(relay.getPos(), relay.getWorld());
if(network != null){
network.changeAmount++;
}
relay.markDirty();
relay.sendUpdate();
relay.markDirty();
relay.sendUpdate();
}
return true;
}
@ -211,23 +209,26 @@ public class BlockLaserRelay extends BlockContainerBase implements IHudDisplay{
@Override
@SideOnly(Side.CLIENT)
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){
if(posHit != null && posHit.getBlockPos() != null && minecraft.world != null){
TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos());
if(tile instanceof TileEntityLaserRelayItem){
TileEntityLaserRelayItem relay = (TileEntityLaserRelayItem)tile;
if(posHit != null && posHit.getBlockPos() != null && minecraft.world != null && StackUtil.isValid(stack)){
boolean compass = stack.getItem() instanceof ItemCompass;
if(compass || stack.getItem() instanceof ItemLaserWrench){
TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos());
if(tile instanceof TileEntityLaserRelay){
TileEntityLaserRelay relay = (TileEntityLaserRelay)tile;
String strg = "Priority: "+TextFormatting.DARK_RED+relay.getPriority()+TextFormatting.RESET;
minecraft.fontRendererObj.drawStringWithShadow(strg, resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2+5, StringUtil.DECIMAL_COLOR_WHITE);
String strg = relay.getExtraDisplayString();
minecraft.fontRendererObj.drawStringWithShadow(strg, resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2+5, StringUtil.DECIMAL_COLOR_WHITE);
String expl;
if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemCompass){
expl = TextFormatting.GREEN+"Right-Click to increase! \nSneak-Right-Click to decrease!";
String expl;
if(compass){
expl = relay.getCompassDisplayString();
}
else{
expl = TextFormatting.GRAY.toString()+TextFormatting.ITALIC+"Hold a Compass to modify!";
}
StringUtil.drawSplitString(minecraft.fontRendererObj, expl, resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2+15, Integer.MAX_VALUE, StringUtil.DECIMAL_COLOR_WHITE, true);
}
else{
expl = TextFormatting.GRAY.toString()+TextFormatting.ITALIC+"Hold a Compass to modify!";
}
StringUtil.drawSplitString(minecraft.fontRendererObj, expl, resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2+15, Integer.MAX_VALUE, StringUtil.DECIMAL_COLOR_WHITE, true);
}
}
}

View file

@ -187,7 +187,7 @@ public final class InitBooklet{
new BookletChapter("lensMining", ActuallyAdditionsAPI.entryReconstruction, new ItemStack(InitItems.itemMiningLens), new PageTextOnly(1).addTextReplacement("<energy>", LensMining.ENERGY_USE), new PageCrafting(2, ItemCrafting.recipeMiningLens).setNoText()).setImportant();
//Laser Relays
chaptersIntroduction[8] = new BookletChapter("laserIntro", ActuallyAdditionsAPI.entryLaserRelays, new ItemStack(InitItems.itemLaserWrench), new PageTextOnly(1), new PageTextOnly(2).addTextReplacement("<range>", TileEntityLaserRelay.MAX_DISTANCE), new PageCrafting(3, ItemCrafting.recipeLaserWrench).setNoText()).setImportant();
chaptersIntroduction[8] = new BookletChapter("laserIntro", ActuallyAdditionsAPI.entryLaserRelays, new ItemStack(InitItems.itemLaserWrench), new PageTextOnly(1), new PageTextOnly(2).addTextReplacement("<range>", TileEntityLaserRelay.MAX_DISTANCE), new PageCrafting(3, ItemCrafting.recipeLaserWrench)).setImportant();
new BookletChapter("laserRelays", ActuallyAdditionsAPI.entryLaserRelays, new ItemStack(InitBlocks.blockLaserRelay), new PageTextOnly(1), new PageTextOnly(2).addTextReplacement("<cap1>", TileEntityLaserRelayEnergy.CAP).addTextReplacement("<cap2>", TileEntityLaserRelayEnergyAdvanced.CAP).addTextReplacement("<cap3>", TileEntityLaserRelayEnergyExtreme.CAP), new PagePicture(3, "page_laser_relay", 0).setNoText(), new PageCrafting(4, BlockCrafting.recipeLaserRelay).setWildcard().setNoText(), new PageCrafting(5, BlockCrafting.recipeLaserRelayAdvanced).setWildcard().setNoText(), new PageCrafting(6, BlockCrafting.recipeLaserRelayExtreme).setWildcard().setNoText());
new BookletChapter("itemStorage", ActuallyAdditionsAPI.entryLaserRelays, new ItemStack(InitBlocks.blockLaserRelayItemWhitelist), new PageTextOnly(1), new PageTextOnly(2), new PagePicture(3, "page_item_laser_relay_basic", 78), new PagePicture(4, "pageItemLaserRelayFail", 84), new PagePicture(5, "pageItemLaserRelayTransfer", 78), new PagePicture(6, "pageItemLaserRelayWhitelistChest", 76), new PagePicture(7, "pageItemLaserRelayWhitelistInterface", 75), new PagePicture(8, "pageItemLaserRelaySystem", 75), new PageTextOnly(9), new PageCrafting(10, BlockCrafting.recipeLaserRelayItem).setWildcard().setNoText(), new PageCrafting(11, BlockCrafting.recipeLaserRelayItemWhitelist).setWildcard().setNoText(), new PageCrafting(12, BlockCrafting.recipeItemInterface).setNoText());
new BookletChapter("fluidLaser", ActuallyAdditionsAPI.entryLaserRelays, new ItemStack(InitBlocks.blockLaserRelayFluids), new PageTextOnly(1), new PageCrafting(2, BlockCrafting.recipeFluidLaser).setNoText());

View file

@ -15,9 +15,12 @@ import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
import de.ellpeck.actuallyadditions.api.laser.LaserType;
import de.ellpeck.actuallyadditions.mod.misc.apiimpl.ConnectionPair;
import io.netty.util.internal.ConcurrentSet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.Set;
@ -130,4 +133,12 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
public AxisAlignedBB getRenderBoundingBox(){
return INFINITE_EXTENT_AABB;
}
@SideOnly(Side.CLIENT)
public abstract String getExtraDisplayString();
@SideOnly(Side.CLIENT)
public abstract String getCompassDisplayString();
public abstract void onCompassAction(EntityPlayer player);
}

View file

@ -18,12 +18,17 @@ import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.darkhax.tesla.api.ITeslaConsumer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.ArrayList;
import java.util.HashMap;
@ -35,6 +40,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay{
public static final int CAP = 1000;
public final ConcurrentHashMap<EnumFacing, TileEntity> receiversAround = new ConcurrentHashMap<EnumFacing, TileEntity>();
private Mode mode = Mode.BOTH;
private final IEnergyStorage[] energyStorages = new IEnergyStorage[6];
@ -84,7 +90,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay{
private int transmitEnergy(EnumFacing from, int maxTransmit, boolean simulate){
int transmitted = 0;
if(maxTransmit > 0){
if(maxTransmit > 0 && this.mode != Mode.OUTPUT_ONLY){
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.pos, this.world);
if(network != null){
transmitted = this.transferEnergyToReceiverInNeed(from, network, maxTransmit, simulate);
@ -147,16 +153,17 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay{
TileEntity relayTile = this.world.getTileEntity(relay);
if(relayTile instanceof TileEntityLaserRelayEnergy){
TileEntityLaserRelayEnergy theRelay = (TileEntityLaserRelayEnergy)relayTile;
if(theRelay.mode != Mode.INPUT_ONLY){
int amount = theRelay.receiversAround.size();
if(theRelay == this && theRelay.receiversAround.containsKey(from)){
//So that the tile energy was gotten from isn't factored into the amount
amount--;
}
int amount = theRelay.receiversAround.size();
if(theRelay == this && theRelay.receiversAround.containsKey(from)){
//So that the tile energy was gotten from isn't factored into the amount
amount--;
}
if(amount > 0){
relaysThatWork.add(theRelay);
totalReceiverAmount += amount;
if(amount > 0){
relaysThatWork.add(theRelay);
totalReceiverAmount += amount;
}
}
}
}
@ -236,4 +243,64 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay{
public double getLossPercentage(){
return 5;
}
@Override
@SideOnly(Side.CLIENT)
public String getExtraDisplayString(){
return "Energy Flow: "+TextFormatting.DARK_RED+this.mode.name+TextFormatting.RESET;
}
@Override
@SideOnly(Side.CLIENT)
public String getCompassDisplayString(){
return TextFormatting.GREEN+"Right-Click to change!";
}
@Override
public void onCompassAction(EntityPlayer player){
this.mode = this.mode.getNext();
}
@Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){
compound.setString("Mode", this.mode.toString());
}
}
@Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){
String modeStrg = compound.getString("Mode");
if(modeStrg != null && !modeStrg.isEmpty()){
this.mode = Mode.valueOf(modeStrg);
}
}
}
public enum Mode{
BOTH("Both Directions"),
OUTPUT_ONLY("Only into adjacent Blocks"),
INPUT_ONLY("Only out of adjacent Blocks");
public final String name;
Mode(String name){
this.name = name;
}
public Mode getNext(){
int ordinal = this.ordinal()+1;
if(ordinal >= values().length){
ordinal = 0;
}
return values()[ordinal];
}
}
}

View file

@ -14,13 +14,19 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
import de.ellpeck.actuallyadditions.api.laser.LaserType;
import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayEnergy.Mode;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.ArrayList;
import java.util.HashMap;
@ -31,6 +37,7 @@ import java.util.concurrent.ConcurrentHashMap;
public class TileEntityLaserRelayFluids extends TileEntityLaserRelay implements ISharingFluidHandler{
public final ConcurrentHashMap<EnumFacing, TileEntity> receiversAround = new ConcurrentHashMap<EnumFacing, TileEntity>();
private Mode mode = Mode.BOTH;
private final IFluidHandler[] fluidHandlers = new IFluidHandler[6];
@ -119,7 +126,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay implements
private int transmitFluid(EnumFacing from, FluidStack stack, boolean doFill){
int transmitted = 0;
if(stack != null){
if(stack != null && this.mode != Mode.OUTPUT_ONLY){
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.pos, this.world);
if(network != null){
transmitted = this.transferFluidToReceiverInNeed(from, network, stack, doFill);
@ -143,16 +150,17 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay implements
TileEntity relayTile = this.world.getTileEntity(relay);
if(relayTile instanceof TileEntityLaserRelayFluids){
TileEntityLaserRelayFluids theRelay = (TileEntityLaserRelayFluids)relayTile;
if(theRelay.mode != Mode.INPUT_ONLY){
int amount = theRelay.receiversAround.size();
if(theRelay == this && theRelay.receiversAround.containsKey(from)){
//So that the tile energy was gotten from isn't factored into the amount
amount--;
}
int amount = theRelay.receiversAround.size();
if(theRelay == this && theRelay.receiversAround.containsKey(from)){
//So that the tile energy was gotten from isn't factored into the amount
amount--;
}
if(amount > 0){
relaysThatWork.add(theRelay);
totalReceiverAmount += amount;
if(amount > 0){
relaysThatWork.add(theRelay);
totalReceiverAmount += amount;
}
}
}
}
@ -196,4 +204,42 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay implements
return transmitted;
}
@Override
@SideOnly(Side.CLIENT)
public String getExtraDisplayString(){
return "Fluid Flow: "+TextFormatting.DARK_RED+this.mode.name+TextFormatting.RESET;
}
@Override
@SideOnly(Side.CLIENT)
public String getCompassDisplayString(){
return TextFormatting.GREEN+"Right-Click to change!";
}
@Override
public void onCompassAction(EntityPlayer player){
this.mode = this.mode.getNext();
}
@Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){
compound.setString("Mode", this.mode.toString());
}
}
@Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){
String modeStrg = compound.getString("Mode");
if(modeStrg != null && !modeStrg.isEmpty()){
this.mode = Mode.valueOf(modeStrg);
}
}
}
}

View file

@ -16,11 +16,15 @@ import de.ellpeck.actuallyadditions.api.laser.LaserType;
import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemViewer.GenericItemHandlerInfo;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
@ -124,6 +128,28 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
}
}
@Override
@SideOnly(Side.CLIENT)
public String getExtraDisplayString(){
return "Priority: "+TextFormatting.DARK_RED+this.getPriority()+TextFormatting.RESET;
}
@Override
@SideOnly(Side.CLIENT)
public String getCompassDisplayString(){
return TextFormatting.GREEN+"Right-Click to increase! \nSneak-Right-Click to decrease!";
}
@Override
public void onCompassAction(EntityPlayer player){
if(player.isSneaking()){
this.priority--;
}
else{
this.priority++;
}
}
@Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type);

View file

@ -944,6 +944,7 @@ booklet.actuallyadditions.chapter.hairBalls.text.2=<item>Balls of Fur<r> are an
booklet.actuallyadditions.chapter.laserIntro.name=Intro to Laser Relays
booklet.actuallyadditions.chapter.laserIntro.text.1=<item>Laser Relays<r> exist in <imp>different variants<r>, however, they all have the same basic functionality. <n>A <item>Laser Relay<r> can be connected to one ore more other laser relays using a <item>Laser Wrench<r>. This can be achieved by <imp>right-clicking<r> the first relay and then right-clicking the second one. There can be an <imp>infinite number<r> of interconnected Laser Relays, making what is called a <item>Network<r> or <item>System<r>. Such a network will have no predefined starting or end point, but instead,
booklet.actuallyadditions.chapter.laserIntro.text.2=every <item>Laser Relay<r> has <imp>access to interact with all of the other ones<r> in different ways. <n>Connecting two <item>Laser Relays<r> has some restrictions, however. First of all, two connected <item>Laser Relays<r> must be <imp>at most <range> blocks apart<r> from each other. <n>Additionally, two <item>Laser Relays<r> of a <imp>different type<r> cannot be connected to one another. <n><n><i>View the other items in this chapter to find out more about different types of Laser Relays!
booklet.actuallyadditions.chapter.laserIntro.text.3=<imp>Hovering over<r> Laser Relays with the <item>Laser Wrench<r> will also bring up useful information like the <imp>energy flow configuration<r> or the <imp>priority configuration<r>.
booklet.actuallyadditions.chapter.laserRelays.name=Energy Laser Relays
booklet.actuallyadditions.chapter.laserRelays.text.1=The <item>Energy Laser Relay<r> is a block that can <imp>wirelessly transfer CF<r>. <n>When placing a Power Generator or Receiver next to the relay, it can receive Power <imp>from any other relay<r> in the network and send power <imp>to any other relay<r> as well. <n>During an energy transfer, they have a slight <imp>Energy Loss<r>, but nothing to worry about, especially because it's <imp>per transfer<r>, so it doesn't matter how many Lasers are inbetween two machines, the loss will <imp>always be the same amount<r>.