Add Laser Relay priorities

This commit is contained in:
Ellpeck 2016-11-16 18:51:23 +01:00
parent b355a66c97
commit 53f6ce0a24
5 changed files with 115 additions and 11 deletions

View file

@ -10,27 +10,40 @@
package de.ellpeck.actuallyadditions.mod.blocks; package de.ellpeck.actuallyadditions.mod.blocks;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase; import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler; import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.mod.tile.*; import de.ellpeck.actuallyadditions.mod.tile.*;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity; import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemCompass;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class BlockLaserRelay extends BlockContainerBase{ public class BlockLaserRelay extends BlockContainerBase implements IHudDisplay{
//This took way too much fiddling around. I'm not good with numbers. //This took way too much fiddling around. I'm not good with numbers.
private static final float F = 1/16F; private static final float F = 1/16F;
@ -52,6 +65,27 @@ public class BlockLaserRelay extends BlockContainerBase{
this.setSoundType(SoundType.STONE); this.setSoundType(SoundType.STONE);
this.type = type; this.type = type;
if(this.type.ordinal() == 0){
MinecraftForge.EVENT_BUS.register(this);
}
}
@SubscribeEvent
public void onBlockRightClick(PlayerInteractEvent.RightClickBlock event){
EntityPlayer player = event.getEntityPlayer();
World world = event.getWorld();
ItemStack stack = event.getItemStack();
BlockPos pos = event.getPos();
if(player != null && world != null && StackUtil.isValid(stack) && pos != null){
IBlockState state = event.getWorld().getBlockState(pos);
if(state != null && state.getBlock() instanceof BlockLaserRelay){
if(stack.getItem() instanceof ItemCompass && player.isSneaking()){
event.setUseBlock(Event.Result.ALLOW);
}
}
}
} }
@Override @Override
@ -100,9 +134,29 @@ public class BlockLaserRelay extends BlockContainerBase{
@Override @Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack stack, EnumFacing par6, float par7, float par8, float par9){ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack stack, EnumFacing par6, float par7, float par8, float par9){
if(player.isSneaking()){ TileEntityLaserRelay tile = (TileEntityLaserRelay)world.getTileEntity(pos);
TileEntityLaserRelay relay = (TileEntityLaserRelay)world.getTileEntity(pos); if(tile instanceof TileEntityLaserRelayItem){
if(relay instanceof TileEntityLaserRelayItemWhitelist){ TileEntityLaserRelayItem relay = (TileEntityLaserRelayItem)tile;
if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemCompass){
if(player.isSneaking()){
relay.priority--;
}
else{
relay.priority++;
}
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(relay.getPos(), relay.getWorld());
if(network != null){
network.changeAmount++;
}
relay.markDirty();
relay.sendUpdate();
return true;
}
else if(relay instanceof TileEntityLaserRelayItemWhitelist && player.isSneaking()){
if(!world.isRemote){ if(!world.isRemote){
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.LASER_RELAY_ITEM_WHITELIST.ordinal(), world, pos.getX(), pos.getY(), pos.getZ()); player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.LASER_RELAY_ITEM_WHITELIST.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
} }
@ -130,6 +184,29 @@ public class BlockLaserRelay extends BlockContainerBase{
} }
} }
@Override
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){
if(posHit != null && posHit.getBlockPos() != null && minecraft.theWorld != null){
TileEntity tile = minecraft.theWorld.getTileEntity(posHit.getBlockPos());
if(tile instanceof TileEntityLaserRelayItem){
TileEntityLaserRelayItem relay = (TileEntityLaserRelayItem)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 expl;
if(stack != null && stack.getItem() instanceof ItemCompass){
expl = TextFormatting.GREEN+"Right-Click to increase! \nSneak-Right-Click to decrease!";
}
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);
}
}
}
public enum Type{ public enum Type{
ENERGY_BASIC, ENERGY_BASIC,
ENERGY_ADVANCED, ENERGY_ADVANCED,

View file

@ -276,17 +276,17 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
@Override @Override
public int compareTo(GenericItemHandlerInfo other){ public int compareTo(GenericItemHandlerInfo other){
boolean thisWhitelist = this.relayInQuestion instanceof TileEntityLaserRelayItemWhitelist; int thisPrio = this.relayInQuestion.getPriority();
boolean otherWhitelist = other.relayInQuestion instanceof TileEntityLaserRelayItemWhitelist; int otherPrio = other.relayInQuestion.getPriority();
if(!thisWhitelist && otherWhitelist){ if(thisPrio == otherPrio){
return 1; return 0;
} }
else if(thisWhitelist && !otherWhitelist){ else if(thisPrio > otherPrio){
return -1; return -1;
} }
else{ else{
return 0; return 1;
} }
} }
} }

View file

@ -17,6 +17,7 @@ import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemViewer.GenericItemHandlerInfo; import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemViewer.GenericItemHandlerInfo;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -31,6 +32,7 @@ import java.util.concurrent.ConcurrentHashMap;
public class TileEntityLaserRelayItem extends TileEntityLaserRelay{ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
public int priority;
public final Map<BlockPos, IItemHandler> handlersAround = new ConcurrentHashMap<BlockPos, IItemHandler>(); public final Map<BlockPos, IItemHandler> handlersAround = new ConcurrentHashMap<BlockPos, IItemHandler>();
public TileEntityLaserRelayItem(String name){ public TileEntityLaserRelayItem(String name){
@ -41,6 +43,10 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
this("laserRelayItem"); this("laserRelayItem");
} }
public int getPriority(){
return this.priority;
}
public boolean isWhitelisted(ItemStack stack, boolean output){ public boolean isWhitelisted(ItemStack stack, boolean output){
return true; return true;
} }
@ -109,4 +115,20 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
} }
} }
} }
@Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){
compound.setInteger("Priority", this.priority);
}
}
@Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){
this.priority = compound.getInteger("Priority");
}
}
} }

View file

@ -164,6 +164,11 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
}.setTile(this); }.setTile(this);
} }
@Override
public int getPriority(){
return super.getPriority()+10;
}
@Override @Override
public boolean isWhitelisted(ItemStack stack, boolean output){ public boolean isWhitelisted(ItemStack stack, boolean output){
return output ? this.rightFilter.check(stack, this.slots) : this.leftFilter.check(stack, this.slots); return output ? this.rightFilter.check(stack, this.slots) : this.leftFilter.check(stack, this.slots);

View file

@ -994,7 +994,7 @@ booklet.actuallyadditions.chapter.itemStorage.text.5=But how to make a system th
booklet.actuallyadditions.chapter.itemStorage.text.6=Here, you can see the use of an <item>Advanced Item Laser Relay<r>. They can have a <imp>whitelist/blacklist configuration<r> for both connections going into them (inbound, the left side in this case) and out of them (outbound, the right side in this case). booklet.actuallyadditions.chapter.itemStorage.text.6=Here, you can see the use of an <item>Advanced Item Laser Relay<r>. They can have a <imp>whitelist/blacklist configuration<r> for both connections going into them (inbound, the left side in this case) and out of them (outbound, the right side in this case).
booklet.actuallyadditions.chapter.itemStorage.text.7=You can also attach these advanced relays to <item>Item Interfaces<r>, which will mean that they will only <imp>have access<r> to certain items from the system. Here, outbound means out of the system, and inbound means into the system. booklet.actuallyadditions.chapter.itemStorage.text.7=You can also attach these advanced relays to <item>Item Interfaces<r>, which will mean that they will only <imp>have access<r> to certain items from the system. Here, outbound means out of the system, and inbound means into the system.
booklet.actuallyadditions.chapter.itemStorage.text.8=What you can do is <imp>take this to the next level<r> and build a fully-fledged <imp>storage system<r> with multiple chests. Pulling out of or inputting into an <item>Item Interface<r> here will pull out of <imp>the entire system<r>. booklet.actuallyadditions.chapter.itemStorage.text.8=What you can do is <imp>take this to the next level<r> and build a fully-fledged <imp>storage system<r> with multiple chests. Pulling out of or inputting into an <item>Item Interface<r> here will pull out of <imp>the entire system<r>.
booklet.actuallyadditions.chapter.itemStorage.text.9=Addendum: <n><item>Advanced Item Laser Relays<r> will always <imp>take priority<r>, meaning inventories connected to them will be input into and pulled out of first. This can be useful if you want to make a <imp>storage system<r> with a <imp>last resort<r>-type chest. <n><n>Also, this system isn't only limited to chests, and there can be <imp>way more<r> than just <imp>two<r> <item>Item Interfaces<r>! <n><n><i>Gigantic storage system ahoy! booklet.actuallyadditions.chapter.itemStorage.text.9=To make this system work in more complex situations, the <item>Priority<r> of a Laser Relay can be changed by <imp>holding a Compass<r> and right-clicking on it. A <imp>higher priority<r> means that the Laser Relay will <imp>first receive items<r> and first have them <imp>extracted<r> from it. You could say that it is <i>first in line<r> for being dealt with by an <item>Item Interface<r>. <n>By defualt, the <item>Advanced Item Laser Relay<r> has a priority <imp>of 10<r>. Priorities can be pretty much infinite and even negative!
booklet.actuallyadditions.chapter.banners.name=Additional Banners booklet.actuallyadditions.chapter.banners.name=Additional Banners
booklet.actuallyadditions.chapter.banners.text.1=For <imp>special items<r> in <imp>Actually Additions<r>, there is also special <item>Banner<r> patterns. All of these just require the <imp>item next to the banner<r> in the crafting grid with, optionally, a <imp>color<r>. You can also combine them with a <item>Shield<r> like normal. <n>The items that have a banner pattern are: <n>The <item>Actually Additions Manual<r> <n>The <item>Phantom Connector<r> <n>The <item>Leaf Blower<r> (not the advanced version) <n>The <item>Drill<r> (only the white one works due to the way banners work) booklet.actuallyadditions.chapter.banners.text.1=For <imp>special items<r> in <imp>Actually Additions<r>, there is also special <item>Banner<r> patterns. All of these just require the <imp>item next to the banner<r> in the crafting grid with, optionally, a <imp>color<r>. You can also combine them with a <item>Shield<r> like normal. <n>The items that have a banner pattern are: <n>The <item>Actually Additions Manual<r> <n>The <item>Phantom Connector<r> <n>The <item>Leaf Blower<r> (not the advanced version) <n>The <item>Drill<r> (only the white one works due to the way banners work)