Added laser range upgrade

This commit is contained in:
Ellpeck 2017-02-13 19:07:53 +01:00
parent 6d3ef21444
commit e8d89f6df4
9 changed files with 85 additions and 11 deletions

View file

@ -35,6 +35,8 @@ public interface ILaserRelayConnectionHandler{
boolean addConnection(BlockPos firstRelay, BlockPos secondRelay, LaserType type, World world, boolean suppressConnectionRender); boolean addConnection(BlockPos firstRelay, BlockPos secondRelay, LaserType type, World world, boolean suppressConnectionRender);
void removeConnection(World world, BlockPos firstRelay, BlockPos secondRelay);
LaserType getTypeFromLaser(TileEntity tile); LaserType getTypeFromLaser(TileEntity tile);
LaserType getTypeFromLaser(BlockPos pos, World world); LaserType getTypeFromLaser(BlockPos pos, World world);

View file

@ -161,6 +161,7 @@ public class CreativeTab extends CreativeTabs{
this.add(InitItems.itemMiningLens); this.add(InitItems.itemMiningLens);
this.add(InitItems.itemLaserWrench); this.add(InitItems.itemLaserWrench);
this.add(InitItems.itemLaserUpgradeInvisibility); this.add(InitItems.itemLaserUpgradeInvisibility);
this.add(InitItems.itemLaserUpgradeRange);
this.add(InitItems.itemInfraredGoggles); this.add(InitItems.itemInfraredGoggles);
this.add(InitItems.itemCrateKeeper); this.add(InitItems.itemCrateKeeper);
this.add(InitItems.itemChestToCrateUpgrade); this.add(InitItems.itemChestToCrateUpgrade);

View file

@ -194,12 +194,14 @@ public final class InitItems{
public static Item itemVoidBag; public static Item itemVoidBag;
public static Item itemFillingWand; public static Item itemFillingWand;
public static Item itemLaserUpgradeInvisibility; public static Item itemLaserUpgradeInvisibility;
public static Item itemLaserUpgradeRange;
public static Item itemInfraredGoggles; public static Item itemInfraredGoggles;
public static void init(){ public static void init(){
ModUtil.LOGGER.info("Initializing Items..."); ModUtil.LOGGER.info("Initializing Items...");
itemInfraredGoggles = new ItemInfraredGoggles("item_infrared_goggles"); itemInfraredGoggles = new ItemInfraredGoggles("item_infrared_goggles");
itemLaserUpgradeRange = new ItemLaserRelayUpgrade("item_laser_upgrade_range");
itemLaserUpgradeInvisibility = new ItemLaserRelayUpgrade("item_laser_upgrade_invisibility"); itemLaserUpgradeInvisibility = new ItemLaserRelayUpgrade("item_laser_upgrade_invisibility");
itemFillingWand = new ItemFillingWand("item_filling_wand"); itemFillingWand = new ItemFillingWand("item_filling_wand");
itemBag = new ItemBag("item_bag", false); itemBag = new ItemBag("item_bag", false);

View file

@ -43,6 +43,7 @@ public class ItemLaserWrench extends ItemBase{
ItemStack stack = player.getHeldItem(hand); ItemStack stack = player.getHeldItem(hand);
TileEntity tile = world.getTileEntity(pos); TileEntity tile = world.getTileEntity(pos);
if(tile instanceof TileEntityLaserRelay){ if(tile instanceof TileEntityLaserRelay){
TileEntityLaserRelay relay = (TileEntityLaserRelay)tile;
if(!world.isRemote){ if(!world.isRemote){
if(ItemPhantomConnector.getStoredPosition(stack) == null){ if(ItemPhantomConnector.getStoredPosition(stack) == null){
ItemPhantomConnector.storeConnection(stack, pos.getX(), pos.getY(), pos.getZ(), world); ItemPhantomConnector.storeConnection(stack, pos.getX(), pos.getY(), pos.getZ(), world);
@ -52,20 +53,26 @@ public class ItemLaserWrench extends ItemBase{
BlockPos savedPos = ItemPhantomConnector.getStoredPosition(stack); BlockPos savedPos = ItemPhantomConnector.getStoredPosition(stack);
if(savedPos != null){ if(savedPos != null){
TileEntity savedTile = world.getTileEntity(savedPos); TileEntity savedTile = world.getTileEntity(savedPos);
int distanceSq = (int)savedPos.distanceSq(pos); if(savedTile instanceof TileEntityLaserRelay){
TileEntityLaserRelay relay = (TileEntityLaserRelay)tile; int distanceSq = (int)savedPos.distanceSq(pos);
if(ItemPhantomConnector.getStoredWorld(stack) == world && savedTile instanceof TileEntityLaserRelay && ((TileEntityLaserRelay)savedTile).type == relay.type && distanceSq <= TileEntityLaserRelay.MAX_DISTANCE*TileEntityLaserRelay.MAX_DISTANCE && ActuallyAdditionsAPI.connectionHandler.addConnection(savedPos, pos, relay.type, world)){ TileEntityLaserRelay savedRelay = (TileEntityLaserRelay)savedTile;
ItemPhantomConnector.clearStorage(stack, "XCoordOfTileStored", "YCoordOfTileStored", "ZCoordOfTileStored", "WorldOfTileStored");
((TileEntityLaserRelay)savedTile).sendUpdate(); int lowestRange = Math.min(relay.getMaxRange(), savedRelay.getMaxRange());
relay.sendUpdate(); int range = lowestRange*lowestRange;
if(ItemPhantomConnector.getStoredWorld(stack) == world && savedRelay.type == relay.type && distanceSq <= range && ActuallyAdditionsAPI.connectionHandler.addConnection(savedPos, pos, relay.type, world)){
ItemPhantomConnector.clearStorage(stack, "XCoordOfTileStored", "YCoordOfTileStored", "ZCoordOfTileStored", "WorldOfTileStored");
player.sendMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.connected.desc")); ((TileEntityLaserRelay)savedTile).sendUpdate();
} relay.sendUpdate();
else{
player.sendMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.cantConnect.desc")); player.sendMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.connected.desc"));
ItemPhantomConnector.clearStorage(stack, "XCoordOfTileStored", "YCoordOfTileStored", "ZCoordOfTileStored", "WorldOfTileStored");
return EnumActionResult.SUCCESS;
}
} }
player.sendMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.cantConnect.desc"));
ItemPhantomConnector.clearStorage(stack, "XCoordOfTileStored", "YCoordOfTileStored", "ZCoordOfTileStored", "WorldOfTileStored");
} }
} }
} }

View file

@ -170,6 +170,27 @@ public final class LaserRelayConnectionHandler implements ILaserRelayConnectionH
return true; return true;
} }
@Override
public void removeConnection(World world, BlockPos firstRelay, BlockPos secondRelay){
if(world != null && firstRelay != null && secondRelay != null){
Network network = this.getNetworkFor(firstRelay, world);
if(network != null){
network.changeAmount++;
WorldData data = WorldData.get(world);
data.laserRelayNetworks.remove(network);
data.markDirty();
for(IConnectionPair pair : network.connections){
if(!pair.contains(firstRelay) || !pair.contains(secondRelay)){
this.addConnection(pair.getPositions()[0], pair.getPositions()[1], pair.getType(), world, pair.doesSuppressRender());
}
}
}
}
}
@Override @Override
public LaserType getTypeFromLaser(TileEntity tile){ public LaserType getTypeFromLaser(TileEntity tile){
if(tile instanceof TileEntityLaserRelay){ if(tile instanceof TileEntityLaserRelay){

View file

@ -14,9 +14,12 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.laser.IConnectionPair; import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
import de.ellpeck.actuallyadditions.api.laser.LaserType; import de.ellpeck.actuallyadditions.api.laser.LaserType;
import de.ellpeck.actuallyadditions.api.laser.Network; import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.misc.apiimpl.ConnectionPair; import de.ellpeck.actuallyadditions.mod.misc.apiimpl.ConnectionPair;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import io.netty.util.internal.ConcurrentSet; import io.netty.util.internal.ConcurrentSet;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@ -35,6 +38,7 @@ public abstract class TileEntityLaserRelay extends TileEntityInventoryBase{
private Network cachedNetwork; private Network cachedNetwork;
private int changeAmountAtCaching = -1; private int changeAmountAtCaching = -1;
private int lastRange;
private Set<IConnectionPair> tempConnectionStorage; private Set<IConnectionPair> tempConnectionStorage;
@ -81,6 +85,26 @@ public abstract class TileEntityLaserRelay extends TileEntityInventoryBase{
} }
} }
@Override
public void updateEntity(){
super.updateEntity();
int range = this.getMaxRange();
if(this.lastRange != range){
ConcurrentSet<IConnectionPair> connections = ActuallyAdditionsAPI.connectionHandler.getConnectionsFor(this.pos, this.world);
if(connections != null && !connections.isEmpty()){
for(IConnectionPair pair : connections){
int distanceSq = (int)pair.getPositions()[0].distanceSq(pair.getPositions()[1]);
if(distanceSq > range*range){
ActuallyAdditionsAPI.connectionHandler.removeConnection(this.world, pair.getPositions()[0], pair.getPositions()[1]);
}
}
}
this.lastRange = range;
}
}
/*@Override /*@Override
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
@ -166,6 +190,16 @@ public abstract class TileEntityLaserRelay extends TileEntityInventoryBase{
return null; return null;
} }
public int getMaxRange(){
ItemStack upgrade = this.slots.getStackInSlot(0);
if(StackUtil.isValid(upgrade) && upgrade.getItem() == InitItems.itemLaserUpgradeRange){
return 35;
}
else{
return MAX_DISTANCE;
}
}
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public abstract String getExtraDisplayString(); public abstract String getExtraDisplayString();

View file

@ -522,6 +522,7 @@ item.actuallyadditions.item_more_damage_lens.name=Lens of the Killer
item.actuallyadditions.item_filling_wand.name=Handheld Filler item.actuallyadditions.item_filling_wand.name=Handheld Filler
item.actuallyadditions.item_laser_upgrade_invisibility.name=Laser Relay Modifier: Invisibility item.actuallyadditions.item_laser_upgrade_invisibility.name=Laser Relay Modifier: Invisibility
item.actuallyadditions.item_infrared_goggles.name=Infrared Goggles item.actuallyadditions.item_infrared_goggles.name=Infrared Goggles
item.actuallyadditions.item_laser_upgrade_range.name=Laser Relay Modifier: Range
#Tooltips #Tooltips
tooltip.actuallyadditions.onSuffix.desc=On tooltip.actuallyadditions.onSuffix.desc=On

View file

@ -0,0 +1,6 @@
{
"parent": "actuallyadditions:item/handheld_item",
"textures": {
"layer0": "actuallyadditions:items/item_laser_upgrade_range"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 B